Class: PadlockAuth::Rails::TokenFactory
- Inherits:
-
Object
- Object
- PadlockAuth::Rails::TokenFactory
- Defined in:
- lib/padlock_auth/rails/token_factory.rb
Overview
Responsible for extracting access tokens from requests, and delgating the creation of access tokens to the configured strategy.
Class Method Summary collapse
-
.authenticate(request) ⇒ Object
Retreives the access token from the request, and builds an access token object.
-
.from_access_token_param(request) ⇒ String?
Extracts the access token from the ‘access_token` parameter.
-
.from_basic_authorization(request) ⇒ Array?
Extracts Basic Auth credentials from the ‘Authorization` header.
-
.from_bearer_authorization(request) ⇒ String?
Extracts a Bearer access token from the ‘Authorization` header.
-
.from_bearer_param(request) ⇒ String?
Extracts the access token from the ‘bearer_token` parameter.
-
.from_request(request, *methods) ⇒ Object
Retreives the access token from the request using the configured methods.
Class Method Details
.authenticate(request) ⇒ Object
Retreives the access token from the request, and builds an access token object.
20 21 22 23 24 25 26 27 28 |
# File 'lib/padlock_auth/rails/token_factory.rb', line 20 def authenticate(request) if (token = from_request(request, *PadlockAuth.config.access_token_methods)) if token.is_a?(Array) PadlockAuth.build_access_token_from_credentials(*token) else PadlockAuth.build_access_token(token) end end end |
.from_access_token_param(request) ⇒ String?
Extracts the access token from the ‘access_token` parameter.
36 37 38 |
# File 'lib/padlock_auth/rails/token_factory.rb', line 36 def from_access_token_param(request) request.parameters[:access_token] end |
.from_basic_authorization(request) ⇒ Array?
Extracts Basic Auth credentials from the ‘Authorization` header.
68 69 70 71 72 |
# File 'lib/padlock_auth/rails/token_factory.rb', line 68 def (request) pattern = /^Basic /i header = request. token_from_basic_header(header, pattern) if match?(header, pattern) end |
.from_bearer_authorization(request) ⇒ String?
Extracts a Bearer access token from the ‘Authorization` header.
56 57 58 59 60 |
# File 'lib/padlock_auth/rails/token_factory.rb', line 56 def (request) pattern = /^Bearer /i header = request. token_from_header(header, pattern) if match?(header, pattern) end |
.from_bearer_param(request) ⇒ String?
Extracts the access token from the ‘bearer_token` parameter.
46 47 48 |
# File 'lib/padlock_auth/rails/token_factory.rb', line 46 def from_bearer_param(request) request.parameters[:bearer_token] end |
.from_request(request, *methods) ⇒ Object
Retreives the access token from the request using the configured methods.
11 12 13 14 15 16 17 |
# File 'lib/padlock_auth/rails/token_factory.rb', line 11 def from_request(request, *methods) methods.inject(nil) do |_, method| method = self.method(method) if method.is_a?(Symbol) credentials = method.call(request) break credentials if credentials.present? end end |