1
OAuth 2.0 및 Authorization Server를 사용하는 Spring Boot 앱이 있습니다. 보안 페이지에 액세스하려고하면 인증 서버 (Blitz Identity Provider)의 로그인 페이지에서 리디렉션되고 모든 것이 제대로 작동해야합니다. 내 문제는 그 것이다 @Controller (보안 페이지에)의 승인 토큰을 추출 할 수 없습니다. 나중에 두 번째 응용 프로그램에서 권한을 부여하기 위해 사용하려는 토큰.@Controller에서 인증 토큰을 추출하는 방법
- 시도 (대답) this thing하고 일, 나는 다시 내 토큰을 가지고, 그러나 당신이 볼 수 있듯이, 그것은 사용자 이름과 암호 매개 변수의 하드 코드이고이 로그인을 통해 로그인 같다 - 난 몰라 두 번째로 에 로그인해야합니다 (인증 된 페이지에서).
- 출력에 authentication.getDetails을 시도(), 그것은 토큰 유형 하고 < TOKEN> 같은 토큰을 보여 주지만 충분하지 않습니다.
- 요청 - 응답 헤더에서 토큰 조회를 시도했지만 찾지 못 했으므로 권한 서버가 헤더로 보내지 않습니다.
여기 내 컨텍스트의 일부를 이해하는 데 도움이되는 두 개의 파일이 있습니다.
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
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";
}
}
그래서, 당신은 무엇을 제안 할 수 있습니다? 이 경우 인증 토큰을 어떻게 추출 할 수 있습니까?
예! 그게 바로 내가 필요로하는 것입니다! 이 코드를 구현하여 토큰을 얻었습니다. OAuth2AuthenticationDetails = auth = (OAuth2AuthenticationDetails) SecurityContextHolder.getContext(). getAuthentication(). getDetails(); accessToken = auth.getTokenValue(); – Artemoon