IdentityServer3,隐式流,如何获取令牌?

编程入门 行业动态 更新时间:2024-10-19 11:40:57
本文介绍了IdentityServer3,隐式流,如何获取令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试访问与IdentityServer3一起使用的令牌URL.服务器是通过以下方式配置的:

var options = new IdentityServerOptions { LoggingOptions = new LoggingOptions { WebApiDiagnosticsIsVerbose = true, EnableWebApiDiagnostics = true, EnableHttpLogging = true, EnableKatanaLogging= true }, Factory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()) .UseInMemoryUsers(Users.Get()), RequireSsl = false, EnableWelcomePage = false, }; app.UseIdentityServer(options);

客户端配置:

new Client { Enabled = true, ClientName = "JS Client", ClientId = "js", Flow = Flows.Implicit, RedirectUris = new List<string> { "localhost:56522" }, AllowedCorsOrigins = new List<string> { "localhost:56522" }, AllowAccessToAllScopes = true }

尝试将以下HTTP请求发布到令牌端点:

Content-Type:application/x-www-form-urlencoded grant_type:password redirect_uri:localhost:56522 client_id:js username:bob password:secret scope:api

我收到无效的客户端错误消息,并显示日志: 操作返回了'IdentityServer3.Core.Results.TokenErrorResult'',Operation = ReflectedHttpActionDescriptor.ExecuteAsync

有什么主意我还想念什么?

解决方案

您的请求正在使用password授予类型,这是OAuth资源所有者流,但您的客户端已配置为使用OpenID Connect隐式流. /p>

要么更改您的客户端配置以使用资源所有者"流,要么将您的请求更改为有效的OpenID Connect请求.

例如:GET /connect/authorize?client_id=js&scope=openid api&response_type=id_token token&redirect_uri=localhost:56522&state=abc&nonce=xyz.这将带您进入登录页面.

或更妙的是,使用建议的@Jenan之类的JavaScipt库,例如 IdentityModel oidc-客户为您处理这些请求.

I am trying to access token URL working with IdentityServer3. The Server is configured the following way:

var options = new IdentityServerOptions { LoggingOptions = new LoggingOptions { WebApiDiagnosticsIsVerbose = true, EnableWebApiDiagnostics = true, EnableHttpLogging = true, EnableKatanaLogging= true }, Factory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()) .UseInMemoryUsers(Users.Get()), RequireSsl = false, EnableWelcomePage = false, }; app.UseIdentityServer(options);

The client configuration:

new Client { Enabled = true, ClientName = "JS Client", ClientId = "js", Flow = Flows.Implicit, RedirectUris = new List<string> { "localhost:56522" }, AllowedCorsOrigins = new List<string> { "localhost:56522" }, AllowAccessToAllScopes = true }

Trying to POST the following HTTP request to token endpoint:

Content-Type:application/x-www-form-urlencoded grant_type:password redirect_uri:localhost:56522 client_id:js username:bob password:secret scope:api

I get Invalid client error message and log shows: Action returned 'IdentityServer3.Core.Results.TokenErrorResult'', Operation=ReflectedHttpActionDescriptor.ExecuteAsync

Any ideas what do I still miss?

解决方案

Your request is using the password grant type, which is the OAuth Resource Owner flow, but your client is configured to use the OpenID Connect Implicit flow.

Either change your client configuration to use the Resource Owner flow, or change your request to be a valid OpenID Connect request.

For example: GET /connect/authorize?client_id=js&scope=openid api&response_type=id_token token&redirect_uri=localhost:56522&state=abc&nonce=xyz. This will take you to a login page.

Or better yet, use a JavaScipt library like @Jenan suggested, such as the IdentityModel oidc-client which handles these requests for you.

更多推荐

IdentityServer3,隐式流,如何获取令牌?

本文发布于:2023-11-17 02:06:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   隐式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!