For a recent Ember.js + Rails API project, I needed to set up OAuth with support for GitHub. I used the Torii library along with EmberCLI. This a rough, not quite finished version.
- EmberCLI v.1.13.8
- Ember.js v.2.1.0
- Torii v.0.6.1
- Ruby on Rails API v.5
Before you get started
Make sure your app is registered on your GitHub account.
Settings > Applications > Developer Applications
To get things up and running in development, just set
Homepage URL and
Authorization callback URL to
I want to authenticate users who try to visit a page of shared links. Any code references to
links can be interchanged with whichever model you are using in your project.
Add Torii to your
torii in your
Create a new folder called
login route to your
You need to create the
logout hooks in your application route
Create a new route for
Create a new
Template for logging in
Toriii has a helper
authenticatedRoute. I set it up for my
links pages in my
Rails 5 API setup
I setup a
User model in my Rails application. Here’s what my migration file looks like
As I mentioned before, I’m using a
Link feature. I needed three different urls to keep track of the sessions. This is my
To keep my sessions controller “skinny”, I extracted my GitHub API logic into an interactor. After that, this is my
With that, you should have all the pieces you need to get basic OAuth2 functionality with GitHub.