2

I have an Angular application that authenticate towards Windows ADFS 2016 using Open Id Connect. The application retrieves access token and id token via implicit flow and it works fine. Problem comes when I try to refresh the token using silentRefresh() as described in the documentation: https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/refreshing-a-token.html

This is the configuration:

const authConfig: AuthConfig = {
issuer: <address to adfs>,
redirectUri: window.location.origin+'/index.html',
silentRefreshRedirectUri: window.location.origin + '/silent-refresh.html',
clientId: '<client-id>',
scope: 'openid email profile',
logoutUrl: window.location.origin+'/logout',
tokenEndpoint: '<adfs address>/adfs/oauth2/token',
loginUrl: '<adfs address>/adfs/oauth2/authorize',
strictDiscoveryDocumentValidation: false,
skipIssuerCheck: true,
oidc: true
};

OAuth configuration

  private configureOauth(){
  this.oauthService.configure(authConfig);
  this.oauthService.tokenValidationHandler = new JwksValidationHandler();
  this.oauthService.setStorage(sessionStorage);
  this.oauthService.setupAutomaticSilentRefresh({});
  this.oauthService.tryLogin({onTokenReceived: context => {
    // tslint:disable-next-line:no-console
    console.debug('logged in');
    // tslint:disable-next-line:no-console
    console.info( this.oauthService.getAccessToken() );
    // tslint:disable-next-line:no-console
    console.info( this.oauthService.getIdToken() );
  }});
}

To refresh the token I call

public triggerSilentRefresh(){
   this
      .oauthService
      .silentRefresh()
      .then(info => console.debug('refresh ok', info))
      .catch(err => console.error('refresh error', err));
}

But I get the following error:

core.js:6014 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'responseType' of null
 TypeError: Cannot read property 'responseType' of null
  at OAuthService.<anonymous> (angular-oauth2-oidc.js:1826)
  at Generator.next (<anonymous>)

This is thrown by createLoginUrl because AuthConfig is null.

    createLoginUrl(state = '', loginHint = '', customRedirectUri = '', noPrompt = false, params = {}) {
    return __awaiter(this, void 0, void 0, function* () {
        /** @type {?} */
        const that = this;
        /** @type {?} */
        let redirectUri;
        if (customRedirectUri) {
            redirectUri = customRedirectUri;
        }
        else {
            redirectUri = this.redirectUri;
        }
        /** @type {?} */
        const nonce = yield this.createAndSaveNonce();
        if (state) {
            state = nonce + this.config.nonceStateSeparator + state;
        }
        else {
            state = nonce;
        }
        if (!this.requestAccessToken && !this.oidc) {
            throw new Error('Either requestAccessToken or oidc or both must be true');
        }
        if (this.config.responseType) { //HERE config is null
            this.responseType = this.config.responseType;

I do not understand how can be null if it has been initialized and I successfully retrieved my access token. Is it something I'm doing wrong or I have missed in the configuration?

r366y
  • 382
  • 6
  • 17

0 Answers0