【发布时间】:2021-09-09 18:00:45
【问题描述】:
我正在尝试使用authorization_code 授权流程设置我的身份验证。我之前使用过grant_type=password,所以我知道这些东西应该如何工作。但是当使用grant_type=authorization_code 时,我无法让它返回invalid_grant以外的任何东西
这是我的设置:
app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/auth/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(5),
Provider = new SampleAuthProvider()
});
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
{
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
AuthenticationType = "Bearer"
});
SampleAuthProvider 是以下类:https://gist.github.com/anonymous/8a0079b705423b406c00
基本上,它只是记录每一步并对其进行验证。我尝试了请求:
POST http://localhost:12345/auth/token
grant_type=authorization_code&code=xxxxxx&client_id=xxxxx&redirect_uri=https://xxxx.com/
Content-Type: application/x-www-form-urlencoded
它正在经历:
OnMatchEndpointOnValidateClientAuthentication
仅此而已。我预计它会调用OnValidateTokenRequest 和OnGrantAuthorizationCodenext,但它没有。我不知道为什么。
请求中的xxxx 不是占位符,我试过这样。也许中间件会自行进行一些检查并因此拒绝请求?我尝试了redirect_uri 和http 的变体,没有任何协议,没有斜杠...
它也适用于自定义grant_type。所以如果我太绝望了,我想我可以用它来模拟authorization_code,但我宁愿不必那样做。
TL;DR
当使用grant_type=authorization_code 时,我的OAuthAuthorizationServerProvider 在OnValidateClientAuthentication 之后返回{"error":"invalid_grant"}。
- 为什么会停在那里?
- 我怎样才能让整个该死的东西发挥作用?
感谢您的帮助!
编辑
正如 RajeshKannan 所指出的,我在配置中犯了一个错误。我没有提供AuthorizationCodeProvider 实例。但是,这并没有完全解决问题,因为在我的例子中,代码不是由AuthorizationCodeProvider 发布的,我不能只是反序列化它。我接受了我正在工作的解决方法。
【问题讨论】:
标签: asp.net oauth-2.0 owin owin.security