Skip to content

Commit 2506b6a

Browse files
committed
Add method to return optional and required attributes
1 parent 7006a9d commit 2506b6a

12 files changed

Lines changed: 63 additions & 0 deletions

File tree

lib/code0/identities/identity_provider.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def load_identity(provider_id, params)
2626

2727
provider.load_identity(params)
2828
end
29+
30+
def [](provider_id)
31+
providers[provider_id]
32+
end
2933
end
3034
end
3135
end

lib/code0/identities/provider/base_oauth.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def initialize(config_loader)
1010
@config_loader = config_loader
1111
end
1212

13+
def config_attributes
14+
raise NotImplementedError
15+
end
16+
1317
def authorization_url
1418
raise NotImplementedError
1519
end

lib/code0/identities/provider/discord.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ module Code0
44
module Identities
55
module Provider
66
class Discord < BaseOauth
7+
def config_attributes
8+
{
9+
required: %i[client_id client_secret redirect_uri],
10+
optional: %i[provider_name]
11+
}
12+
end
13+
714
def token_url
815
"https://discord.com/api/oauth2/token"
916
end

lib/code0/identities/provider/github.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ module Code0
44
module Identities
55
module Provider
66
class Github < BaseOauth
7+
def config_attributes
8+
{
9+
required: %i[client_id client_secret redirect_uri],
10+
optional: %i[provider_name]
11+
}
12+
end
13+
714
def token_url
815
"https://github.com/login/oauth/access_token"
916
end

lib/code0/identities/provider/gitlab.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ module Code0
44
module Identities
55
module Provider
66
class Gitlab < BaseOauth
7+
def config_attributes
8+
{
9+
required: %i[base_url client_id client_secret redirect_uri],
10+
optional: %i[provider_name]
11+
}
12+
end
13+
714
def base_url
815
config[:base_url]
916
end

lib/code0/identities/provider/google.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ module Code0
44
module Identities
55
module Provider
66
class Google < BaseOauth
7+
def config_attributes
8+
{
9+
required: %i[client_id client_secret redirect_uri],
10+
optional: %i[provider_name]
11+
}
12+
end
13+
714
def base_url
815
"https://accounts.google.com"
916
end

lib/code0/identities/provider/microsoft.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ module Code0
44
module Identities
55
module Provider
66
class Microsoft < BaseOauth
7+
def config_attributes
8+
{
9+
required: %i[client_id client_secret redirect_uri],
10+
optional: %i[provider_name]
11+
}
12+
end
13+
714
def base_url
815
"https://graph.microsoft.com/"
916
end

lib/code0/identities/provider/oidc.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ module Code0
44
module Identities
55
module Provider
66
class Oidc < BaseOauth
7+
def config_attributes
8+
{
9+
required: %i[client_id client_secret redirect_uri token_url user_details_url authorization_url],
10+
optional: %i[provider_name]
11+
}
12+
end
13+
714
def token_url
815
config[:token_url]
916
end

lib/code0/identities/provider/saml.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ def initialize(config_loader)
1010
@config_loader = config_loader
1111
end
1212

13+
def config_attributes
14+
{
15+
required: %i[],
16+
optional: %i[provider_name metadata_url settings response_settings attribute_statements]
17+
}
18+
end
19+
1320
def authorization_url
1421
request = OneLogin::RubySaml::Authrequest.new
1522
request.create(create_settings)

sig/code0/identities/identity_provider.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Code0
77

88
def initialize: () -> void
99

10+
def []: (Symbol) -> Provider::BaseOauth
11+
1012
def add_provider: (provider_type: Symbol, config: Proc | Hash[Symbol, any]) -> void
1113

1214
def add_named_provider: (provider_id: Symbol, provider_type: Symbol, config: Proc | Hash[Symbol, any]) -> void

0 commit comments

Comments
 (0)