Ember Simple Auth OpenID Connect Addon

7.4.1 · active · verified Wed Apr 22

ember-simple-auth-oidc is an Ember.js addon that integrates OpenID Connect (OIDC) Authorization Code Flow into applications utilizing Ember Simple Auth. It provides an `OIDCAuthenticationRoute` for handling authentication, OIDC-aware adapters (`OIDCJSONAPIAdapter`, `OIDCRESTAdapter`) for Ember Data, and middleware for `@ember-apollo-client` to manage authorization headers and token refreshing. The package is actively maintained, with version 7.4.1 being the current stable release as of February 2026, and typically sees monthly or bi-monthly updates for bug fixes and minor features. It supports Ember.js v4.12+, Ember CLI v4.12+, Node.js v18+, and Ember Simple Auth v6+, offering robust OIDC compliance and seamless integration into the Ember ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core setup for `ember-simple-auth-oidc`, including environment configuration, defining an authentication route, securing a protected route, and integrating with Ember Data for authenticated API requests. It also shows an optional setup for Apollo Client integration.

/* config/environment.js */
module.exports = function (environment) {
  let ENV = {
    modulePrefix: 'my-app',
    environment,
    rootURL: '/',
    locationType: 'history',
    EmberENV: {
      FEATURES: {},
      EXTEND_PROTOTYPES: {
        Date: false
      }
    },
    APP: {
      // Here you can pass flags/options to your application instance
      // when it is created
    },
    'ember-simple-auth': {
      authenticationRoute: 'login'
    },
    'ember-simple-auth-oidc': {
      clientId: process.env.OIDC_CLIENT_ID ?? 'my-oidc-client',
      issuer: process.env.OIDC_ISSUER ?? 'https://my-auth-server.com/realms/my-realm',
      redirectUri: process.env.OIDC_REDIRECT_URI ?? 'http://localhost:4200/login',
      scope: 'openid profile email',
      responseType: 'code',
      postLogoutRedirectUri: process.env.OIDC_LOGOUT_URI ?? 'http://localhost:4200/',
      tokenEndpoint: process.env.OIDC_TOKEN_ENDPOINT ?? 'https://my-auth-server.com/realms/my-realm/protocol/openid-connect/token',
      logoutEndpoint: process.env.OIDC_LOGOUT_ENDPOINT ?? 'https://my-auth-server.com/realms/my-realm/protocol/openid-connect/logout'
    }
  };

  return ENV;
};

/* app/routes/login.js */
import OIDCAuthenticationRoute from "ember-simple-auth-oidc/routes/oidc-authentication";

export default class LoginRoute extends OIDCAuthenticationRoute {}

/* app/routes/protected.js */
import Route from "@ember/routing/route";
import { service } from "@ember/service";

export default class ProtectedRoute extends Route {
  @service session;

  async beforeModel(transition) {
    await this.session.requireAuthentication(transition, "login");
  }
}

/* app/adapters/application.js */
import { service } from "@ember/service";
import OIDCJSONAPIAdapter from "ember-simple-auth-oidc/adapters/oidc-json-api-adapter";

export default class ApplicationAdapter extends OIDCJSONAPIAdapter {
  @service session;

  get headers() {
    return { ...this.session.headers, "Content-Language": "en-us" };
  }
}

// Example for Apollo client integration (optional)
/* app/services/apollo.js */
// import { service } from "@ember/service";
// import ApolloService from "ember-apollo-client/services/apollo";
// import { apolloMiddleware } from "ember-simple-auth-oidc";

// export default class CustomApolloService extends ApolloService {
//   @service session;

//   link() {
//     const httpLink = super.link();
//     return apolloMiddleware(httpLink, this.session);
//   }
// }

view raw JSON →