-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wire in Rails engine and Userinfo controller
- Loading branch information
Sam Dengler
committed
Jun 11, 2014
1 parent
7dfc9bb
commit ade260e
Showing
10 changed files
with
151 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Doorkeeper::OpenIdConnect | ||
# Doorkeeper::OpenidConnect | ||
|
||
TODO: Write a gem description | ||
|
||
|
9 changes: 9 additions & 0 deletions
9
app/controllers/doorkeeper/openid_connect/userinfo_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |