身份服务器4令牌未在使用Identity Server 3的.NetFramework Api中validation
在我的身份服务器应用程序中使用idsv4并在端口“5000”上运行有一个客户端
new Client { ClientId = "client", // no interactive user, use the clientid/secret for authentication AllowedGrantTypes = GrantTypes.ClientCredentials, // secret for authentication ClientSecrets = { new Secret("secret".Sha256()) }, // scopes that client has access to AllowedScopes = { "api1" } }`
在我的.Net Framework Api的启动类中使用端口号“7001”:
app.UseIdentityServerBearerTokenAuthentication( new IdentityServerBearerTokenAuthenticationOptions { Authority = "https://localhost:5000", ValidationMode = ValidationMode.ValidationEndpoint, RequiredScopes = new[] { "api1" } });`
最后在我的客户端成功捕获令牌:
static TokenResponse GetClientToken() { var client = new TokenClient( "https://localhost:5000/connect/token", "client", "secret"); return client.RequestClientCredentialsAsync("api1").Result; }`
但是当我使用这个令牌来调用api时:
static void CallApi(TokenResponse response) { var client = new HttpClient(); client.SetBearerToken(response.AccessToken); Console.WriteLine(client.GetStringAsync("https://localhost:7001/api/identity/get").Result); }
客户端抛出exception:
响应状态代码不表示成功:401(未授权)。 我已经在核心api中完成了所有这些,并且每件事都可以!
切换到X509证书而不是样本附带的证书后,一切都开始正常工作。
摆脱.AddDeveloperSigningCredential()并使用.AddSigningCredential(GET_THE_CERT_FROM_YOUR_CERT_STORE)
上述就是C#学习教程:身份服务器4令牌未在使用Identity Server 3的.NetFramework Api中validation分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/989018.html