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.

onAuthorizationResultComplete doesn't return AuthorizationResult.authorized

See original GitHub issue

I am trying to implement some code that runs after the AuthorizationResult is complete and authorized. In my own code (based on your dotnet-angular-azure-ad-oidc sample), I consistently get AuthorizationResult.unauthorized returned when the user is unauthorized. However, I cannot get it to returnAuthorizationResult.authorized ever. To be clear, the authorization is successful, as I am able to see the token, and use the getIsAuthorized to change the nav bar.

In the constructor, I have:

    this.oidcSecurityService.onAuthorizationResult.subscribe(
      (authorizationResult: AuthorizationResult) => {
        this.onAuthorizationResultComplete(authorizationResult);
      });

which calls

  private onAuthorizationResultComplete(authorizationResult: AuthorizationResult) {
    console.log('AppComponent:onAuthorizationResultComplete');
    const path = this.read('redirect');
    if (authorizationResult === AuthorizationResult.authorized) {
      this.router.navigate([path]);
    } else {
      this.router.navigate(['/Unauthorized']);
    }
  }

But as I said above, this only ever gets AuthorizationResult.unauthorized passed into it. My hope is to add my own post-successful login code into the AuthorizationResult.authorized code block above.

I have noticed that whether I run your sample code (pointing to our Azure AD), or my own code, that I get a TypeError: Cannot read property 'toLowerCase' of undefined, which may or may not be related.

stack:"TypeError: Cannot read property 'toLowerCase' of undefined\n    at HttpXsrfInterceptor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http://localhost:4200/vendor.js:8032:29)\n    at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http://localhost:4200/vendor.js:7412:33)\n    at HttpInterceptingHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http://localhost:4200/vendor.js:8085:27)\n    at MergeMapSubscriber.project (http://localhost:4200/vendor.js:7163:184)\n    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (http://localhost:4200/vendor.js:79776:27)\n    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (http://localhost:4200/vendor.js:79766:18)\n    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (http://localhost:420...

Finally, I do have the configuration set to call that event handler:

      openIDImplicitFlowConfiguration.trigger_authorization_result_event = true;

This is with Angular 6.0.5 (sample code) and 5.2.9 (my code) on Node 8.11.1.

Any suggestions or ideas?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
patrickgardellacommented, Jun 28, 2018

PR 246 submitted

1reaction
patrickgardellacommented, Jun 28, 2018

I figured it out!

Azure AD, which we are authenticating against, has not implemented the UserInfo end point. The default setting for auto_userinfo here in AuthConfiguration is “true”. This causes execution to go down the path:

 if (this.authConfiguration.auto_userinfo) {
                    this.getUserinfo(
                        isRenewProcess,
                        result,
                        validationResult.id_token,
                        validationResult.decoded_id_token
                    ).subscribe(response => {
                        if (response) {
                            this.onAuthorizationResult.emit(AuthorizationResult.authorized);
                            if (!this.authConfiguration.trigger_authorization_result_event && !isRenewProcess) {
                                this.router.navigate([
                                    this.authConfiguration.post_login_route
                                ]);
                            }
                        } else {
                            this.onAuthorizationResult.emit(AuthorizationResult.unauthorized);
                            if (!this.authConfiguration.trigger_authorization_result_event && !isRenewProcess) {
                                this.router.navigate([
                                    this.authConfiguration.unauthorized_route
                                ]);
                            }
                        }
                    });

That subscribe doesn’t have a catch/catchError associated with it, so it just never executes. Hence, no AuthorizationResult.authorized is ever emitted, and the onAuthorizationResultComplete is never called.

Setting openIDImplicitFlowConfiguration.auto_userinfo = false; in app.module.ts made everything work properly.

I’ll submit a pull request for adding the catch for your review shortly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 5 angular-auth-oidc-client Code Examples - Snyk
private onAuthorizationResultComplete(authorizationResult: ... The ID Token MUST be rejected if the ID Token does not list the Client as a valid audience, ...
Read more >
Auto redirect to an STS server in an Angular app using oidc ...
onAuthorizationResultComplete (authorizationResult); ... If the user is not authorized, the auto-login component is called.
Read more >
AuthorizationResult.Failed Method - Microsoft Learn
Contains information about why authorization failed. Returns. AuthorizationResult. The AuthorizationResult. Applies to. ASP.NET Core 7.0 and other versions ...
Read more >
Customizing Authorization Responses in .NET 5.0 - Ben Foster
It would therefore be preferable to return a HTTP 404 - Not Found response. Semantically this also makes sense given that the site...
Read more >
How to mock IAuthorizationService in .net core 2.0
Not much detail here https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authorization.authorizationresult?view=aspnetcore-2.0.
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