AngularJS Send authentication token http header
In this Post We Will Explain About is AngularJS Send authentication token http header With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to AngularJS: Send auth token with every requestExample
In this post we will show you Best way to implement send custom access token as http request, hear for how to add access token in angularjs httpwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
send custom access token as http request
[php]
$http({
method: “post”,
url: apiPath.addPostComment,
data: {
SocialPostId: liveid,
CommentDescription: message,
CommentedUserId: userdataid,
CommentedDate: new Date()
},
params: {
action: “post”
},
headers: {
‘Authorization’: ‘bearer ‘ + accessToken
}
});
[/php]
Add access token to every request header in Angular js
[php]
$httpProvider.interceptors.push(function($q, $cookies) {
return {
‘request’: function(parmconfig) {
parmconfig.headers[‘Token’] = $cookies.loginTokenCookie;
return parmconfig;
}
};
});
[/php]
AngularJS: Send auth token with every request
Build a RESTful resource
[php]
angular.module(‘liveApp.services’, [‘ngResource’])
.factory(‘Todo’, [‘$resource’,
function($resource) {
var resource =
$resource(‘http://infinityknow.com/todos/:id’, {
port:”:3001″,
id:’@id’
}, {
update: {method: ‘PUT’}
});
return resource;
}])
[/php]
AngularJS All The Methods pass header
[php]
{ ‘get’: {method:’GET’},
‘save’: {method:’POST’},
‘query’: {method:’GET’, isArray:true},
‘remove’: {method:’DELETE’},
‘delete’: {method:’DELETE’} };
[/php]
Send auth token with every request
[php]
.factory(‘TokenHandler’, function() {
var get_totkenhandler = {};
var token = “none”;
get_totkenhandler.set = function( my_newtoken ) {
token = my_newtoken;
};
get_totkenhandler.get = function() {
return token;
};
[/php]
I hope you have Got What is AngularJS: Send auth token with every request And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.