2017-02-07 10 views
1

私のリソースサーバーが私の認証サーバーと通信するのを苦労しています。スプリングブートOAuth2

これは、my認証サーバーの設定です。

@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です:

@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"); 
    } 

} 

これは、リソースサーバのための私の設定です

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:[email protected]:9999/uaa/oauth/token -d grant_type=client_credentials 
{"access_token":"5e74b3fd-41d2-48a7-a21c-31edf52bcb63","token_type":"bearer","expires_in":43199,"scope":"openid"} 

そして、私は無効なトークンを取得しないとログに示すことを何も、誰が助けてくださいすることができますしかし、私の気持ちは、それがリソースサーバの間違った設定だで、次の

$ 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"} 

を使用して、私のリソースAPIを打つためにトークンを使用。

答えて

0

あなたのリソースサーバのapplication.ymlはASこの

@RequestMapping(value = "/user", 
     method = RequestMethod.GET) 
public Principal user(Principal user) { 
    return user; 
} 

のようにこれはspring security documentation

から取得されたユーザの詳細を公開する必要があり、この

security: 
    oauth2: 
    resource: 
     user-info-uri: http://localhost:9999/user 

このユーザーのエンドポイントのような設定が含まれている必要があります更新:@EnableWebMvcが使用されていないことを確認してください。 filter based

+0

のため、Springセキュリティを使用するアプリケーションの場合は動作しません。user-info-uriの必要はありません。ユーザーの詳細を含むJWTトークンを使用しています。 – Jack

関連する問題