From 81744dc5e21efa26252e31a724dbf69ed9c5616a Mon Sep 17 00:00:00 2001 From: Dario Date: Sat, 23 Nov 2024 01:11:00 +0100 Subject: [PATCH 1/2] make provider namespace configurable --- lib/code0/identities/provider/base_oauth.rb | 7 +++++-- lib/code0/identities/provider/discord.rb | 2 +- lib/code0/identities/provider/github.rb | 2 +- lib/code0/identities/provider/gitlab.rb | 2 +- lib/code0/identities/provider/google.rb | 2 +- lib/code0/identities/provider/microsoft.rb | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/code0/identities/provider/base_oauth.rb b/lib/code0/identities/provider/base_oauth.rb index 995e132..012b254 100644 --- a/lib/code0/identities/provider/base_oauth.rb +++ b/lib/code0/identities/provider/base_oauth.rb @@ -68,9 +68,12 @@ def create_identity(response, token, token_type) end def config - return config_loader.call if config_loader.is_a?(Proc) + config = config_loader + config = config_loader.call if config_loader.is_a?(Proc) - config_loader + config[:provider_name] ||= self.class.name.downcase.split("::").last + + config end end end diff --git a/lib/code0/identities/provider/discord.rb b/lib/code0/identities/provider/discord.rb index 371d039..d78a8af 100644 --- a/lib/code0/identities/provider/discord.rb +++ b/lib/code0/identities/provider/discord.rb @@ -31,7 +31,7 @@ def create_identity(response, *) username = body["username"] email = body["email"] - Identity.new(:discord, identifier, username, email, nil, nil) + Identity.new(config[:provider_name], identifier, username, email, nil, nil) end end end diff --git a/lib/code0/identities/provider/github.rb b/lib/code0/identities/provider/github.rb index efc97dc..6609336 100644 --- a/lib/code0/identities/provider/github.rb +++ b/lib/code0/identities/provider/github.rb @@ -43,7 +43,7 @@ def create_identity(response, access_token, token_type) email = private_email(access_token, token_type) if email.nil? - Identity.new(:github, identifier, username, email, nil, nil) + Identity.new(config[:provider_name], identifier, username, email, nil, nil) end end end diff --git a/lib/code0/identities/provider/gitlab.rb b/lib/code0/identities/provider/gitlab.rb index 12526e3..9b606d7 100644 --- a/lib/code0/identities/provider/gitlab.rb +++ b/lib/code0/identities/provider/gitlab.rb @@ -37,7 +37,7 @@ def create_identity(response, *) username = body["username"] email = body["email"] - Identity.new(config_loader.call[:provider_name], identifier, username, email, nil, nil) + Identity.new(config[:provider_name], identifier, username, email, nil, nil) end end end diff --git a/lib/code0/identities/provider/google.rb b/lib/code0/identities/provider/google.rb index 378ab4d..bb839d0 100644 --- a/lib/code0/identities/provider/google.rb +++ b/lib/code0/identities/provider/google.rb @@ -41,7 +41,7 @@ def create_identity(response, *) firstname = body["given_name"] lastname = body["family_name"] - Identity.new(:google, identifier, username, email, firstname, lastname) + Identity.new(config[:provider_name], identifier, username, email, firstname, lastname) end end end diff --git a/lib/code0/identities/provider/microsoft.rb b/lib/code0/identities/provider/microsoft.rb index fdf3466..ca2cf30 100644 --- a/lib/code0/identities/provider/microsoft.rb +++ b/lib/code0/identities/provider/microsoft.rb @@ -36,7 +36,7 @@ def create_identity(response, *) lastname = body["familyname"] email = body["email"] - Identity.new(:microsoft, identifier, nil, email, firstname, lastname) + Identity.new(config[:provider_name], identifier, nil, email, firstname, lastname) end end end From f44d2202d2f8d0183f4eefd6b9db220807afce4a Mon Sep 17 00:00:00 2001 From: Dario Date: Sat, 23 Nov 2024 01:16:00 +0100 Subject: [PATCH 2/2] adjust symbols to string --- spec/code0/identities/provider/discord_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/code0/identities/provider/discord_spec.rb b/spec/code0/identities/provider/discord_spec.rb index 604c890..31c25d5 100644 --- a/spec/code0/identities/provider/discord_spec.rb +++ b/spec/code0/identities/provider/discord_spec.rb @@ -58,7 +58,7 @@ .to_return(body: response_body, headers: { "Content-Type": "application/json" }) expect(service_response.identifier).to eq(1) - expect(service_response.provider).to eq(:discord) + expect(service_response.provider).to eq("discord") expect(service_response.username).to eq("name") expect(service_response.email).to eq("example@code0.tech") end