Skip to content

Commit

Permalink
wire in Rails engine and Userinfo controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Dengler committed Jun 11, 2014
1 parent 7dfc9bb commit ade260e
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ENV['rails'] ||= ENV['orm'] == "mongoid4" ? '4.0.2' : '3.2.13'

source 'https://rubygems.org'

# Define Rails version
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Doorkeeper::OpenIdConnect
# Doorkeeper::OpenidConnect

TODO: Write a gem description

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Doorkeeper
module OpenidConnect
class UserinfoController < ::Doorkeeper::ApplicationController
def show
render text: 'hello world'
end
end
end
end
13 changes: 6 additions & 7 deletions doorkeeper-openid_connect.gemspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
$:.push File.expand_path("../lib", __FILE__)
require 'doorkeeper/openid_connect/version'

Gem::Specification.new do |spec|
spec.name = "doorkeeper-openid_connect"
spec.version = Doorkeeper::OpenIdConnect::VERSION
spec.authors = ["Sam Dengler"]
spec.version = Doorkeeper::OpenidConnect::VERSION
spec.authors = ["sdengler"]
spec.email = ["sam.dengler@playonsports.com"]
spec.summary = "OpenID Connect Extension to Doorkeeper"
spec.description = "OpenID Connect Extension to Doorkeeper"
spec.homepage = "https://github.com/doorkeeper-gem/doorkeeper/doorkeeper-openid_connect"
spec.license = "MIT"
spec.summary = %q{OpenID Connect extension to Doorkeeper.}
spec.description = %q{OpenID Connect extension to Doorkeeper.}
spec.license = %q{MIT}

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
Expand Down
13 changes: 8 additions & 5 deletions lib/doorkeeper/openid_connect.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require "doorkeeper/openid_connect/version"
require 'doorkeeper/openid_connect/version'
require 'doorkeeper/openid_connect/engine'

module Doorkeeper
module OpenIdConnect
require 'doorkeeper/openid_connect/rails/routes'

#module Doorkeeper
#module OpenidConnect
# Your code goes here...
end
end
#end
#end
10 changes: 10 additions & 0 deletions lib/doorkeeper/openid_connect/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Doorkeeper
module OpenidConnect
class Engine < ::Rails::Engine
puts '************ Doorkeeper::OpenidConnect::Engine'
initializer 'doorkeeper.openid_connect.routes' do
Doorkeeper::OpenidConnect::Rails::Routes.install!
end
end
end
end
50 changes: 50 additions & 0 deletions lib/doorkeeper/openid_connect/rails/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'doorkeeper/openid_connect/rails/routes/mapping'
require 'doorkeeper/openid_connect/rails/routes/mapper'

module Doorkeeper
module OpenidConnect
module Rails
class Routes
module Helper
def use_doorkeeper_openid_connect(options = {}, &block)
Doorkeeper::OpenidConnect::Rails::Routes.new(self, &block).generate_routes!(options)
end
end

def self.install!
ActionDispatch::Routing::Mapper.send :include, Doorkeeper::OpenidConnect::Rails::Routes::Helper
end

attr_accessor :routes

def initialize(routes, &block)
@routes, @block = routes, block
end

def generate_routes!(options)
@mapping = Mapper.new.map(&@block)
routes.scope options[:scope] || 'oauth', as: 'oauth' do
map_route(:userinfo, :userinfo_routes)
end
end

private

def map_route(name, method)
unless @mapping.skipped?(name)
send method, @mapping[name]
end
end

def userinfo_routes(mapping)
routes.resource(
:userinfo,
path: 'userinfo',
only: [:show], as: mapping[:as],
controller: mapping[:controllers]
)
end
end
end
end
end
30 changes: 30 additions & 0 deletions lib/doorkeeper/openid_connect/rails/routes/mapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Doorkeeper
module OpenidConnect
module Rails
class Routes
class Mapper
def initialize(mapping = Mapping.new)
@mapping = mapping
end

def map(&block)
self.instance_eval(&block) if block
@mapping
end

def controllers(controller_names = {})
@mapping.controllers.merge!(controller_names)
end

def skip_controllers(*controller_names)
@mapping.skips = controller_names
end

def as(alias_names = {})
@mapping.as.merge!(alias_names)
end
end
end
end
end
end
34 changes: 34 additions & 0 deletions lib/doorkeeper/openid_connect/rails/routes/mapping.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Doorkeeper
module OpenidConnect
module Rails
class Routes
class Mapping
attr_accessor :controllers, :as, :skips

def initialize
@controllers = {
userinfo: 'doorkeeper/openid_connect/userinfo'
}

@as = {
userinfo: :userinfo
}

@skips = []
end

def [](routes)
{
controllers: @controllers[routes],
as: @as[routes]
}
end

def skipped?(controller)
@skips.include?(controller)
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/doorkeeper/openid_connect/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Doorkeeper
module OpenIdConnect
module OpenidConnect
VERSION = "0.0.1"
end
end

0 comments on commit ade260e

Please sign in to comment.