我有使用OAuth 2.0和授权服务器的Spring Boot应用程序。当我尝试访问安全页面时,我在我的授权服务器(Blitz Identity Provider)的登录页面上获得了重定向,并且一切在这里都能正常运行。我的问题是我无法在@Controller(在安全页面上)中提取授权令牌。我想稍后在第二个应用程序中使用该令牌进行授权。
这里有2个文件,可以帮助您了解我的情况的某些部分。
application.yml
server:
port: 8080
context-path: /
session:
cookie:
name:FIRSTSESSION
security:
basic:
enabled: false
oauth2:
client:
clientId: test_id
clientSecret: f3M5m9a2Dn0v15l
accessTokenUri: http://server:9000/blitz/oauth/te
userAuthorizationUri: http://server:9000/blitz/oauth/ae?scope=test_scope
resource:
userInfoUri: http://server:9000/blitz/oauth/me
logging:
level:
org.springframework.security: DEBUG
Run Code Online (Sandbox Code Playgroud)
SsoController.java
@EnableOAuth2Sso
@Controller
public class SsoController {
@RequestMapping("/secondService")
public String getContent(HttpServletRequest request, Model model) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
model.addAttribute("submittedValue", authentication.getDetails());
return "secondService";
}
}
Run Code Online (Sandbox Code Playgroud)
那么,您有什么建议?在这种情况下,如何提取授权令牌?