Web API oauth承载令牌身份验证在Edge浏览器中不起作用

时间:2016-05-25 20:05:54

标签: asp.net authentication oauth access-token microsoft-edge

我使用Web API oauth bearer token authentication + AngularJs from here 它适用于其他浏览器,但在Microsoft Edge中它不起作用。 在这个浏览器中,我从服务器获取令牌,但仍留在此页面中, 虽然浏览器必须重定向到另一个页面。 我认为当我将令牌数据设置为本地存储时会出现问题。 我是这样做的

if (loginData.useRefreshTokens) {
            localStorageService.set('authorizationData', { token: response.access_token, userName: loginData.userName, refreshToken: response.refresh_token, useRefreshTokens: true });
        }
        else {
            localStorageService.set('authorizationData', { token: response.access_token, userName: loginData.userName, refreshToken: "", useRefreshTokens: false });
        }

1 个答案:

答案 0 :(得分:0)

问题是当我对web api方法进行http获取请求时,检查当前用户是否通过这种方式需要角色

AngularJS

 $http({
        method: "GET",
        url: "api/Models/CheckAccess/"
    }).then(function mySucces(response) {
        if (response.data === true) {
            $location.path(page);
        }
        else
        {
            authServiceFactory.logOut();
            $location.path("login");
        }

    });

WebApi方法

    [HttpGet]
    public bool CheckAccess()
    {
        var identity = (ClaimsPrincipal)Thread.CurrentPrincipal;        
        var userRole = identity.Claims.Where(c => c.Type == ClaimTypes.Role)
                           .Select(c => c.Value).SingleOrDefault();
        if (userRole=="Hauler")
        {
            return true;
        }
        else
        {
            return false;
        }      
    }

在Edge浏览器中,它总是返回false。我通过这种方式解决了这个问题

    [HttpGet]
    [Authorize(Roles = "Hauler")]
    public bool CheckAccess()
    {      
        return true;
    }