-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement identity provider to allow loading of identities and fix so…
…me issues
- Loading branch information
Showing
10 changed files
with
81 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Code0 | ||
module Identities | ||
class IdentityProvider | ||
attr_reader :providers | ||
|
||
def initialize | ||
@providers = {} | ||
end | ||
|
||
def add_provider(provider_type, config_loader) | ||
add_named_provider provider_type, provider_type, config_loader | ||
end | ||
|
||
def add_named_provider(provider_id, provider_type, config_loader) | ||
provider = Identities::Provider.const_get(provider_type.capitalize).new(config_loader) | ||
providers[provider_id] = provider | ||
end | ||
|
||
def load_identity(provider_id, params) | ||
provider = providers[provider_id] | ||
if provider.nil? | ||
raise Error, "Provider with id '#{provider_id}' is not configured, did you forget to use add_provider" | ||
end | ||
|
||
provider.load_identity(params) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Code0::Identities::IdentityProvider do | ||
let(:instance) do | ||
described_class.new | ||
end | ||
|
||
describe "#add_provider" do | ||
it "adds the correct class" do | ||
instance.add_provider :google, -> {} | ||
expect(instance.providers).to match(google: an_instance_of(Code0::Identities::Provider::Google)) | ||
end | ||
end | ||
|
||
describe "#load_identity" do | ||
it "calls the right provider" do | ||
provider = Code0::Identities::Provider::Google.new(-> {}) | ||
allow(provider).to receive(:load_identity) | ||
instance.providers[:google] = provider | ||
instance.load_identity(:google, { test: 1 }) | ||
expect(provider).to have_received(:load_identity).with({ test: 1 }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters