stormpath / stormpath-sdk-angular

Angular Components for Stormpath

Home Page:https://docs.stormpath.com/angular/api/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow users to get an AccessToken before making Http calls

mraible opened this issue · comments

From the AngularJS implementation:

// This access token getter attempts to refresh expired access tokens if needed, which is why it is async (promise)

$auth.getAccessToken()
  .then(function(accessToken){
    $http({
      url: 'http://localhost:3000/api/subscription',
      method: 'GET',
      headers: {
        Authorization: 'Bearer ' + accessToken
      }
    );
  })
  .catch(function(){
    // Could not get access token, user is not logged in
  });

If access token is expired, it will automatically try to get a new one with a refresh token.

Consider implementing stormpath/stormpath-sdk-react#175 as part of resolving this issue.