This site is my tutorials, rantings and musings on software development, with a focus on JavaScript, Ember.js, Vue.js and Node.js.

02 Mar 2015

Ember Authentication Tutorial with Ember Simple Auth

Today we are going to dive into creating a simple application with Facebook authentication using ember-simple-auth and Torii.

Ember Simple Auth is a lightweight library for implementing authentication with Ember.js applications. It handles all the session data and makes it really easy to authenticate against external providers or your own server. For the purposes of this tutorial we'll stick with authenticating against Facebook.

Torii is a set of abstractions that is built with a number of providers and a session manager. We'll be using the facebook-oauth2 provider that comes with Torii.

The last command will install the ember-cli-simple-auth addon. You'll need both addons and the torii npm for everything to work, at least as of ember-cli 0.2.0-beta.1.

Next we'll need to edit the config/environment.js file and add our authorizer. Since we are using Torii we have several built in providers we can use. We'll go ahead and configure the one for Facebook.

Routes and Templates

Ember Simple Auth comes with several application mixins. Let's set one up with the application route. By adding the ApplicationRouteMixin to the application route we can now access the session property from anywhere in our program.