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

Best approach when all routes requires an authenticated user #45

Open
larserikfinholt opened this issue Dec 1, 2017 · 8 comments
Open

Comments

@larserikfinholt
Copy link

Hi! First, thanks for this plugin, it works great!

In our new app we only allows authenticated users. That is, we dont need a login button. If the user is not logged in, the app should imediatly redirect to the STS (Identityserver).

What are the recommended way of doing this?

This is what we want to achive:

  • As fast/early as possible, check for a already logged in user (Any helper methods for this?)
  • If user is not logged in - redirect to STS
  • If user is logged in - continue booting the app

Are there any build in functionality in the plugin to help with this?

@shaunluttin
Copy link
Collaborator

I can put together a small demo for you later this week. Off the top of my head, I think it is as simple as adding the following to the attached method in app.ts.

this.openIdConnect.observeUser((user: User) => this.user = user);
if (!user) {
    this.openIdConnect.login();
}

See https://github.com/shaunluttin/aurelia-open-id-connect/blob/master/src/open-id-connect.ts for the plugin API. You might also what to try loginSilent() instead of or in addition to login().

@shaunluttin shaunluttin self-assigned this Dec 1, 2017
@larserikfinholt
Copy link
Author

Thanks, I did try something like you descibed, but it sometimes ended in a loop, but I did'nt do much testing. If you would create a small demo, that would be really great!

@shaunluttin
Copy link
Collaborator

Apologies for not having responded. I have been away from the computer for a while.

@shaunluttin
Copy link
Collaborator

This appears to work in the app.ts code:

  public attached() {
    this.openIdConnect.observeUser((user: User) => this.onUserChanged(user));
  }

  private onUserChanged(user: User) {
    this.user = user;
    if (!this.user) {
      this.openIdConnect.login();
    }
  }

@AndreSteenbergen
Copy link

AndreSteenbergen commented Dec 16, 2017

Hi all, I remember I posted a piece of code before as well. On an issue, including a check if the user is still logged in. I'll try to find it.

@AndreSteenbergen
Copy link

Maybe you can find your answer here:
#25

@AndreSteenbergen
Copy link

The login silent call is to check if the current user still has a valid session. Because userdetails are placed in local storage.

@shaunluttin shaunluttin removed their assignment Sep 28, 2018
@arnederuwe
Copy link
Collaborator

I'll see if I can get this baked in, we did something similar in a project of ours

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

No branches or pull requests

4 participants