我正在使用OAuthAuthorizationServerProvider
Microsoft Owin Security,这是我正在使用的代码,
var oAuthAuthorizationServerOptions = new OAuthAuthorizationServerOptions()
{
TokenEndpointPath = new Microsoft.Owin.PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(5),
AllowInsecureHttp = true,
Provider = new CustomOAuthProvider()
};
CustomOAuthProvider,
public class CustomOAuthProvider : OAuthAuthorizationServerProvider
{
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
var lstClients = ClientService.GetClients();
if (lstClients.Count <= 0) return base.ValidateClientAuthentication(context);
context.TryGetFormCredentials(out var clientId, out var clientSecret);
if (lstClients.Count(c => c.ClientId == clientId) > 0
&& lstClients.Count(c => c.ClientPassword == clientSecret) > 0)
{
context.Validated(clientId);
}
return base.ValidateClientAuthentication(context);
}
public override Task GrantClientCredentials(OAuthGrantClientCredentialsContext context)
{
var claimsIdentity = new ClaimsIdentity(context.Options.AuthenticationType);
claimsIdentity.AddClaim(new Claim(ClaimTypes.Name, context.ClientId));
var props = new AuthenticationProperties(new Dictionary<string, string>
{
{ "client_id", context.ClientId },
{ "scope", string.Join(" ",context.Scope) }
});
var ticket = new AuthenticationTicket(claimsIdentity, props);
context.Validated(ticket);
return base.GrantClientCredentials(context);
}
}
我在这里尝试添加scope
,但看起来这不是正确的添加方式,即使所有看起来都很好并且工作正常,当我尝试查看令牌时,
- 在
jwt.IO
我看到无效签名错误。 - 在
calebb.net
,它是说 - JWT 需要有三个段
这里有什么问题?请建议。