OAuth2 with Doorkeeper

Make your application to be an OAuth2 provider
Icons/chart bar
Used 32 times
Created by
N Nikita Bulai

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/z5OsrK"
Template Source

Review the code before running this template on your machine.

def do_bundle
  # Custom bundle command ensures dependencies are correctly installed
  Bundler.with_unbundled_env { run "bundle install" }
end

def add_gem(gem_name)
  run "bundle add #{gem_name}"
  do_bundle
end

def set_orm(orm)
  gsub_file "config/initializers/doorkeeper.rb", /orm\s+:active_record/, "orm :#{orm}"
end

add_gem("doorkeeper")

rails_command "generate doorkeeper:install"

orm = ask("Which ORM do you use? (leave blank if you're using ActiveRecord):")
orm = orm.to_s.downcase.strip.gsub(/[^a-z]+/i, "")

# If not default ORM choosed
if !orm.empty? && orm != "activerecord"
  case orm
  when "mongoid"
    add_gem("doorkeeper-mongodb")
    set_orm("mongoid7")
  when "sequel"
    add_gem("doorkeeper-sequel")
    set_orm("sequel")
  when "couchbase"
    add_gem("doorkeeper-couchbase")
    set_orm("couchbase")
  else
    puts "#{orm} not supported, fallback to ActiveRecord!"
  end
end
    
rails_command "generate doorkeeper:migration"

if yes?("Do you want to run database migrations right now? [y/n]")
  rails_command "db:migrate"
end
Comments

Sign up or Login to leave a comment.