Class: Hitch::ClientAuthentication

Inherits:
Object
  • Object
show all
Defined in:
app/models/hitch/client_authentication.rb

Defined Under Namespace

Classes: Invalid, Resolution

Constant Summary collapse

MAX_AUTHORIZATION_BYTES =
4_096
MAX_SECRET_BYTES =
512
CONTROL_CHARACTERS =
/[\u0000-\u001F\u007F-\u009F]/

Class Method Summary collapse

Class Method Details

.resolve(request:, body_client_id:, body_secret_present:) ⇒ Object

Raises:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/hitch/client_authentication.rb', line 25

def self.resolve(request:, body_client_id:, body_secret_present:)
  authorization = request.headers["Authorization"].to_s
  return public_client_id(body_client_id, body_secret_present:) if authorization.blank?

  raise Invalid.new("invalid_request", "client_secret is not accepted in the request body") if body_secret_present

  client_id, secret = decode_basic(authorization)
  invalid_client! if body_client_id.present? && body_client_id != client_id

  client = Hitch::Client.find_by(client_id: client_id)
  invalid_client! unless client&.authenticates_secret?(secret)

  Resolution.new(
    client_id:,
    token_endpoint_auth_method: "client_secret_basic",
    registered_client: true,
    operator_registered: client.operator_registered?
  )
end