auth0 / angular-jwt

Library to help you work with JWTs on AngularJS
MIT License
0 stars 1 forks source link

Can't inject anything to jwtOptionsProvider tokenGetter config #188

Closed xskid closed 5 years ago

xskid commented 5 years ago
tokenGetter.$inject = ["options", "myService"];
export function tokenGetter (option, myService)  {
  // Skip authentication for any requests ending in .html
  if (options.url.substr(options.url.length - 5) == '.html') {
    return null;
  }
  console.log(myService);
  return localStorage.getItem('jwtKey');
}

And then

appConfig.$inject = ["$httpProvider", "jwtOptionsProvider"];
function appConfig($httpProvider, jwtOptionsProvider) {
  jwtOptionsProvider.config({
    whiteListedDomains: [
      'localhost'
    ],
    tokenGetter : tokenGetter
  });
  $httpProvider.interceptors.push('jwtInterceptor');
}

error Cannot read property 'url' of undefined myService is undefined

I've tried several ways, without success yet

xskid commented 5 years ago

For does with this problem, need o inject jwtInterceptorProvider and put tokenGetter. there, not into jwtOptionsProvider.

appConfig.$inject = ["$httpProvider", "jwtOptionsProvider", "jwtInterceptorProvider"];
function appConfig($httpProvider, jwtOptionsProvider, jwtInterceptorProvider) {
  jwtOptionsProvider.config({
    whiteListedDomains: [
      'localhost'
    ]
  });
  jwtInterceptorProvider.tokenGetter = tokenGetter;
  $httpProvider.interceptors.push('jwtInterceptor');
}

Basic usage does not mention that.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️