如何使用OWIN OAuthBearerAuthentication验证访问令牌?

问题描述 投票:9回答:1

我想要的:

  1. 令牌生成器使用OAuthAuthorizationServer,而令牌使用者使用OAuthBearerAuthentication(对访问令牌进行身份验证。)>
  2. 使用OWIN管道管理所有内容,令牌内容和Web API内容。
  3. 代码呢:

public void Configuration(IAppBuilder app)
{
    app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
    {
        AuthorizeEndpointPath = "/Authorize",
        AllowInsecureHttp = true,
        Provider = new OAuthAuthorizationServerProvider 
        {
            OnGrantCustomExtension = GrantCustomExtension,
            OnValidateClientRedirectUri = ValidateClientRedirectUri,
            OnValidateClientAuthentication = ValidateClientAuthentication,
        }
    });

    app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
    {
        Provider = new OAuthBearerAuthenticationProvider 
        { 
            //Handles applying the authentication challenge to the response message.
            ApplyChallenge=MyApplyChallenge,

            //Handles processing OAuth bearer token.
            RequestToken=MyRequestToken,

            //Handles validating the identity produced from an OAuth bearer token.
            ValidateIdentity = MyValidateIdentity,
        }
    });

    app.UseWebApi(new WebApplication3.Config.MyWebApiConfiguration());
}

有什么问题:

  1. OAuthBearerAuthenticationProvider的3个属性,ApplyChallengeRequestTokenValidateIdentity。如何实现3方法?

  2. 在令牌认证过程中,我认为是解密访问令牌,从客户端验证令牌,如果令牌已验证,则将令牌的标识放入HttpContext.Current.User

  3. OAuthBearerAuthenticationProvider的责任是履行先前的步骤。我说的对吗?

我想要的是:令牌生成器使用OAuthAuthorizationServer,而令牌使用者使用OAuthBearerAuthentication(对访问令牌进行身份验证)。使用OWIN管道来管理所有东西,令牌东西和...

asp.net asp.net-web-api oauth-2.0 owin
1个回答
7
投票

您知道,UseOAuthAuthorizationServer负责验证用户的工作。然后,UseOAuthBearerAuthentication的任务是确保只有经过身份验证的用户才能访问您的应用程序。通常,这两个作业分配给不同的Web应用程序。看来您的应用程序同时在做。

© www.soinside.com 2019 - 2024. All rights reserved.