jeudi 2 avril 2015

AngulatJs oAuth2 integration

Hi everyone I am working on an angularjs application in which I need to integrate spring oauth2 provider for login authentication the first which I need to make for authentication is for token the call is post and following things I need to send from angularjs side


URL : http://localhost:8090/oauth/token.


AUTHENTICATION-HEADER : Authorization: Basic


POST_DATA : username=&password=&grant_type=&scope=&client_id=


This is the code how I pass this things :



var req = {
method: 'POST',
url: 'http://localhost:SERVER_PORT/oauth1/token',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic <base64 ID:SECRET>'
},
data: { username=<username>&password=<password>&grant_type=<grant_type>&scope=<scope>&client_id=<client_id>}
}


$http(req).success(function(data, status, headers, config){
var d = data;
$scope.dataLoading = false;
}).error(function(data, status, headers, config){

var d = data;
$scope.dataLoading = false;
});


I have put this code in a controller method and method gets called when user presses login button but this call gives me "401 unauthorised error" desc : "full authentication is required..." but if I check from rest client in chrome it works fine with same data I don't know where i am missing some I know that this errors only comes if my authorization header will not be sent properly.


But I checked all ways to send authorization header in AngularJS...is there any solution to achieve this..?


Aucun commentaire:

Enregistrer un commentaire