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.

Event 'discovery_document_loaded' is triggered twice, possibly causing nonce validation to fail

See original GitHub issue

To reproduce

The issue can be verified very simply by editing the sample app in this repo, adding a couple of lines at the beginning of AppComponent.constructor() to log the event

   this.oauthService.events
      .pipe(filter((e) => e.type === 'discovery_document_loaded'))
      .subscribe((e) => console.log( e.type, e['info'] ));

and adding a call to oauthService.initCodeFlow() to AppComponent.configureCodeFlow():

    this.oauthService.configure(authCodeFlowConfig);
    this.oauthService.initCodeFlow();   // ADDED
    this.oauthService.loadDiscoveryDocumentAndTryLogin().then((_) => { ... }

The net effect is, the user cannot login and is redirected to the login page over and over.

Analysis

In oauth-service.ts the discovery_document_loaded event gets published twice, once by loadJwks(), and then again by its caller, loadDiscoveryDocument().

This is probably inefficient but harmless, unless you call initCodeFlow() before invoking loadDiscoveryDocumentAndTryLogin(), as suggested in the “Logging in” section of the README.md file. The code flow init method (see lines 2706-2708 in oauth-service.ts) subscribes to the discovery_document_loaded event, invoking initCodeFlowInternal() when upon reception.

The nonce is created in the course of the execution of this last method.

If the event is thrown twice:

  • (first event received) A nonce is created
  • The login URL is created, including that nonce
  • The browser is redirected to the login page
  • (second event received) A new nonce overwrites the previous one in the session storage
  • The browser is redirected to the app; the URL includes the previous nonce
  • Nonce validation fails: nonce in the session storage does not match what came back from the Identity Provider

I suggest that the discovery_document_loaded event gets published only once.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
amchavancommented, Feb 16, 2022

It’s pretty clear (to me, at least) that initLoginFlow() is an alternative to initCodeFlow(). But right after that, the README continues:

Also – as shown in the readme – you have to execute the following code…

…which (to me, at least) implies: “after you have initialized the code flow, you’ll need to configure the OAuth2 client code and load the discovery document”. That’s what got me.

Minor note: it may be worth it to remove that “-- as shown in the readme --” fragment, since we are in the README file.

Minor suggestion: it may be worth it to combine configuration and initialization in a single method, something like

public configureAndInitLoginFlow( config: AuthConfig ) { ... }
0reactions
manfredsteyercommented, Nov 18, 2022

will be fixed in next version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MsalError Class (Microsoft.Identity.Client) - Azure for .NET ...
Error code returned as a property in MsalException. ... Failed to validate android broker signature ... Possible cause: use of CNG certificates with...
Read more >
SafetyNet Attestation API - Android Developers
The SafetyNet Attestation API provides services for determining whether a device running your app satisfies Android compatibility tests.
Read more >
RFC 3588: Diameter Base Protocol
This document specifies the message format, transport, error reporting, accounting and security services to be used by all Diameter applications.
Read more >
xDS REST and gRPC protocol - Envoy Proxy
xDS REST and gRPC protocol¶. Envoy discovers its various dynamic resources via the filesystem or by querying one or more management servers.
Read more >
64 WSM-00001 to WSM-09029
WSM-00055: The keystore located at {0} cannot be loaded due to {1}. ... Caused by:-{0} ... Cause: Failure occurred while performing nonce Validation....
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