Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/omniauth/strategies/openid_connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class OpenIDConnect
userinfo_endpoint: "/userinfo",
jwks_uri: '/jwk'
}
option :client_name, "a web application via omniauth-openid-connect" # in case of dynamic registration
option :issuer
option :discovery, false
option :client_signing_alg
Expand Down Expand Up @@ -74,7 +75,18 @@ class OpenIDConnect
end

def client
@client ||= ::OpenIDConnect::Client.new(client_options)
@client ||= \
if client_options.identifier.nil?
registrar.register!.tap do |client|
%i(authorization_endpoint token_endpoint userinfo_endpoint).each do |key|
client.send :"#{key}=", client_options[key]
end
client_options.identifier = client.identifier
client_options.secret = client.secret
end
else
::OpenIDConnect::Client.new(client_options)
end
end

def config
Expand Down Expand Up @@ -138,6 +150,13 @@ def public_key

private

def registrar
::OpenIDConnect::Client::Registrar.new(config.registration_endpoint).tap do |registrar|
registrar.redirect_uris = *client_options.redirect_uri
registrar.client_name = options.client_name
end
end

def issuer
resource = "#{client_options.scheme}://#{client_options.host}" + ((client_options.port) ? ":#{client_options.port.to_s}" : '')
::OpenIDConnect::Discovery::Provider.discover!(resource).issuer
Expand Down