我正在尝试使用已在IdentityServer4中实现的设备代码流,但是在文档中,我找不到关于设备代码流的任何有用信息。我找到了设备代码流的示例,但我不明白什么是用户代码,如何获取或保存它。
这里是用于获取授权上下文的基本服务。
private readonly IDeviceFlowInteractionService _interaction;
public DeviceController(
IDeviceFlowInteractionService interaction)
{
_interaction = interaction;
_clientStore = clientStore;
_resourceStore = resourceStore;
_events = eventService;
_logger = logger;
}
private async Task<DeviceAuthorizationViewModel> BuildViewModelAsync(string userCode, DeviceAuthorizationInputModel model = null)
{
var request = await _interaction.GetAuthorizationContextAsync(userCode);
// Some code ...
return null;
}
如您在上面看到的,我使用的是具有参数userCode的GetAuthorizationContext,但是我不知道如何获取此代码?或保存位置。在文档中,我没有找到有关UserCode的任何信息。
由IdentityServer维护者之一构建的[Here is a sample application,显示了如何利用设备流。
客户端将需要向设备授权端点发出请求以生成代码。由this file的第38行指示,一旦生成代码,就应向用户显示。
然后,用户可以在Web应用程序上输入代码,以提交给上面构建的DeviceController
。