Coder Social home page Coder Social logo

viamin / devise-doorkeeper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from betterup/devise-doorkeeper

0.0 2.0 0.0 46 KB

Integrate Doorkeeper OAuth2 tokens into Devise applications

License: MIT License

Ruby 89.67% JavaScript 1.00% CSS 1.14% HTML 8.18%

devise-doorkeeper's Introduction

Build Status

Devise::Doorkeeper

Integrates OAuth2 tokens from the Doorkeeper gem into Devise authentication strategies

Devise/Doorkeeper Integration

Devise and Doorkeeper are complimentary gems. Doorkeeper's job is to dispense OAuth2 tokens and Devise's job is to ensure your resources are protected from unauthenticated requests.

The devise-doorkeeper gem allows your existing Devise application to accept OAuth2 tokens created by the Doorkeeper authorization flow.

This means you do not need to update your controllers to use the doorkeeper_authorize! filter and can use the standard Devise authenticate_user! methods instead.

Installation

Add this line to your application's Gemfile:

gem 'devise-doorkeeper'

Configuration

Update doorkeeper config

Update your config/initializers/doorkeeper.rb to call Devise::Doorkeeper.configure_doorkeeper(self).

# config/initializers/doorkeeper.rb
Doorkeeper.configure do
  Devise::Doorkeeper.configure_doorkeeper(self)

  # extra configuration goes below
end

Update devise config

Update your config/initializers/devise.rb to call Devise::Doorkeeper.configure_devise.

# config/initializers/devise.rb
Devise.setup do |config|
  Devise::Doorkeeper.configure_devise(config)

  # extra configuration goes below
end

Add :doorkeeper to your list of devise modules

# example app/models/user.rb
class User
  devise :doorkeeper
end

Ensure controllers have authentication enabled

# example app/controllers/comments_controller.rb
class CommentsController < ApplicationController
  before_action :authenticate_user!

  def index
    # this action is protected
    # the devise-doorkeeper gem will permit access via valid OAuth2 tokens
  end
end

(optional) Disable session storage

Most API's should not create sessions for each API request. This can be configured via the Devise skip_session_storage setting.

# config/initializers/devise.rb
config.skip_session_storage = [:http_auth] # this is the default devise config
config.skip_session_storage << :doorkeeper # disable session storage for oauth requests
  1. Fork it ( https://github.com/betterup/devise-doorkeeper/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.