Class: KeycloakRack::ReadToken Private

Inherits:
Object
  • Object
show all
Defined in:
lib/keycloak_rack/read_token.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Read the bearer token from the Authorization token.

Constant Summary collapse

BEARER_TOKEN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The pattern to match bearer tokens with.

/\ABearer (?<token>.+)\z/i.freeze

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Dry::Monads::Success(String), ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • env (Hash, #[])

Returns:

  • (Dry::Monads::Success(String))

    when a token is found

  • (Dry::Monads::Success(nil))

    when a token is not found, but unauthenticated requests are allowed

  • (Dry::Monads::Failure(:no_token, String))

19
20
21
22
23
24
25
26
27
# File 'lib/keycloak_rack/read_token.rb', line 19

def call(env)
  found_token = read_from env

  return Success(found_token) if found_token.present?

  return Success(nil) if config.allow_anonymous?

  Failure[:no_token, "No JWT provided"]
end