Class: Himari::ClientRegistration

Inherits:
Object
  • Object
show all
Defined in:
lib/himari/client_registration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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

#idObject (readonly)

Returns the value of attribute id.



18
19
20
# File 'lib/himari/client_registration.rb', line 18

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/himari/client_registration.rb', line 18

def name
  @name
end

#preferred_key_groupObject (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_urisObject (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_pkceObject (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_logObject



33
34
35
# File 'lib/himari/client_registration.rb', line 33

def as_log
  {name: name, id: id}
end

#match_hint?(id: nil) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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_hashObject



20
21
22
# File 'lib/himari/client_registration.rb', line 20

def secret_hash
  @secret_hash ||= Digest::SHA384.hexdigest(secret)
end