Skip to content

OktaAuthStateService.authState does not correctly reflect user's state when user is authenticated but not authorized #94

@nathaniellee87

Description

@nathaniellee87

Describe the bug?

OktaAuthStateService.authState does not correctly reflect user's state when user is authenticated but not authorized. The OktaAuthStateService.authState.isAuthenticated member has the value of false and OktaAuthStateService.authState..idToken is undefined after the user has successfully logged in and been authenticated. However, the user is not authorized and receives the error "OAuthError: User is not assigned to the client application". Okta Angular treats the user as logged in when I run OktaAuth.signInWithRedirect() (it doesn't not redirect me, but recognizes I'm authenticated and just redirects me to the callback). If I run OktaAuth.signOut(), it successfully signs me out and redirects me to the Okta login page. Despite this, the OktaAuthStateService.authState does not correctly reflect the user's state.

What is expected to happen?

The OktaAuthStateService.authState should correctly reflect the user's state (such as being authenticated but not authorized). User information (such is via [OktaAuthStateService.authState.idToken)] should be provided so that the user's state can be correctly displayed on the UI (such as user's name).

What is the actual behavior?

OktaAuthStateService.authState does not correctly reflect the user's state; if the user is authenticated but not authorized, OktaAuthStateService.authState.isAuthenticated is false and no user information is provided for the authenticated user (such is via OktaAuthStateService.authState.idToken).

Reproduction Steps?

  1. Add Okta configuration to app.module.ts per Okta documentation with pkce: true
  2. Add guards and callback to Routes array per Okta documentation
  3. Do NOT assign the user to the application
  4. Navigate to the with the protected route of web app to initiate login redirect
  5. Log in
  6. View the OktaAuthStateService.authState object to see if it reflects the user's state.

SDK Versions

"@angular/animations": "=13.1.2",
"@angular/cdk": "=12.2.0",
"@angular/common": "=13.1.2",
"@angular/compiler": "=13.1.2",
"@angular/core": "=13.1.2",
"@angular/forms": "=13.1.2",
"@angular/material": "=12.2.0",
"@angular/platform-browser": "=13.1.2",
"@angular/platform-browser-dynamic": "=13.1.2",
"@angular/router": "=13.1.2",
"@azure/msal-angular": "=2.0.5",
"@azure/msal-browser": "=2.19.0",
"@microsoft/signalr": "=6.0.1",
"@okta/okta-angular": "=5.2.0",
"@okta/okta-auth-js": "=6.5.0",
"ajv": "=6.12.3",
"rxjs": "=6.6.0",
"tslib": "=2.3.0",
"zone.js": "=0.11.4"

Execution Environment

Chrome Version 101.0.4951.67 (Official Build) (64-bit)
Windows 10 Version 20H2 (19042.1706)
Angular 13

Additional Information?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions