Skip to content

Commit

Permalink
Allow id token hint param (#8)
Browse files Browse the repository at this point in the history
* Add id_token_hint param to end_session_endpoint

* Don't use discovery when set to false

* Correct variable update

* Linting
  • Loading branch information
stephenagreer authored Dec 14, 2022
1 parent 0b85867 commit 0870e66
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 18 deletions.
24 changes: 24 additions & 0 deletions lib/extensions/discovery.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Extensions
module Discovery
Module.new do
# Monkey patch allow HTTP instead of forcing HTTPS for discovery.

attr_reader :scheme

def initialize(uri)
@scheme = uri.scheme
super
end

def endpoint
URI::Generic.build(scheme: scheme, host: host, port: port, path: path)
rescue URI::Error => e
raise SWD::Exception, e.message
end

prepend_features(::OpenIDConnect::Discovery::Provider::Config::Resource)
end
end
end
55 changes: 55 additions & 0 deletions lib/omniauth/strategies/base_strategy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require "omniauth_openid_connect"
require_relative "../../extensions/discovery"

module OmniAuth
module Strategies
class BaseStrategy < OmniAuth::Strategies::OpenIDConnect
def public_key
@public_key ||= if options.discovery
config.jwks
elsif key_or_secret
key_or_secret
elsif client_options.jwks_uri
fetch_key
end
end

private

def fetch_key
@fetch_key ||= parse_jwk_key(::OpenIDConnect.http_client.get_content(client_options.jwks_uri))
end

def key_or_secret
@key_or_secret ||=
case options.client_signing_alg&.to_sym
when :HS256, :HS384, :HS512
client_options.secret
when :RS256, :RS384, :RS512
parse_key
end
end

def encoded_post_logout_redirect_uri
return unless options.post_logout_redirect_uri

query = {
post_logout_redirect_uri: options.post_logout_redirect_uri,
}
query = query.merge({ id_token_hint: params["id_token_hint"] }) if params["id_token_hint"]

URI.encode_www_form(query)
end

def parse_key
if options.client_jwk_signing_key
parse_jwk_key(options.client_jwk_signing_key)
elsif options.client_x509_signing_key
parse_x509_key(options.client_x509_signing_key)
end
end
end
end
end
14 changes: 5 additions & 9 deletions lib/omniauth/strategies/nitro_id.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# frozen_string_literal: true

require "omniauth_openid_connect"
require_relative "base_strategy"

module OmniAuth
module Strategies
class NitroId < OmniAuth::Strategies::OpenIDConnect
DEFAULT_STRATEGY_NAME = "nitro_id"
DEFAULT_ISSUER = "https://id.powerhrg.com/"
DEFAULT_HOST = "id.powerhrg.com"

option :name, DEFAULT_STRATEGY_NAME
class NitroId < BaseStrategy
option :name, "nitro_id"
option :discovery, true
option :issuer, DEFAULT_ISSUER
option :client_options, host: DEFAULT_HOST
option :issuer, "https://id.powerhrg.com/"
option :client_options, host: "id.powerhrg.com"
end
end
end
14 changes: 5 additions & 9 deletions lib/omniauth/strategies/tempo_id.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# frozen_string_literal: true

require "omniauth_openid_connect"
require_relative "base_strategy"

module OmniAuth
module Strategies
class TempoId < OmniAuth::Strategies::OpenIDConnect
DEFAULT_STRATEGY_NAME = "tempo_id"
DEFAULT_ISSUER = "https://id.streamfinancial.io/"
DEFAULT_HOST = "id.streamfinancial.io"

option :name, DEFAULT_STRATEGY_NAME
class TempoId < BaseStrategy
option :name, "tempo_id"
option :discovery, true
option :issuer, DEFAULT_ISSUER
option :client_options, host: DEFAULT_HOST
option :issuer, "https://id.streamfinancial.io/"
option :client_options, host: "id.streamfinancial.io"
end
end
end

0 comments on commit 0870e66

Please sign in to comment.