我正在尝试设置Thinktecture的Identity Server 3,但在交换授权代码时(或使用ResourceOwner流时,我似乎无法让它返回刷新令牌,但我将专注于授权代码)因为它现在对我来说更重要).我回来访问令牌并且可以使用它们进行身份验证就好了,但它似乎甚至没有生成我期望回来的刷新令牌.为了让Identity Server返回刷新令牌,我需要做些什么特别的事情吗?
我查看了文档,但没有看到任何我设置错误的内容,并且他们在页面上唯一的刷新令牌,我没有做的是在发送用户时明确请求"offline_access"范围在那里进行身份验证,因为每当我尝试时,我都会收到"无效范围"错误.因此,我采用Thinktecture的措辞"请求offline_access范围(通过代码或资源所有者流程)"来表示offline_access范围是根据您正在使用的流程自动请求的内容.
我一直在努力跟踪他们的示例应用程序(以及Katana Project中现有的Owin中间件的源代码),我的设置如下:
var client = new Client()
{
ClientId = "SomeId",
ClientName = "Client with Authentication Code Flow",
RequireConsent = false, //Setting this to true didn't help
Flow = Flows.AuthorizationCode,
ClientSecrets = new List() {
new ClientSecret("secret")
},
RedirectUris = new List()
{
"localhost:/specific-redirect-path"
}
};
var authorizationEndpoint =
AuthorizationEndpointBase +
"?client_id=" + Uri.EscapeDataString(Options.ClientId) +
"&scope=Default" +
"&response_type=code" +
"&redirect_uri=" + Uri.EscapeDataString(redirectUri) +
"&state=" + Uri.EscapeDataString(state);
Response.Redirect(authorizationEndpoint);
其中"默认"是我创建的范围.我有一个PowerShell脚本需要调用C#才能正常工作,其中一些是异步的.在调试一些仅在从PowerShell调用C#代码时出现的错误时,我注意到了一些我没想到的东西.在C#代码中,如果我调用Console.WriteLine它,则按预期写入PowerShell控制台,除非我使用的是PowerShell ISE,并且在我在异步函数中进行等待后调用它.
这是一个显示问题的示例脚本:
$source = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
public class TestClass
{
public static int TestWrapper()
{
var task = TestAsync();
task.Wait();
return task.Result;
}
private static async Task<int> TestAsync()
{
Console.WriteLine("Before await");
await Task.Run(() => { Thread.Sleep(2000); return; });
Console.WriteLine("After await");
return 2;
}
}
"@
Add-Type -TypeDefinition $source
[TestClass]::TestWrapper()
Run Code Online (Sandbox Code Playgroud)
在这里,我只是调用异步函数,等待它完成,并返回结果.在函数内部,我只是在返回一个值之前和之后尝试在线程休眠之前和之后进行记录,以便我知道该函数已完全执行.
我希望看到:
Before await
After await
2
Run Code Online (Sandbox Code Playgroud)
这就是我作为C#控制台应用程序或基本PowerShell运行时所看到的,但是当通过PowerShell ISE运行时,我看到:
Before await
2
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么会这样吗?