Class: Himari::ClientRegistration
- Inherits:
-
Object
- Object
- Himari::ClientRegistration
- Defined in:
- lib/himari/client_registration.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#preferred_key_group ⇒ Object
readonly
Returns the value of attribute preferred_key_group.
-
#redirect_uris ⇒ Object
readonly
Returns the value of attribute redirect_uris.
-
#require_pkce ⇒ Object
readonly
Returns the value of attribute require_pkce.
Instance Method Summary collapse
- #as_log ⇒ Object
-
#initialize(name:, id:, secret: nil, secret_hash: nil, redirect_uris:, preferred_key_group: nil, require_pkce: false) ⇒ ClientRegistration
constructor
A new instance of ClientRegistration.
- #match_hint?(id: nil) ⇒ Boolean
- #match_secret?(given_secret) ⇒ Boolean
- #secret_hash ⇒ Object
Constructor Details
#initialize(name:, id:, secret: nil, secret_hash: nil, redirect_uris:, preferred_key_group: nil, require_pkce: false) ⇒ ClientRegistration
Returns a new instance of ClientRegistration.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/himari/client_registration.rb', line 5 def initialize(name:, id:, secret: nil, secret_hash: nil, redirect_uris:, preferred_key_group: nil, require_pkce: false) @name = name @id = id @secret = secret @secret_hash = secret_hash @redirect_uris = redirect_uris @preferred_key_group = preferred_key_group @require_pkce = require_pkce raise ArgumentError, "name starts with '_' is reserved" if @name&.start_with?('_') raise ArgumentError, "either secret or secret_hash must be present" if !@secret && !@secret_hash end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
18 19 20 |
# File 'lib/himari/client_registration.rb', line 18 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/himari/client_registration.rb', line 18 def name @name end |
#preferred_key_group ⇒ Object (readonly)
Returns the value of attribute preferred_key_group.
18 19 20 |
# File 'lib/himari/client_registration.rb', line 18 def preferred_key_group @preferred_key_group end |
#redirect_uris ⇒ Object (readonly)
Returns the value of attribute redirect_uris.
18 19 20 |
# File 'lib/himari/client_registration.rb', line 18 def redirect_uris @redirect_uris end |
#require_pkce ⇒ Object (readonly)
Returns the value of attribute require_pkce.
18 19 20 |
# File 'lib/himari/client_registration.rb', line 18 def require_pkce @require_pkce end |
Instance Method Details
#as_log ⇒ Object
33 34 35 |
# File 'lib/himari/client_registration.rb', line 33 def as_log {name: name, id: id} end |
#match_hint?(id: nil) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/himari/client_registration.rb', line 37 def match_hint?(id: nil) result = true result &&= if id id == self.id else true end result end |
#match_secret?(given_secret) ⇒ Boolean
24 25 26 27 28 29 30 31 |
# File 'lib/himari/client_registration.rb', line 24 def match_secret?(given_secret) if @secret Rack::Utils.secure_compare(@secret, given_secret) else dgst = [secret_hash].pack('H*') Rack::Utils.secure_compare(dgst, Digest::SHA384.digest(given_secret)) end end |
#secret_hash ⇒ Object
20 21 22 |
# File 'lib/himari/client_registration.rb', line 20 def secret_hash @secret_hash ||= Digest::SHA384.hexdigest(secret) end |