Skip to content

Instantly share code, notes, and snippets.

View mkhizeryounas's full-sized avatar
:octocat:
Creating

Khizer Younas mkhizeryounas

:octocat:
Creating
View GitHub Profile
@mkhizeryounas
mkhizeryounas / bearerHttpInterceptor
Created April 25, 2018 19:18 — forked from antoniocapelo/bearerHttpInterceptor
AngularJS HTTP Interceptor for Bearer Token Auth Requests
app.factory('BearerAuthInterceptor', function ($window, $q) {
return {
request: function(config) {
config.headers = config.headers || {};
if ($window.localStorage.getItem('token')) {
// may also use sessionStorage
config.headers.Authorization = 'Bearer ' + $window.localStorage.getItem('token');
}
return config || $q.when(config);
},