刷新令牌在Spring Security OAuth2中不起作用

时间:2019-04-21 20:19:10

标签: spring-boot oauth-2.0 microservices spring-security-oauth2

有一个网关作为oauth2客户端和一个授权服务器。授权类型为authorization_code。一切正常。 Uaa和网关以及资源服务器位于here

网关的application.yml:

zuul:
  routes:
    resource:
      url: http://localhost:8085
    resource2:
      url: http://localhost:8086
security:
  oauth2:
    resource:
      user-info-uri: http://localhost:9191/uaa/user
    client:
      accessTokenUri: http://localhost:9191/uaa/oauth/token
      userAuthorizationUri: http://localhost:9191/uaa/oauth/authorize
      clientId: web
      clientSecret: secret
      grant-type: authorization_code,refresh_token

logging:
  level:
    org.springframework.security: DEBUG

如您在上面的application.yml中所看到的,授予类型中有refresh_token

以及授权服务器的配置:

@Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        //clients.jdbc(appConfig.dataSource());
        clients.inMemory()
                .withClient("web")
                .secret(new HashingClass().encode("secret"))
                .authorizedGrantTypes("authorization_code","refresh_token")
                .scopes("read,write")
                .accessTokenValiditySeconds(9)
                .refreshTokenValiditySeconds(9);

    }

正如您在上面的配置类中看到的那样,authorizedGrantTypes中有refresh_token

但是9秒钟后,刷新令牌不起作用,并且网关应用程序中出现以下错误:

  

原因:   org.springframework.security.authentication.BadCredentialsException:   无法在处获取有效的访问令牌   org.springframework.cloud.security.oauth2.proxy.OAuth2TokenRelayFilter.getAccessToken(OAuth2TokenRelayFilter.java:99)   〜[spring-cloud-security-2.0.0.RELEASE.jar:2.0.0.RELEASE]在   org.springframework.cloud.security.oauth2.proxy.OAuth2TokenRelayFilter.run(OAuth2TokenRelayFilter.java:79)   〜[spring-cloud-security-2.0.0.RELEASE.jar:2.0.0.RELEASE]在   com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117)   〜[zuul-core-1.3.1.jar:1.3.1]在   com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193)   〜[zuul-core-1.3.1.jar:1.3.1] ...省略了97个常见框架

哪里出问题了?刷新令牌会丢失其他什么配置?

除了9秒钟之后,我的网关应用程序都会通过刷新令牌自动获取新令牌。为什么不会发生?

0 个答案:

没有答案