Web Api令牌承载授权失败

时间:2017-08-09 15:40:55

标签: angularjs asp.net-web-api2 owin

有人可以指出我的原因吗?

这是调用需要授权的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();
    }

1 个答案:

答案 0 :(得分:0)

获取新令牌,然后比较您的请求授权标头令牌。也许authService.getToken()返回错误的值。