有人可以指出我为什么吗?
这是调用需要授权的 API 方法的 angularjs 方法
this.getTasks = function () {
var request = $http({
method: "get",
headers: {
"Authorization": 'Bearer ' + authService.getToken()
},
url: serviceBase + "api/tasks"
});
return request;
};
这是我的配置
public void ConfigureOAuth(IAppBuilder app)
{
OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AuthorizeEndpointPath = new PathString("/api/account/login"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(3),
Provider = new SimpleAuthorizationServerProvider()
};
// Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
app.UseOAuthBearerTokens(OAuthServerOptions);
}
我调用的 API 方法
[Authorize]
public async Task<ICollection<Models.Task>> GetTasks()
{
return await repository.GetAll();
}
获取新令牌,然后比较请求授权标头令牌。也许authService.getToken((返回错误的值。