2017-06-21 5 views
0

リソースサービスとuiの前にoauth2クライアントとしてゲートウェイを実装しました。すべてのものは、私がセッションとして認証として、ゲートウェイはユーザーを検討している、すでに私のリソースサービスやUIながら@ EnableOAuth2Ssoは、トークンの有効期限が切れていないかどうかをチェックしません。

2017-06-21 09:17:34.311 DEBUG 32482 --- [nio-8080-exec-6] o.s.s.w.a.i.FilterSecurityInterceptor : Previously Authenticated: or[email protected]a80f4caf: Principal: user; Credentials: [PROTECTED]; Authenticated: true; Details: remoteAddress=0:0:0:0:0:0:0:1, sessionId=<SESSION>, tokenType=bearertokenValue=<TOKEN>; Granted Authorities: ROLE_ACTUATOR, ROLE_USER 
2017-06-21 09:17:34.311 DEBUG 32482 --- [nio-8080-exec-6] o.s.s.access.vote.AffirmativeBased  : Voter: org.sp[email protected]1aaae9c5, returned: 1 

存在していたログを確認する

<oauth> 
    <error_description>bfc5a9f6-0537-4ab9-91c1-e756501b429d</error_description> 
    <error>invalid_token</error> 
</oauth> 

を受け取るトークンの有効期限が切れるとき以外は良い取り組んでいますない

2017-06-21 09:17:34.532 WARN 32484 --- [nio-9001-exec-1] o.s.b.a.s.o.r.UserInfoTokenServices  : Could not fetch user details: class org.springframework.security.oauth2.client.resource.UserRedirectRequiredException, A redirect is required to get the users approval 

ゲートウェイの設定

@SpringBootApplication 
@EnableDiscoveryClient 
@EnableZuulProxy 
public class GatewayApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(GatewayApplication.class, args); 
    } 
} 

@Configuration 
@EnableOAuth2Sso 
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { 


    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .csrf() 
       .disable() 
       .authorizeRequests() 
       .anyRequest().authenticated(); 

    } 

} 

security: 
    oauth2: 
    client: 
     accessTokenUri: http://localhost:9191/uaa/oauth/token 
     userAuthorizationUri: http://localhost:9191/uaa/oauth/authorize 
     clientId: acme 
     clientSecret: acmesecret 
    resource: 
     user-info-uri: http://localhost:9191/uaa/user 
     prefer-token-info: false 
zuul: 
    ignored-services: '*' 
    routes: 
    authserver: /uaa/** 
    resource-service: /resource/** 
    ui: 
     path: /ui/** 
     strip-prefix: false 

UI設定または任意のリソースサーバー

@SpringBootApplication 
@EnableDiscoveryClient 
@EnableResourceServer 
public class UiApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(UiApplication.class, args); 
    } 
} 

security: 
    oauth2: 
    resource: 
     user-info-uri: http://localhost:9191/uaa/user 
server: 
    port: 9001 
    context-path: /${spring.application.name} 

私は期待とトークンが有効であり、そうでない場合はページをログインするか、リフレッシュトークンを使用するようにユーザーをリダイレクトする場合はやろうとすると、そのゲートウェイチェックです何をすべきかトークンを更新するには?

答えて

0

ギッターにデイブ・syer @に話した後、彼はそれがspring-bootにデフォルトで作成されていないとして、我々はゲートウェイの内側OAuth2RestOperationsを宣言する必要があると教えてくれましたし、OAuth2TokenRelayFilter

でリフレッシュトークンを要求するために必要とされていますしたがって、以下をすべて固定してください。

@Bean 
public OAuth2RestOperations oAuth2RestOperations(OAuth2ClientContext oauth2ClientContext, OAuth2ProtectedResourceDetails details) { 
    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(details, oauth2ClientContext); 
    return oAuth2RestTemplate; 
} 
関連する問題