@lblod/ember-acmidm-login

Ember addon with a login and logout component for ACM/IDM

Stats

StarsIssuesVersionUpdatedCreatedSize
@lblod/ember-acmidm-login
101.3.0a month ago3 years agoMinified + gzip package size for @lblod/ember-acmidm-login in KB

Readme

ember-acmidm-login

Ember addon providing an Ember Simple Auth authenticator for ACM/IDM and a simple login and switch component.

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v10 or above

Installation

ember install @lblod/ember-acmidm-login

Usage

Add the following configuration of the ACM/IDM OpenId provider to config/environment.js:

torii: {
  disableRedirectInitializer: true,
  providers: {
    'acmidm-oauth2': {
      apiKey: 'your-key',
      baseUrl: 'https://authenticatie-ti.vlaanderen.be/op/v1/auth',
      scope: 'openid rrn vo profile',
      redirectUri: 'https://loket.lblod.info/authorization/callback',
      logoutUrl: 'https://authenticatie-ti.vlaanderen.be/op/v1/logout',
      returnUrl: 'https://loket.lblod.info/switch-login' //optional
    }
  }
}

Add the acmidm-login-service in the backend to provide the necessary API endpoints.

Configure authentication with ember-simple-auth and put the <Acmidm::Login> component on the appropriate pages. This will handle authentication with ACM/IDM automatically.

The <Acmidm::Login> component does not output any HTML so your project will need to provide this. A usage example can be found in the dummy app.

Finally, extend Ember Simple Auth's SessionService and override the handleInvalidation method:

import { inject as service } from '@ember/service';
import BaseSessionService from 'ember-simple-auth/services/session';
import ENV from 'app-name/config/environment';

export default class SessionService extends BaseSessionService {
  @service currentSession;

  handleInvalidation() {
    const logoutUrl = ENV['torii']['providers']['acmidm-oauth2']['logoutUrl'];
    super.handleInvalidation(logoutUrl);
  }
}

User account switching

To support switching accounts without doing a full logout, set the appropriate returnUrl in the torii configuration and set up a switch route. This route should trigger a login, for example:

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class SwitchRoute extends Route {
  @service session;

  async model() {
    try {
      await this.session.authenticate('authenticator:torii', 'acmidm-oauth2');
    }
    catch(e) {
      return 'Fout bij het aanmelden. Gelieve opnieuwe te proberen.';
    }
  }
}

Note that this url should be registered with ACM/IDM

After the switch route is created you can add the <Acmidm::Switch> component were needed.

The <Acmidm::Switch> component does not output any HTML so your project will need to provide this. A usage example can be found in the dummy app.

Contributing

See the Contributing guide for details.

NOTE: There's currently an issue when using this addon with npm link when using in a host app with ember-source < 3.27, see this comment for more information.

License

This project is licensed under the MIT License.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.