OAuth2RestOperationsConfiguration.java 文件源码

java
阅读 42 收藏 0 点赞 0 评论 0

项目:spring-security-oauth2-boot 作者:
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
    DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
            new DefaultAccessTokenRequest());
    Authentication principal = SecurityContextHolder.getContext()
            .getAuthentication();
    if (principal instanceof OAuth2Authentication) {
        OAuth2Authentication authentication = (OAuth2Authentication) principal;
        Object details = authentication.getDetails();
        if (details instanceof OAuth2AuthenticationDetails) {
            OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
            String token = oauthsDetails.getTokenValue();
            context.setAccessToken(new DefaultOAuth2AccessToken(token));
        }
    }
    return context;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号