OktaAuth token manager add & get

Hi,

I am setting up the frontend web site (with AngularJS v1.2.14) to interact with a Web API using an Authorization Bearer Token.

I’ve set up OktaAuth (okta/okta-auth-js) like so:

var authClient = new OktaAuth({
        url: '<okta_server>',
        clientId: '<client_secrete>',
        redirectUri:'<redirect_url>'
});

then calling authClient.token.getWithoutPrompt, I get the token successfully, and save it to tokenManager:

authClient.tokenManager.add('tokenKey', token);

However, immediately after, trying to get the same token, I can’t retrieve it from tokenManager, like so:

authClient.tokenManager.get('tokenKey');

I get no errors in console. I can’t seem to figure out what’s going on here.

Does anyone have any idea why this is not working?

Thanks.

Regards,
Nuno

I figure it out.

The add and get are JS promises.

So, the correct way is:

authClient.tokenManager.get(tokenKey)
                        .then(token => {                           
                            console.log(token.idToken);
                        });

Another way would be to use async-await keywords, but then we would have potential Browser compatibility issues.

Cya
Nuno