2016-01-12 8 views
5

私たちはoauth 2サーバーとapiサーバー(どちらも異なるサーバー)を実装しようとしています。独自のoauth2サーバーとapiサーバーを実装しています

enter image description here

たちはhttps://github.com/FrankHassanabad/Oauth2orizeRecipes認証コードが

流れています。(すべてのために使用してnodejsは)我々はOAuthのサーバーで新しいvalidateToken関数を記述し、ちょうどそのユーザを認証するためのAPI側からそれをヒットする必要がありますのみ。

私たちはoauth側でユーザーと役割を維持することを考えていますが、api呼び出し応答を与える前にapi側で確認する必要があります。

私たちはcmsとモバイルアプリの認証目的でもこの機能を使用しようとしています。私たちは正しい軌道に乗っているか、何かが足りない。

答えて

0

あなたがOAuthのを使用している場合は、[いいえ、あなたは新しい検証トークンメソッドを記述する必要はありません

を(私はそのためのコンテキストで、.NETで似たような状況に直面しました)。 OAuthBearerAuthenticationProviderとして は、舞台裏で(私の経験による)

app.UseJwtBearerAuthentication(
      new JwtBearerAuthenticationOptions 
      { 
       AuthenticationMode = AuthenticationMode.Active, 
       AllowedAudiences = new[] { audience }, 
       IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[] 
       { 
        new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret) 
       }, 
       Provider = new OAuthBearerAuthenticationProvider 
        { 
         OnValidateIdentity = context => 
         { 
          context.Ticket.Identity.AddClaim(new System.Security.Claims.Claim("newCustomClaim", "newValue")); 
          return Task.FromResult<object>(null); 
         } 
        } 

      }); 

これを行います。しかし、あなたがしたい場合は、プロバイダを設定するためのオプションは、あなたの「起動」ファイルにあります:

app.UseJwtBearerAuthentication(
      new JwtBearerAuthenticationOptions 
      { 
       AuthenticationMode = AuthenticationMode.Active, 
       AllowedAudiences = new[] { audience }, 
       IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[] 
       { 
        new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret) 
       }, 
       Provider = new CustomOAuthBearerProvider()       

      }); 

「CustomOAuthBearerProviderは」RequestToken()メソッドのシグネチャを事前に定義している「IOAuthBearerAuthenticationProvider」インターフェースを継承し、この方法は、前に呼び出されますトークンの検証。だから私はトークンのカスタム検証作業のためにそれを使用し、OAuth検証のためのトークンを送信することができると思います。

関連する問題