Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not staying authenticated after successfully authenticating #1434

Open
briclabs opened this issue Sep 4, 2024 · 3 comments
Open

Not staying authenticated after successfully authenticating #1434

briclabs opened this issue Sep 4, 2024 · 3 comments

Comments

@briclabs
Copy link

briclabs commented Sep 4, 2024

Describe the bug
I'm using Authentik as my identity provider, and can see that when I click login, it is in fact redirecting to Authentik and authenticating. However, it then redirects back to my app like its supposed to, but it doesn't retain state: it forgets it just authenticated. I feel like its reloading the SPA and in doing so is losing knowledge of the access token etc that it just got back from Authentik? It then tries to do it again, causing it to loop indefinitely, authenticating successfully each time and promptly forgetting it did so every time as well. Very confused.

AuthConfig:

export const authCodeFlowConfig: AuthConfig ={
  issuer: 'http://localhost:9000/application/o/evcoordinator/',
  tokenEndpoint: 'http://localhost:9000/application/o/token/',
  redirectUri: window.location.origin,
  requireHttps: false,
  clientId: 'evcoordinator',
  responseType: 'code',
  scope: 'openid profile email offline_access',
  useSilentRefresh: true,
  showDebugInformation: true,
  strictDiscoveryDocumentValidation: false,
}

Constructor of a service that is injected into my component:

  constructor(private readonly oauthService: OAuthService, private httpClient: HttpClient) {
    oauthService.configure(authCodeFlowConfig);
    oauthService.loadDiscoveryDocument()
      .then( () => {
      oauthService.tryLoginCodeFlow().then( () => {
        if (!oauthService.hasValidAccessToken()) {
          oauthService.initLoginFlow();
        } else {
          oauthService.loadUserProfile().then( (userProfile) => {
            console.log(JSON.stringify(userProfile));
          })
        }
      })
    })
  }

Credit to https://www.youtube.com/watch?v=QV5YtczsorY for getting me this far. This seems like it should work. I feel like I must be missing something pretty simple but I can't figure out what it is.

@Menschomat
Copy link

Did you find any solution for authentik?

@briclabs
Copy link
Author

briclabs commented Sep 9, 2024

No sir; dunno why what I posted wouldn't work.

@briclabs
Copy link
Author

I just confirmed the same code does the same thing with Keycloak. This makes no sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants