okta / okta-oidc-js

okta-oidc-js
https://github.com/okta/okta-oidc-js
Other
395 stars 232 forks source link

using getAccessToken from localhost never resolves promise #821

Open DavidLozzi opened 4 years ago

DavidLozzi commented 4 years ago

I'm submitting this issue for the package(s):

I'm submitting a:

Current behavior

We're using the getAccessToken() method to retrieve the Okta token for our API calls. code below. When running this on localhost it doesn't do anything, I can debug and see the code stops at this line, but never resolves, rejects, anything! Just sits and waits.

If we just read the token from the localStorage directly, everything works, but we don't get the added benefit of renewing our token that getAccessToken() provides us.

Expected behavior

getAccessToken responds and continues our code. The code DOES WORK as expected in our pre-prod and prod environments.

Minimal reproduction of the problem with instructions

our authservice

import { AuthService } from '@okta/okta-react';
import CONFIG from 'config';
import history from './history';

export default new AuthService({
  history,
  issuer: CONFIG.OKTA.ISSUER,
  pkce: false,
  clientId: CONFIG.OKTA.CLIENT_ID,
  redirectUri: `${window.location.origin}${CONFIG.OKTA.REDIRECT_URL}`,
  tokenManager: {
    expireEarlySeconds: (30 * 60)
  }
});

usage with axios

import axios from 'axios';
import authService from 'redux/auth';

axios.defaults.baseURL = CONFIG.SERVER_URL;

axios.interceptors.request.use(async (config) => {
  console.log('before get access token');
  const accessToken = await authService.getAccessToken();
  console.log('after get access token'); // never reaches this line

Extra information about the use case/user story you are trying to implement

I've confirmed the token is in local storage when this runs.

Environment

shuowu-okta commented 4 years ago

@DavidLozzi I suspect the issue may come from axios.interceptors.request.use, can you try adding the rejected function to see if any error can be caught? https://github.com/axios/axios/blob/0d69a79c81a475f1cca6d83d824eed1e5b0b045d/lib/core/InterceptorManager.js#L17