Spring OAuth2隐式流重定向url

时间:2016-12-17 19:40:34

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

在我的Spring Boot / OAuth2应用程序中,我试图通过我自己的OAuth2服务器登录用户,隐式流程跟随以下网址:

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

使用#符号而不是?将用户重定向到网址是否正确?我的意思是:

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?

1 个答案:

答案 0 :(得分:5)

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

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

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

enter image description here

相关问题