【发布时间】:2014-09-25 15:50:35
【问题描述】:
我想要什么:
- 令牌生成器使用 OAuthAuthorizationServer,令牌消费者使用 OAuthBearerAuthentication(验证访问令牌)。
- 使用 OWIN 管道管理所有内容、令牌内容和 Web api 内容。
代码呢:
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());
}
问题是什么:
-
OAuthBearerAuthenticationProvider的3个属性,ApplyChallenge、RequestToken和ValidateIdentity。如何 实现这3种方法? -
在令牌认证过程中,我的想法是解密访问令牌,从客户端验证令牌,如果令牌被验证,则将令牌的身份放入
HttpContext.Current.User。OAuthBearerAuthenticationProvider的职责是履行 前面的步骤。我说的对吗?
【问题讨论】:
-
你在ASP网站上用过walkthrough吗?
-
@MatthewHaugen 绝对是,但他们没有提到 OAuthBearerAuthenticationProvider 中的 3 个方法
-
请问您为什么要实现它们呢?我的意思是不要误会我的意思,总是知道你所有的选择是件好事。我只是好奇你为什么要在你的情况下覆盖默认行为,这听起来不像你需要任何不寻常的东西。
-
@MatthewHaugen 官方owin中间件的文档很差。 :( 你的意思是中间件已经为我做了解密、验证和放置 Principal @_@ ?
-
如果您遵循该演练,您将获得一个有效的实现。所以是的。在那之后你可能想做其他的事情,但我会首先得到演练所说的工作。但是,是的,我当然同意文档还有待改进。
标签: asp.net asp.net-web-api oauth-2.0 owin