【问题标题】:Spring OAuth2 implicit flow redirect urlSpring OAuth2 隐式流重定向 url
【发布时间】:2017-05-03 07:29:26
【问题描述】:

在我的 Spring Boot/OAuth2 应用程序中,我试图通过我自己的 OAuth2 服务器登录用户,并使用以下 url 进行隐式流程:

http://example.com/api/oauth/authorize?response_type=token&client_id=example_client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin

登录后它将用户重定向到以下网址:

http://localhost:8080/login#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoyOTcsInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsicmVh&token_type=bearer&expires_in=43199&scope=read%20write&user_id=297&jti=9d416117-0d08-4f4e-874d-3f31dbe7815f

将用户重定向到带有# 符号而不是? 的url 是否正确。我的意思是:

http://localhost:8080/login?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoyOTcsInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsicmVh&token_type=bearer&expires_in=43199&scope=read%20write&user_id=297&jti=9d416117-0d08-4f4e-874d-3f31dbe7815f

如果没有 - 如何设置我的 Spring 应用程序 OAuth2 服务器以便将用户重定向到正确的 url?

【问题讨论】:

    标签: java spring spring-boot spring-security oauth2


    【解决方案1】:

    行为是正确的。授权代码流程要求将响应参数嵌入重定向 URI(RFC 6749,4.1.2. Authorization Response)的 query 部分,而隐式流程要求将响应参数嵌入 fragment 部分(RFC 6749,4.2.2. Access Token Response)。

    OAuth 2.0 Multiple Response Type Encoding Practices 定义了一个新的请求参数<strong>response_mode</strong>。该参数指定应嵌入响应参数的位置。在规范中,定义了<strong>query</strong><strong>fragment</strong><strong>none</strong>。此外,OAuth 2.0 Form Post Response Mode 已将<strong>form_post</strong> 添加为response_mode 的值。如果授权请求中包含response_mode=form_post,则响应参数将作为 HTML 表单参数嵌入。

    您可以在 Authlete 权威指南的“2. Response Format”中找到描述response_type/response_mode 组合与 HTTP 状态/响应参数位置之间关系的表格。

    【讨论】:

      猜你喜欢
      • 2016-02-23
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      • 2021-08-08
      • 2015-10-28
      • 2023-03-24
      • 2020-06-03
      • 2021-03-05
      相关资源
      最近更新 更多