Registering Plugin aurelia-open-id-connect in Aurelia 2

I am working on Aurelia 2 app and need to use above mentioned plugin for identityserver4. I don’t know how to register the plugin.

Aurelia
// .register(RouterConfiguration)
// To use HTML5 pushState routes, replace previous line with the following
// customized router config.
.register(RouterConfiguration.customize({ useUrlFragmentHash: false }))
.register((‘aurelia-open-id-connect’), () => oidcConfig)
.app(App)
.start();

Is above correct? Because when in app.ts I am specifying in constructor

 export class App {
    constructor( private openIdConnect: OpenIdConnect) {}
}

Its giving me error as below and not resolving.

di.js:548 Uncaught TypeError: Illegal constructor
    at Object.invoke (di.js:548)
    at Factory.construct (di.js:509)
    at Resolver.resolve (di.js:457)
    at Container.get (di.js:812)
    at Object.invoke (di.js:572)
    at Factory.construct (di.js:509)
    at Resolver.resolve (di.js:457)
    at Container.get (di.js:812)
    at Object.invoke (di.js:572)
    at Factory.construct (di.js:509)
2 Likes

I wouldn’t expect this plugin to work with V2, the plugin registration model has changed in V2 and I’m putting development on-hold till:

  • the V2 router API has stabilized
  • the pre-beta package is released
  • there are docs available on how to build a plugin in V2

For now, I propose you use the oidc-client library directly in V2, this works fine, you just need to handle the routing stuff yourself for now

2 Likes

Damn, I was thinking let me prepare myself for v2 and once the alpha/beta release I am prepared. Especially got excited more after seeing router video (jwx) on Youtube. Bummer.

@arnederuwe do you have any sample / code for this requirement to look at, will be very helpful. Thanks

2 Likes

I understand your frustration, for me it’s a matter of efficiency though, I don’t have a lot of spare time, so the longer I wait the more efficient I will be in building a plugin for V2…
You should be able to do something like this in V2 with just oidc-client:

import { UserManager, User } from "oidc-client";
import oidcConfig from "./oidc-config";

export class MyApp {
  public user: User;
  private userManager: UserManager;

  constructor() {
    this.userManager = new UserManager(oidcConfig);
  }

  public async beforeBind() {
    let user = await this.userManager.getUser();
    //user found, see if its session is still valid
    if (user) {
      try {
        let status = await this.userManager.querySessionStatus();
        this.user = user;
      } catch (ex) {
        this.userManager.removeUser();
      }
    } else {
      try {
        this.user = await this.userManager.signinSilent();
      } catch (ex) {
        this.userManager.signinRedirect();
      }
    }

    this.userManager.events.addUserLoaded(async () => {
      this.user = await this.userManager.getUser();
    });
  }
}

This is very POCy :slight_smile: you would want to abstract this away in a service, but you get the idea

2 Likes

Thanks and noted.

I will check the code and get back if anything

1 Like