Commit 8e4cac8

mo <mo.khan@gmail.com>
2019-01-05 19:31:42
specify primary authentication scheme tag: v0.2.0
1 parent 95724d7
lib/scim/kit/v2/templates/authentication_scheme.json.jbuilder
@@ -6,3 +6,4 @@ json.description description
 json.spec_uri spec_uri
 json.documentation_uri documentation_uri
 json.type type
+json.primary primary if primary
lib/scim/kit/v2/authentication_scheme.rb
@@ -26,15 +26,17 @@ module Scim
         attr_accessor :documentation_uri
         attr_accessor :spec_uri
         attr_accessor :type
+        attr_accessor :primary
 
         def initialize
           yield self if block_given?
         end
 
-        def self.build_for(type)
+        def self.build_for(type, primary: nil)
           defaults = DEFAULTS[type.to_sym] || {}
           new do |x|
             x.type = type
+            x.primary = primary
             x.description = defaults[:description]
             x.documentation_uri = defaults[:documentation_uri]
             x.name = defaults[:name]
lib/scim/kit/v2/service_provider_configuration.rb
@@ -23,10 +23,10 @@ module Scim
           @filter = Supportable.new(:max_results)
         end
 
-        def add_authentication(type)
-          authentication_scheme = AuthenticationScheme.build_for(type)
-          yield authentication_scheme if block_given?
-          @authentication_schemes << authentication_scheme
+        def add_authentication(type, primary: nil)
+          scheme = AuthenticationScheme.build_for(type, primary: primary)
+          yield scheme if block_given?
+          @authentication_schemes << scheme
         end
       end
     end
spec/scim/kit/v2/service_provider_configuration_spec.rb
@@ -52,6 +52,26 @@ RSpec.describe Scim::Kit::V2::ServiceProviderConfiguration do
       specify { expect(result[:authenticationSchemes][0][:type]).to eql('httpbasic') }
     end
 
+    context 'with multiple schemes' do
+      before do
+        subject.add_authentication(:oauthbearertoken, primary: true)
+        subject.add_authentication(:httpbasic)
+      end
+
+      specify { expect(result[:authenticationSchemes][0][:name]).to eql('OAuth Bearer Token') }
+      specify { expect(result[:authenticationSchemes][0][:description]).to eql('Authentication scheme using the OAuth Bearer Token Standard') }
+      specify { expect(result[:authenticationSchemes][0][:specUri]).to eql('http://www.rfc-editor.org/info/rfc6750') }
+      specify { expect(result[:authenticationSchemes][0][:documentationUri]).to eql('http://example.com/help/oauth.html') }
+      specify { expect(result[:authenticationSchemes][0][:type]).to eql('oauthbearertoken') }
+      specify { expect(result[:authenticationSchemes][0][:primary]).to be(true) }
+
+      specify { expect(result[:authenticationSchemes][1][:name]).to eql('HTTP Basic') }
+      specify { expect(result[:authenticationSchemes][1][:description]).to eql('Authentication scheme using the HTTP Basic Standard') }
+      specify { expect(result[:authenticationSchemes][1][:specUri]).to eql('http://www.rfc-editor.org/info/rfc2617') }
+      specify { expect(result[:authenticationSchemes][1][:documentationUri]).to eql('http://example.com/help/httpBasic.html') }
+      specify { expect(result[:authenticationSchemes][1][:type]).to eql('httpbasic') }
+    end
+
     context 'with custom scheme' do
       before do
         subject.add_authentication(:custom) do |x|