Skip to content

Instantly share code, notes, and snippets.

@miry
Last active August 29, 2015 14:06
Show Gist options
  • Save miry/37fbc43a11f0b679b3e7 to your computer and use it in GitHub Desktop.
Save miry/37fbc43a11f0b679b3e7 to your computer and use it in GitHub Desktop.

OAth + Rails 4 Tutorial

Step 1: Rails

$ gem install rails
$ rails new oath_provider_sample
$ cd oath_provider_sample
$ git init .
$ git add .
$ git commit -m 'Initial commit'
$ echo "gem 'pg'" >> Gemfile
$ bundle
$ cat > config/database.yml <<EOF
development:
  adapter: postgresql
  database: oath_development
  host: localhost

test:
  adapter: postgresql
  database: oath_development
  host: localhost
EOF
$ rake db:create

Step 2: Devise

url: https://github.com/plataformatec/devise#getting-started

$ echo "gem 'devise'" >> Gemfile
$ bundle
$ rails generate devise:install
$ cat > config/initializers/action_mailer.rb <<EOF
Rails.application.configure do
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
end

EOF
$ rails g devise:views
$ rails generate devise User
$ rake db:migrate
$ vim config/routes.rb # Uncomment or add `root to: "welcome#index"`
$ rails generate controller Welcome index
$ rm test/fixtures/users.yml
$ rake
$ rake routes # Yoou should see devise routes

Step 3: Doorkeeper

url: https://github.com/doorkeeper-gem/doorkeeper

$ echo "gem 'doorkeeper'" >> Gemfile
$ bundle
$ rails generate doorkeeper:install
$ rails generate doorkeeper:migration
$ rake db:migrate
$ rake routes # You should see default routes for oath
$ vim config/initializers/doorkeeper.rb # Add devise auth: `current_user || warden.authenticate!(:scope => :user)`
$ vim app/controllers/welcome_controller.rb # Add restriction filter: `before_action :doorkeeper_authorize!`

Step 4: Javascript libraries

url: https://github.com/emberjs/ember-rails

$ cat >> Gemfile <<EOF
gem 'ember-rails'
gem 'ember-source', '1.5.0' # or the version you need

EOF
$ bundle
$ rails g ember:bootstrap -g --javascript-engine coffee

Step 5: Ember OAth

url: https://github.com/amkirwan/ember-oauth2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment