From 2506b6a1f0d31ed7011ccccf1650021a07b9c180 Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Thu, 30 Jul 2026 19:46:38 +0200 Subject: [PATCH] Add method to return optional and required attributes --- lib/code0/identities/identity_provider.rb | 4 ++++ lib/code0/identities/provider/base_oauth.rb | 4 ++++ lib/code0/identities/provider/discord.rb | 7 +++++++ lib/code0/identities/provider/github.rb | 7 +++++++ lib/code0/identities/provider/gitlab.rb | 7 +++++++ lib/code0/identities/provider/google.rb | 7 +++++++ lib/code0/identities/provider/microsoft.rb | 7 +++++++ lib/code0/identities/provider/oidc.rb | 7 +++++++ lib/code0/identities/provider/saml.rb | 7 +++++++ sig/code0/identities/identity_provider.rbs | 2 ++ sig/code0/identities/provider/base_oauth.rbs | 2 ++ sig/code0/identities/provider/saml.rbs | 2 ++ 12 files changed, 63 insertions(+) diff --git a/lib/code0/identities/identity_provider.rb b/lib/code0/identities/identity_provider.rb index 3712e14..e55e4c3 100644 --- a/lib/code0/identities/identity_provider.rb +++ b/lib/code0/identities/identity_provider.rb @@ -26,6 +26,10 @@ def load_identity(provider_id, params) provider.load_identity(params) end + + def [](provider_id) + providers[provider_id] + end end end end diff --git a/lib/code0/identities/provider/base_oauth.rb b/lib/code0/identities/provider/base_oauth.rb index 012b254..d4a3824 100644 --- a/lib/code0/identities/provider/base_oauth.rb +++ b/lib/code0/identities/provider/base_oauth.rb @@ -10,6 +10,10 @@ def initialize(config_loader) @config_loader = config_loader end + def config_attributes + raise NotImplementedError + end + def authorization_url raise NotImplementedError end diff --git a/lib/code0/identities/provider/discord.rb b/lib/code0/identities/provider/discord.rb index d78a8af..8f602c7 100644 --- a/lib/code0/identities/provider/discord.rb +++ b/lib/code0/identities/provider/discord.rb @@ -4,6 +4,13 @@ module Code0 module Identities module Provider class Discord < BaseOauth + def config_attributes + { + required: %i[client_id client_secret redirect_uri], + optional: %i[provider_name] + } + end + def token_url "https://discord.com/api/oauth2/token" end diff --git a/lib/code0/identities/provider/github.rb b/lib/code0/identities/provider/github.rb index 6609336..9768ee1 100644 --- a/lib/code0/identities/provider/github.rb +++ b/lib/code0/identities/provider/github.rb @@ -4,6 +4,13 @@ module Code0 module Identities module Provider class Github < BaseOauth + def config_attributes + { + required: %i[client_id client_secret redirect_uri], + optional: %i[provider_name] + } + end + def token_url "https://github.com/login/oauth/access_token" end diff --git a/lib/code0/identities/provider/gitlab.rb b/lib/code0/identities/provider/gitlab.rb index 9b606d7..aae6100 100644 --- a/lib/code0/identities/provider/gitlab.rb +++ b/lib/code0/identities/provider/gitlab.rb @@ -4,6 +4,13 @@ module Code0 module Identities module Provider class Gitlab < BaseOauth + def config_attributes + { + required: %i[base_url client_id client_secret redirect_uri], + optional: %i[provider_name] + } + end + def base_url config[:base_url] end diff --git a/lib/code0/identities/provider/google.rb b/lib/code0/identities/provider/google.rb index bb839d0..c9ad658 100644 --- a/lib/code0/identities/provider/google.rb +++ b/lib/code0/identities/provider/google.rb @@ -4,6 +4,13 @@ module Code0 module Identities module Provider class Google < BaseOauth + def config_attributes + { + required: %i[client_id client_secret redirect_uri], + optional: %i[provider_name] + } + end + def base_url "https://accounts.google.com" end diff --git a/lib/code0/identities/provider/microsoft.rb b/lib/code0/identities/provider/microsoft.rb index ca2cf30..a84ba3a 100644 --- a/lib/code0/identities/provider/microsoft.rb +++ b/lib/code0/identities/provider/microsoft.rb @@ -4,6 +4,13 @@ module Code0 module Identities module Provider class Microsoft < BaseOauth + def config_attributes + { + required: %i[client_id client_secret redirect_uri], + optional: %i[provider_name] + } + end + def base_url "https://graph.microsoft.com/" end diff --git a/lib/code0/identities/provider/oidc.rb b/lib/code0/identities/provider/oidc.rb index d078bde..e4f2892 100644 --- a/lib/code0/identities/provider/oidc.rb +++ b/lib/code0/identities/provider/oidc.rb @@ -4,6 +4,13 @@ module Code0 module Identities module Provider class Oidc < BaseOauth + def config_attributes + { + required: %i[client_id client_secret redirect_uri token_url user_details_url authorization_url], + optional: %i[provider_name] + } + end + def token_url config[:token_url] end diff --git a/lib/code0/identities/provider/saml.rb b/lib/code0/identities/provider/saml.rb index 1902e3b..dbd46be 100644 --- a/lib/code0/identities/provider/saml.rb +++ b/lib/code0/identities/provider/saml.rb @@ -10,6 +10,13 @@ def initialize(config_loader) @config_loader = config_loader end + def config_attributes + { + required: %i[], + optional: %i[provider_name metadata_url settings response_settings attribute_statements] + } + end + def authorization_url request = OneLogin::RubySaml::Authrequest.new request.create(create_settings) diff --git a/sig/code0/identities/identity_provider.rbs b/sig/code0/identities/identity_provider.rbs index 6339dcb..12b4b77 100644 --- a/sig/code0/identities/identity_provider.rbs +++ b/sig/code0/identities/identity_provider.rbs @@ -7,6 +7,8 @@ module Code0 def initialize: () -> void + def []: (Symbol) -> Provider::BaseOauth + def add_provider: (provider_type: Symbol, config: Proc | Hash[Symbol, any]) -> void def add_named_provider: (provider_id: Symbol, provider_type: Symbol, config: Proc | Hash[Symbol, any]) -> void diff --git a/sig/code0/identities/provider/base_oauth.rbs b/sig/code0/identities/provider/base_oauth.rbs index 1a27976..b2b9d45 100644 --- a/sig/code0/identities/provider/base_oauth.rbs +++ b/sig/code0/identities/provider/base_oauth.rbs @@ -8,6 +8,8 @@ module Code0 def authorization_url: () -> String + def config_attributes: -> { optional: Array[Symbol], required: Array[Symbol] } + def token_url: () -> String def user_details_url: () -> String diff --git a/sig/code0/identities/provider/saml.rbs b/sig/code0/identities/provider/saml.rbs index 7862e13..fef3755 100644 --- a/sig/code0/identities/provider/saml.rbs +++ b/sig/code0/identities/provider/saml.rbs @@ -4,6 +4,8 @@ module Code0 class Saml def authorization_url: () -> String + def config_attributes: -> { optional: Array[Symbol], required: Array[Symbol] } + def load_identity: (Hash[Symbol, any]) -> Identity end end