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

Newbie question #25

Closed
stuartbloom opened this issue Mar 29, 2017 · 7 comments
Closed

Newbie question #25

stuartbloom opened this issue Mar 29, 2017 · 7 comments
Labels

Comments

@stuartbloom
Copy link

stuartbloom commented Mar 29, 2017

Hi there, and thank you for this plugin.

Although I am getting compilation errors when running the cloned demo, I am able to get it to connect ot my token server and make api calls :)

Just wondering; is it possible to use the plugin and forward the application to the token server when the application starts?

Thanks again

@shaunluttin
Copy link
Collaborator

Yes, that would be possible.

@stuartbloom
Copy link
Author

@shaunluttin Thant's great, would you have an example?

@shaunluttin
Copy link
Collaborator

shaunluttin commented Apr 7, 2017

Hmm. I don't have an example of that off the top of my head. I've been away from this project for some time now. We can chat about it in this issue, and you'll need to do a lot of the leg work yourself while I can guide you in the right direction.

On application startup, to forward the app to the authorization service, you will need to trigger this:

https://github.com/shaunluttin/aurelia-open-id-connect/blob/master/src/open-id-connect-navigation-strategies.ts#L15-L18

    public login(instruction: NavigationInstruction): Promise<any> {
        let args: any = {};
        return this.userManager.signinRedirect(args);
    }

That is exactly what the existing login route does.

https://github.com/shaunluttin/aurelia-open-id-connect/blob/master/src/open-id-connect-routing.ts#L27-L42

    private addLoginRoute(routerConfiguration: RouterConfiguration) {
        routerConfiguration.mapRoute({
            name: "login",
            nav: false,
            navigationStrategy: (instruction: NavigationInstruction) => {
                instruction.config.redirect = "";
                return this.openIdConnectNavigationStrategies.login(instruction);
            },
            route: "login",
            settings: {
                roles: [
                    OpenIdConnectRoles.Anonymous,
                ],
            },
        });
    }

So, you need with to call openIdConnectNavigationStrategies.login(instruction) directly or trigger the configured login route.

Does that make sense?

@stuartbloom
Copy link
Author

Thanks, away from desk at the moment, but will have a play after the weekend, have a good one ;)

@AndreSteenbergen
Copy link

AndreSteenbergen commented May 31, 2017

Something like this? (in app.js) and place the aurelia stuff in a div, instead of body. usermanager adds an iframe, which it needs to check the session.

so like this:

<body>
      <div aurelia-app="main"></div>
      <script src="scripts/vendor-bundle.js" data-main="aurelia-bootstrapper"></script>
  </body>
import { inject } from 'aurelia-dependency-injection';
import oidcConfig from "./open-id-connect-configuration";
import { OpenIdConnect, OpenIdConnectRoles } from "aurelia-open-id-connect";

@inject(OpenIdConnect)
export class App {
    constructor(openIdConnect) {
        let self = this;
        this.openIdConnect = openIdConnect;

        let mgr = self.openIdConnect.userManager;
        self.openIdConnect.userManager.getUser().then((user) => {
            if (user) {
                mgr.querySessionStatus().then(
                    function () {
                        self._loadUserDetails(user);
                    },
                    function () {
                        mgr.removeUser();
                    }
                );
            }
            else {
                mgr.signinSilent().then(function (user) {
                    self._loadUserDetails(user);
                }, function () {
                    mgr.signinRedirect({});
                });
            }
        });

        self.openIdConnect.userManager.events.addUserLoaded(() => {
            self.openIdConnect.userManager.getUser().then((user) => {
                self._loadUserDetails(user);
            });
        });
    }

    _loadUserDetails(user) {
        this.user = user;
    }

@shaunluttin
Copy link
Collaborator

shaunluttin commented Jun 7, 2017

Thank-you @AndreSteenbergen for that.

@AndreSteenbergen
Copy link

AndreSteenbergen commented Jun 7, 2017 via email

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

No branches or pull requests

3 participants