【问题标题】:Web Api token Bearer authorization failsWeb Api 令牌承载授权失败
【发布时间】:2017-08-09 15:40:54
【问题描述】:

有人能告诉我为什么吗?

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-09-24
      • 2020-08-28
      • 2016-10-31
      • 2014-09-19
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 2021-07-23
      • 2021-03-07
      相关资源
      最近更新 更多