[英]IdentityServer3 .Net Web API. Getting error - Authorization has been denied for this request
I am trying to setup authentication for my .net webapi using identityserver3. 我正在尝试使用identityserver3为.net webapi设置身份验证。
This is my code in Owin.Startup of the Authentication server project 这是我在Owin.Authentication服务器项目启动中的代码
public class Startup
{
public void Configuration(IAppBuilder app)
{
// hardcoded list of clients, scopes and users
var factory = new IdentityServerServiceFactory()
.UseInMemoryClients(clients)
.UseInMemoryScopes(scopes)
.UseInMemoryUsers(users);
app.UseIdentityServer(new IdentityServerOptions
{
SigningCertificate = new X509Certificate2($@"{AppDomain.CurrentDomain.BaseDirectory}\bin\my_selfsigned_cert.pfx", ConfigurationManager.AppSettings["certificatekey"]),
RequireSsl = false,
Factory = factory
});
}
And the following is the code in my web api owin startup 以下是我的Web API owin启动中的代码
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "http://localhost:45230"
});
app.UseWebApi(GlobalConfiguration.Configuration);
}
}
My authorization server seems to work when I try to login in the identity servers login page. 当我尝试在身份服务器登录页面中登录时,授权服务器似乎可以正常工作。 I am also able to retrieve authorization token by posting to /connect/token
However when I use the bearer token thus received to call my webapi method below, it's always failing with error "{"Message": "Authorization has been denied for this request."} 我还可以通过发布到/connect/token
来检索授权令牌。但是,当我使用收到的承载令牌来调用下面的webapi方法时,它总是失败,并显示错误“ {”消息”:“此请求的授权被拒绝。“}
Api - api-
[HttpGet]
[Authorize]
public IEnumerable<Customer> Get()
{
var customerRepository = new CustomerRepository();
return customerRepository.GetCustomers();
}
Can somebody please suggest what i am missing ? 有人可以建议我缺少什么吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.