什么是"错误":" unsupported_grant_type"在网络Api

时间:2016-06-01 01:36:14

标签: javascript angularjs asp.net-web-api

我正在尝试实现用户登录 并使用angularJS和web Api注销 但服务器总是返回badrequest(400) 例外

错误来自这段代码

AuthApp.factory('authService', ['$http', '$q', 'localStorageService', function ($http, $q, localStorageService) {

   var  authServiceFactory = {};

    var _authentication =
        {
            isAuth: false,
            userName: ""
        };

    // this is the login function
    authServiceFactory.login = function (loginData) {
        var data = "grant_type=password&username=" + loginData.userName + "&password=" + loginData.password;
        var deferred = $q.defer();
       // alert(data);
        $http.post('/token', data, {
            header: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (response) {
            localStorageService.set('authorizationData', { token: response.access_token, userName: response.userName });

            _authentication.isAuth = true;
            _authentication.userName = loginData.userName;

            deferred.resolve(response);

        }).error(function (err) {
            // _logout();
            deferred.reject(err);
        });

        return deferred.promise;
    }

    authServiceFactory.logout = function ()
    {
        localStorageService.remove("authenticationData");
        _authentication.isAuth = false;
        _authentication.userName = "";

    }

    return authServiceFactory;
}]);

使用邮递员进一步查看错误 出现了这个

  

{"错误":" unsupported_grant_type" }

0 个答案:

没有答案