我正在设置我自己的 OAuth2 服务器。到目前为止,我已经成功地实现GrantResourceOwnerCredentials了我的OAuthAuthorizationServerProvider. 现在,因为我正在为我们的业务开发应用程序,所以我想实施 OAuth2 授权代码授权。
我试图按照这里的指示https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server但在我的实施中,我没有找到了如何达到(我在 中设置的)的Create调用。AuthorizationCodeProviderOAuthAuthorizationServerOptions
我已经简要检查了TokenEndpointPath使用(错误的)代码参数访问 是否有效,并且在调试器中我看到我AuthorizationCodeProvider的Receive调用被击中。当然没有成功,因为我发送的代码是“sometestcode”而不是真正的代码,但是代码被命中了,这意味着我走在正确的道路上。
这是我到目前为止所拥有的:
public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
{
if (OAuthRepository.GetClient(context.ClientId) != null)
{
var expectedRootUri = new Uri(context.Request.Uri, "/");
if (context.RedirectUri.StartsWith(expectedRootUri.AbsoluteUri))
{
context.Validated();
return Task.FromResult<object>(null);
}
}
context.Rejected();
return Task.FromResult<object>(null);
}
public override Task AuthorizeEndpoint(OAuthAuthorizeEndpointContext context)
{
// I know this is wrong but it's just a start and not the focus of this SO …Run Code Online (Sandbox Code Playgroud)