main
1# frozen_string_literal: true
2
3module Scim
4 module Kit
5 module V2
6 # Represents the available Authentication Schemes.
7 class AuthenticationScheme
8 DEFAULTS = {
9 httpbasic: {
10 description: 'Authentication scheme using the HTTP Basic Standard',
11 documentation_uri: 'http://example.com/help/httpBasic.html',
12 name: 'HTTP Basic',
13 spec_uri: 'http://www.rfc-editor.org/info/rfc2617'
14 },
15 oauthbearertoken: {
16 description:
17 'Authentication scheme using the OAuth Bearer Token Standard',
18 documentation_uri: 'http://example.com/help/oauth.html',
19 name: 'OAuth Bearer Token',
20 spec_uri: 'http://www.rfc-editor.org/info/rfc6750'
21 }
22 }.freeze
23 include Templatable
24 attr_accessor :name
25 attr_accessor :description
26 attr_accessor :documentation_uri
27 attr_accessor :spec_uri
28 attr_accessor :type
29 attr_accessor :primary
30
31 def initialize
32 yield self if block_given?
33 end
34
35 class << self
36 def build_for(type, primary: nil)
37 defaults = DEFAULTS[type.to_sym] || {}
38 new do |x|
39 x.type = type
40 x.primary = primary
41 x.description = defaults[:description]
42 x.documentation_uri = defaults[:documentation_uri]
43 x.name = defaults[:name]
44 x.spec_uri = defaults[:spec_uri]
45 end
46 end
47
48 def from(hash)
49 x = build_for(hash[:type], primary: hash[:primary])
50 x.description = hash[:description]
51 x.documentation_uri = hash[:documentationUri]
52 x.name = hash[:name]
53 x.spec_uri = hash[:specUri]
54 x
55 end
56 end
57 end
58 end
59 end
60end