Ember CLI Simple Auth
raw JSON → 0.8.0 verified Sat Apr 25 auth: no javascript deprecated
An Ember CLI addon that packages the Ember Simple Auth base library for use with Ember applications. Version 0.8.0 is deprecated and unmaintained; the project has been superseded by ember-simple-auth. It provides authentication, authorization, and session management for Ember apps. Differentiators: tight integration with Ember CLI; includes generators for custom authenticators, authorizers, session stores, and sessions; configuration via config/environment.js.
Common errors
error Cannot find module 'ember-cli-simple-auth' ↓
cause Package not installed or not added to package.json.
fix
Run
ember install ember-cli-simple-auth to install and add to dependencies. error Uncaught TypeError: Cannot read property 'authenticate' of undefined ↓
cause Session service not injected or session property is undefined.
fix
Ensure you have the session service injected: session: Ember.inject.service().
error Assertion Failed: Unable to find authenticator: simple-auth-authenticator:oauth2-password-grant ↓
cause Missing or misspelled authenticator name; the authenticator must be registered.
fix
Check that the authenticator is correctly registered, e.g.,
export default Ember.SimpleAuth.Authenticators.OAuth2PasswordGrant.extend(...) or installed via addon. error The `ember-cli-simple-auth` addon requires an Ember CLI version of 0.0.44 or above ↓
cause Ember CLI version is too old.
fix
Upgrade Ember CLI to at least 0.0.44.
Warnings
deprecated This package is deprecated. Use ember-simple-auth instead. ↓
fix Replace with ember-simple-auth: remove ember-cli-simple-auth, add ember-simple-auth, update imports and configuration.
breaking Requires at least Ember CLI 0.0.44; incompatible with older versions. ↓
fix Upgrade Ember CLI to at least 0.0.44.
gotcha Installation command differs based on Ember CLI version: for 0.2.2 or older use `ember install:addon`, for 0.1.4 or older use manual npm + generate. ↓
fix Use `ember install ember-cli-simple-auth` for modern Ember CLI (>=0.2.3).
gotcha The addon automatically initializes; manual import of the main module is not required and may cause issues. ↓
fix Do not manually import 'ember-cli-simple-auth' in your app unless you have a specific reason.
Install
npm install ember-cli-simple-auth yarn add ember-cli-simple-auth pnpm add ember-cli-simple-auth Imports
- default wrong
const SimpleAuth = require('ember-cli-simple-auth')correctimport SimpleAuth from 'ember-cli-simple-auth' - Authenticator wrong
import { Authenticator } from 'ember-cli-simple-auth'correctimport Authenticator from 'ember-cli-simple-auth/authenticators/base' - Authorizer wrong
import { Authorizer } from 'ember-cli-simple-auth'correctimport Authorizer from 'ember-cli-simple-auth/authorizers/base' - Session wrong
import { Session } from 'ember-cli-simple-auth'correctimport Session from 'ember-cli-simple-auth/sessions/base' - SessionStore wrong
import { SessionStore } from 'ember-cli-simple-auth'correctimport SessionStore from 'ember-cli-simple-auth/stores/base'
Quickstart
// Install the addon
ember install ember-cli-simple-auth
// Configure in config/environment.js
module.exports = function(environment) {
var ENV = {
// ... other config
'simple-auth': {
routeAfterAuthentication: '/protected',
serverTokenEndpoint: '/api/token',
serverTokenRevocationEndpoint: '/api/revoke'
}
};
return ENV;
};
// Use the session in a route or controller
import Session from 'ember-cli-simple-auth/sessions/base';
export default Ember.Controller.extend({
session: Ember.inject.service(),
actions: {
login: function() {
this.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', {
identification: this.get('username'),
password: this.get('password')
});
},
logout: function() {
this.get('session').invalidate();
}
}
});