You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
|
4 years ago
|
using Microsoft.Owin.Security.OAuth;
|
||
|
|
using System;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
|
||
|
|
namespace SpaAspNetCore.Providers
|
||
|
|
{
|
||
|
|
public class ApplicationOAuthProvider : OAuthAuthorizationServerProvider
|
||
|
|
{
|
||
|
|
private readonly string _publicClientId;
|
||
|
|
|
||
|
|
public ApplicationOAuthProvider(string publicClientId)
|
||
|
|
{
|
||
|
|
if (publicClientId == null)
|
||
|
|
{
|
||
|
|
throw new ArgumentNullException("publicClientId");
|
||
|
|
}
|
||
|
|
|
||
|
|
_publicClientId = publicClientId;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
|
||
|
|
{
|
||
|
|
if (context.ClientId == _publicClientId)
|
||
|
|
{
|
||
|
|
Uri expectedRootUri = new Uri(context.Request.Uri, "/");
|
||
|
|
|
||
|
|
if (expectedRootUri.AbsoluteUri == context.RedirectUri)
|
||
|
|
{
|
||
|
|
context.Validated();
|
||
|
|
}
|
||
|
|
else if (context.ClientId == "web")
|
||
|
|
{
|
||
|
|
var expectedUri = new Uri(context.Request.Uri, "/");
|
||
|
|
context.Validated(expectedUri.AbsoluteUri);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return Task.FromResult<object>(null);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|