question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AuthConfig is null when calling OAuthService.silentRefresh()

See original GitHub issue

I’m not sure if this is a bug or a wrong configuration in AuthConfig. 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
};

OAuthService 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() );
  }});
}

Then 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 (<anonymou

This is thrown by createLoginUrl because AuthConfig is null. Snippet from chrome debugger

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?

OS: Windows 10 Browser: Chrome/Firefox “version”: “8.0.4”

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
R366Ycommented, Jan 20, 2020

Hi @jeroenheijmans , thank you very much for your answer. I try your approach as you suggested and I’ll let you know the results.

0reactions
jeroenheijmanscommented, Feb 3, 2020

Thanks for getting back to us, hopefully it’ll help others landing here! Good luck!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular-oauth-oidc, AuthConfig is null when calling ...
Angular-oauth-oidc, AuthConfig is null when calling OAuthService. ... Problem comes when I try to refresh the token using silentRefresh() as ...
Read more >
AuthConfig - angular-oauth2-oidc
Defined in projects/lib/src/auth.config.ts:280. Parameters : ... Default value : null ... Default value : 'angular-oauth-oidc-silent-refresh-iframe'.
Read more >
Silent Refresh - angular-oauth2-oidc
To refresh your tokens when using implicit flow you can use a silent refresh. This is a well-known solution that compensates the fact...
Read more >
OAuthService - angular-oauth2-oidc
Performs a silent refresh for implicit flow. Use this method to get new tokens when/before the existing tokens expire. Parameters : Name, Type,...
Read more >
Refreshing a Token when using Implicit Flow (Silent Refresh)
To use this approach, setup a redirect uri for the silent refresh. ... This api will come in the next version import {...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found