AngularJS: Basic example to use authentication in Single Page Application

后端 未结 6 1567
余生分开走
余生分开走 2020-12-02 03:30

I am new to AngularJS and gone through their tutorial and got a feel for it.

I have a backend for my project ready where each of the REST endpoints need

6条回答
  •  忘掉有多难
    2020-12-02 04:05

    var _login = function (loginData) {
     
            var data = "grant_type=password&username=" + loginData.userName + "&password=" + loginData.password;
     
            var deferred = $q.defer();
     
            $http.post(serviceBase + 'token', data, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).success(function (response) {
     
                localStorageService.set('authorizationData', { token: response.access_token, userName: loginData.userName });
     
                _authentication.isAuth = true;
                _authentication.userName = loginData.userName;
     
                deferred.resolve(response);
     
            }).error(function (err, status) {
                _logOut();
                deferred.reject(err);
            });
     
            return deferred.promise;
     
        };
     

提交回复
热议问题