Skip to content

Commit

Permalink
feature: Add discovery endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
toupeira committed Oct 5, 2016
1 parent fcd5f62 commit a16caa8
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 2 deletions.
53 changes: 53 additions & 0 deletions app/controllers/doorkeeper/openid_connect/discovery_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Doorkeeper
module OpenidConnect
class DiscoveryController < ::Doorkeeper::ApplicationController
include Doorkeeper::Helpers::Controller

def show
render json: provider_configuration
end

private

def provider_configuration
doorkeeper = ::Doorkeeper.configuration
openid_connect = ::Doorkeeper::OpenidConnect.configuration

{
issuer: openid_connect.issuer,
authorization_endpoint: oauth_authorization_url(protocol: :https),
token_endpoint: oauth_token_url(protocol: :https),
userinfo_endpoint: oauth_userinfo_url(protocol: :https),

# TODO: implement controller
#jwks_uri: oauth_keys_url(protocol: :https),

scopes_supported: doorkeeper.scopes,

# TODO: support id_token response type
response_types_supported: doorkeeper.authorization_response_types,
response_modes_supported: [ 'query', 'fragment' ],

token_endpoint_auth_methods_supported: [
'client_secret_basic',
'client_secret_post',

# TODO: look into doorkeeper-jwt_assertion for these
#'client_secret_jwt',
#'private_key_jwt'
],

# TODO: make this configurable
subject_types_supported: [
'public',
],

# TODO: make this configurable
id_token_signing_alg_values_supported: [
'RS256',
],
}
end
end
end
end
13 changes: 13 additions & 0 deletions lib/doorkeeper/openid_connect/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def generate_routes!(options)
routes.scope options[:scope] || 'oauth', as: 'oauth' do
map_route(:userinfo, :userinfo_routes)
end

routes.scope as: 'oauth' do
map_route(:discovery, :discovery_routes)
end
end

private
Expand All @@ -44,6 +48,15 @@ def userinfo_routes(mapping)
controller: mapping[:controllers]
)
end

def discovery_routes(mapping)
routes.resource(
:discovery,
path: '.well-known/openid-configuration',
only: [:show], as: mapping[:as],
controller: mapping[:controllers]
)
end
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/doorkeeper/openid_connect/rails/routes/mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class Mapping

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

@as = {
userinfo: :userinfo
userinfo: :userinfo,
discovery: :discovery
}

@skips = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'rails_helper'

describe Doorkeeper::OpenidConnect::DiscoveryController, type: :controller do
describe '#show' do
it 'returns the provider configuration' do
get :show
configuration = JSON.parse(response.body)

expect(configuration.sort).to eq({
'issuer' => 'dummy',
'authorization_endpoint' => 'https://test.host/oauth/authorize',
'token_endpoint' => 'https://test.host/oauth/token',
'userinfo_endpoint' => 'https://test.host/oauth/userinfo',

'scopes_supported' => ['openid'],

'response_types_supported' => ['code'],
'response_modes_supported' => ['query', 'fragment'],

'token_endpoint_auth_methods_supported' => [
'client_secret_basic',
'client_secret_post',
],

'subject_types_supported' => [
'public',
],

'id_token_signing_alg_values_supported' => [
'RS256',
],
}.sort)
end
end
end
2 changes: 2 additions & 0 deletions spec/dummy/config/initializers/doorkeeper_openid_connect.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Doorkeeper::OpenidConnect.configure do
issuer 'dummy'

resource_owner_from_access_token do |access_token|
User.find_by(id: access_token.resource_owner_id)
end
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/doorkeeper/openid_connect/routes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

describe Doorkeeper::OpenidConnect::Rails::Routes, type: :routing do
it 'maps userinfo#show' do
expect(get: 'oauth/userinfo').to route_to(
controller: 'doorkeeper/openid_connect/userinfo',
action: 'show'
)
end

it 'maps discovery#show' do
expect(get: '.well-known/openid-configuration').to route_to(
controller: 'doorkeeper/openid_connect/discovery',
action: 'show'
)
end
end

0 comments on commit a16caa8

Please sign in to comment.