【发布时间】:2017-06-24 22:48:11
【问题描述】:
我正在努力让我的资源服务器与我的授权服务器通信。
这是我的授权服务器的配置。
@Configuration
@EnableAuthorizationServer
public class AuthorisationServerConfig extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("app1").secret("password").authorizedGrantTypes("authorization_code", "refresh_token", "password", "client_credentials")
.scopes("openid");
}
}
这是我对资源服务器的配置:
@SpringBootApplication
@EnableResourceServer
@RestController
public class ResourceServerApplication {
public static void main(String[] args) {
SpringApplication.run(ResourceServerApplication.class, args);
}
@RequestMapping("/hello")
public String home() {
return "Hello World!";
}
}
这是资源服务器的 application.yml:
security:
oauth2:
client:
id: app1
client-secret: password
access-token-uri: http://localhost:9999/oauth/token
user-authorization-uri: http://localhost:9999/oauth/authorize
我可以使用以下方式从我的 AS 请求令牌:
$ curl app1:password@localhost:9999/uaa/oauth/token -d grant_type=client_credentials
{"access_token":"5e74b3fd-41d2-48a7-a21c-31edf52bcb63","token_type":"bearer","expires_in":43199,"scope":"openid"}
然后我使用令牌通过以下方式访问我的资源 API
$ curl -H "Authorization: Bearer 5e74b3fd-41d2-48a7-a21c-31edf52bcb63" localhost:8080/hello
{"error":"invalid_token","error_description":"Invalid access token: 5e74b3fd-41d2-48a7-a21c-31edf52bcb63"}
但是我得到无效的令牌并且在日志中没有任何指示,任何人都可以帮忙,我的感觉是资源服务器的配置错误。
【问题讨论】:
标签: spring-boot spring-security oauth-2.0 spring-cloud