C# Microsoft.Owin.Security.OAuth.OAuthorizationServerProvider-clientId和clientSecret在尝试从Postman生成令牌时为空
我正在为我的asp.net web api 2应用程序使用OWIN安全性,下面是我的auth启动类设置C# Microsoft.Owin.Security.OAuth.OAuthorizationServerProvider-clientId和clientSecret在尝试从Postman生成令牌时为空,c#,asp.net-web-api2,owin,C#,Asp.net Web Api2,Owin,我正在为我的asp.net web api 2应用程序使用OWIN安全性,下面是我的auth启动类设置 public void ConfigureOAuth(IAppBuilder app) { var oAuthServerOptions = new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, TokenEndpointPath
public void ConfigureOAuth(IAppBuilder app)
{
var oAuthServerOptions = new OAuthAuthorizationServerOptions
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new CustomAuthorizationServerProvider()
};
// Token Generation
app.UseOAuthAuthorizationServer(oAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
}
下面是CustomAuthorizationServerProvider
类实现
public class CustomAuthorizationServerProvider : OAuthAuthorizationServerProvider
{
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.TryGetFormCredentials(out var clientId, out var clientSecret);
if (clientId == "987459827985" && clientSecret == "lkfjldsfjkld")
{
context.Validated(clientId);
}
return base.ValidateClientAuthentication(context);
}
public override Task GrantClientCredentials(OAuthGrantClientCredentialsContext context)
{
var oAuthIdentity = new ClaimsIdentity(context.Options.AuthenticationType);
oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, "TestClient"));
var ticket = new AuthenticationTicket(oAuthIdentity, new AuthenticationProperties());
context.Validated(ticket);
return base.GrantClientCredentials(context);
}
}
现在,在尝试使用端点http://localhost:8080/token
,clientId和clientSecret的值都为NULL,因此我得到了“错误”:“无效的\u客户端”
。我错过了什么
编辑:编辑
当我使用raw
作为主体时,我可以看到令牌生成正在工作,客户端和机密都有价值。为什么它不适用于表单数据
查看邮递员文档: 最重要的是: 网站表单通常将数据作为多部分/表单数据发送到API。您可以使用表单数据体选项卡在Postman中复制此内容。表单数据允许您发送键值对,并指定内容类型 通过在web上快速搜索,API需要有一种特殊的处理方式来绑定
多部分/表单数据
i、 e
内容类型很重要。资源所有者密码凭据不提供客户端ID。请查看此链接:但我正在使用客户端凭据流谢谢。我得到了它。