2016-04-19 19 views
0

oauth2.0フレームワークに基づいて保護された残りのapiを作成しています。Oauth2.0認証サーバーの設定

私は認証サーバーリソースサーバーを正常に構築しました。

AuthorizationServer私はこの拡張メソッド

公共ボイド設定(ClientDetailsS​​erviceConfigurerクライアント)例外{}

をスローの問題に直面しています、 AuthorizationServerConfigurerAdapter を拡張し、いくつかのメソッドをオーバーライド

ここに説明はあります

私は設定()認証サーバ

@Override 
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 

     clients.inMemory().withClient("clientapp").authorizedGrantTypes("password", "refresh_token") 
       .scopes("read", "write").resourceIds(RESOURCE_ID).secret("123456"); 

    } 

このメソッドのこのバージョンを実行しているだけで正常に動作し、私はそれを求めるときaccess_tokenはを返します。

しかし、いくつかの機能拡張を使って同じ方法を実行したとき、私はaccess_tokenを要求したときに何も得られませんでしたが、無許可のhttp応答が401でした。

public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
    int n = appMetier.getAppsCount(); 
    for (App app:appMetier.findAll(0, n).getApps()) { 
     clients.inMemory().withClient(app.getClientPublicId()).authorizedGrantTypes("password", "refresh_token") 
       .scopes("read", "write").resourceIds(RESOURCE_ID).secret(app.getClientSecretId()); 
    } 
    } 

ここでは、n個の変数が17に等しく、それは私が権利を有するメモリ内の17台のクライアントがaccess_tokenはを受ける必要があるということです。

17からaccess_tokenを取得した唯一のものが最初のものです。

ご回答ありがとうございます。

+0

同じOAuthプロバイダに複数のクライアントが必要ですか? – 11thdimension

答えて

0

あなたは毎回ビルダーサービスを上書きします。inMemory()を複数回呼び出すとします。一度だけ呼び出す必要があります。

次のコードは動作するはずです。

public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
    int n = appMetier.getAppsCount(); 
    InMemoryClientDetailsServiceBuilder clientBuilder = clients.inMemory(); 

    for (App app:appMetier.findAll(0, n).getApps()) { 
     clientBuilder.withClient(app.getClientPublicId()).authorizedGrantTypes("password", "refresh_token") 
      .scopes("read", "write").resourceIds(RESOURCE_ID).secret(app.getClientSecretId()); 
    } 
} 
+0

あなたは大歓迎です! – 11thdimension

関連する問題