1

Web APIで、要求のCookiesヘッダーからアクセストークンを取得し、トークンの検証を行います。現時点では、IdentityServer3.AccessTokenValidationパッケージはベアラトークンの検証を行うために使用され、認証ヘッダーのみからトークンを探します。可能であれば、同じベアラトークン検証プロセスを使用したいと思いますが、Cookiesヘッダーからトークンを取得すると、そのサウンドは便利なコードで実行できますか?おかげカスタマイズされたヘッダーからアクセストークンを取得します。

答えて

2

ちょうどあなた自身のTokenProviderを実装し、AccessTokenValidationMiddlewareにそれを提供します。あなたのStartup.cs

public class MyCustomTokenProvider : IOAuthBearerAuthenticationProvider 
{ 
    public Task RequestToken(OAuthRequestTokenContext context) 
    { 
     if (context.Token == null) 
     { 
      //try get from cookie 
      var tokenCookie = context.Request.Cookies["myCookieName"]; 

      if (tokenCookie != null) 
      { 
       context.Token = tokenCookie; 
      } 
     } 

     return Task.FromResult(0); 
    } 

    public Task ValidateIdentity(OAuthValidateIdentityContext context) 
    { 
     throw new NotImplementedException(); 
    } 

    public Task ApplyChallenge(OAuthChallengeContext context) 
    { 
     throw new NotImplementedException(); 
    } 
} 

app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions 
{ 
    Authority = "http://myhost", 
    RequiredScopes = new[] { "my-scope" }, 
    TokenProvider = new MyCustomTokenProvider() 
}); 
+0

おかげフェデリコ!それも私が考えたものですが、私はRequestTokenメソッドを誤って解釈しました。トークンエンドポイントから新しいトークンを要求するために使用されていると考えました。これは役に立ちます! –

関連する問題