From 4fd651e25c19cf1dc4e2bd53f7f41cdf0a5fcf27 Mon Sep 17 00:00:00 2001 From: Katie Weber <38359249+web-kat@users.noreply.github.com> Date: Thu, 1 Dec 2022 11:39:48 -0500 Subject: [PATCH] [SHD-160] Add tempo id provider (#6) Add tempo id provider --- lib/omniauth/nitro_id.rb | 1 + lib/omniauth/strategies/tempo_id.rb | 18 ++++++++ spec/omniauth/strategies/tempo_id_spec.rb | 55 +++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 lib/omniauth/strategies/tempo_id.rb create mode 100644 spec/omniauth/strategies/tempo_id_spec.rb diff --git a/lib/omniauth/nitro_id.rb b/lib/omniauth/nitro_id.rb index ecb98f8..9fab6a2 100644 --- a/lib/omniauth/nitro_id.rb +++ b/lib/omniauth/nitro_id.rb @@ -2,3 +2,4 @@ require "omniauth/nitro_id/version" require "omniauth/strategies/nitro_id" +require "omniauth/strategies/tempo_id" diff --git a/lib/omniauth/strategies/tempo_id.rb b/lib/omniauth/strategies/tempo_id.rb new file mode 100644 index 0000000..85a5d93 --- /dev/null +++ b/lib/omniauth/strategies/tempo_id.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require "omniauth_openid_connect" + +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 + option :discovery, true + option :issuer, DEFAULT_ISSUER + option :client_options, host: DEFAULT_HOST + end + end +end diff --git a/spec/omniauth/strategies/tempo_id_spec.rb b/spec/omniauth/strategies/tempo_id_spec.rb new file mode 100644 index 0000000..8c4de09 --- /dev/null +++ b/spec/omniauth/strategies/tempo_id_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe OmniAuth::Strategies::TempoId do + let(:access_token) { instance_double("AccessToken", :options => {}, :[] => "user") } + let(:custom_client) do + OmniAuth::Strategies::TempoId.new(:test_app, + issuer: "https://example-host.com/", + discovery: false, + client_options: { + host: "example-host.com", + }) + end + + subject do + OmniAuth::Strategies::TempoId.new({}) + end + + before(:each) do + allow(subject).to receive(:access_token).and_return(access_token) + end + + context "options" do + it "should have correct name" do + expect(subject.options.name).to eq "tempo_id" + end + + it "should have correct host" do + expect(subject.options.client_options.host).to eq "id.streamfinancial.io" + end + + it "should have correct issuer" do + expect(subject.options.issuer).to eq "https://id.streamfinancial.io/" + end + + it "should have the correct discovery setting" do + expect(subject.options.discovery).to eq true + end + + describe "should be overrideable" do + it "for host" do + expect(custom_client.options.client_options.host).to eq "example-host.com" + end + + it "for issuer" do + expect(custom_client.options.issuer).to eq "https://example-host.com/" + end + + it "for discovery" do + expect(custom_client.options.discovery).to eq false + end + end + end +end