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.
Instance Method Summary collapse
- #as_log ⇒ Object
-
#initialize(name:, id:, secret: nil, secret_hash: nil, redirect_uris:, preferred_key_group: nil) ⇒ 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) ⇒ ClientRegistration
Returns a new instance of ClientRegistration.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/himari/client_registration.rb', line 5 def initialize(name:, id:, secret: nil, secret_hash: nil, redirect_uris:, preferred_key_group: nil) @name = name @id = id @secret = secret @secret_hash = secret_hash @redirect_uris = redirect_uris @preferred_key_group = preferred_key_group 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.
17 18 19 |
# File 'lib/himari/client_registration.rb', line 17 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/himari/client_registration.rb', line 17 def name @name end |
#preferred_key_group ⇒ Object (readonly)
Returns the value of attribute preferred_key_group.
17 18 19 |
# File 'lib/himari/client_registration.rb', line 17 def preferred_key_group @preferred_key_group end |
#redirect_uris ⇒ Object (readonly)
Returns the value of attribute redirect_uris.
17 18 19 |
# File 'lib/himari/client_registration.rb', line 17 def redirect_uris @redirect_uris end |
Instance Method Details
#as_log ⇒ Object
32 33 34 |
# File 'lib/himari/client_registration.rb', line 32 def as_log {name: name, id: id} end |
#match_hint?(id: nil) ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/himari/client_registration.rb', line 36 def match_hint?(id: nil) result = true result &&= if id id == self.id else true end result end |
#match_secret?(given_secret) ⇒ Boolean
23 24 25 26 27 28 29 30 |
# File 'lib/himari/client_registration.rb', line 23 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
19 20 21 |
# File 'lib/himari/client_registration.rb', line 19 def secret_hash @secret_hash ||= Digest::SHA384.hexdigest(secret) end |