Class: Foobara::Auth::AuthenticateWithApiKey
- Defined in:
- foobara-auth-0.1.1/src/authenticate_with_api_key.rb
Defined Under Namespace
Classes: ApiKeyDoesNotExistError, InvalidApiKeyError
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#api_key_id ⇒ Object
Returns the value of attribute api_key_id.
-
#api_key_record ⇒ Object
Returns the value of attribute api_key_record.
-
#api_key_secret ⇒ Object
Returns the value of attribute api_key_secret.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #determine_api_key_id_and_secret ⇒ Object
- #execute ⇒ Object
- #load_api_key_record ⇒ Object
- #load_user ⇒ Object
- #user_and_credential ⇒ Object
- #verify_api_key ⇒ Object
Methods inherited from Command
Methods included from TruncatedInspect
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Instance Attribute Details
#api_key_id ⇒ Object
Returns the value of attribute api_key_id.
37 38 39 |
# File 'src/authenticate_with_api_key.rb', line 37 def api_key_id @api_key_id end |
#api_key_record ⇒ Object
Returns the value of attribute api_key_record.
37 38 39 |
# File 'src/authenticate_with_api_key.rb', line 37 def api_key_record @api_key_record end |
#api_key_secret ⇒ Object
Returns the value of attribute api_key_secret.
37 38 39 |
# File 'src/authenticate_with_api_key.rb', line 37 def api_key_secret @api_key_secret end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
37 38 39 |
# File 'src/authenticate_with_api_key.rb', line 37 def expires_at @expires_at end |
#user ⇒ Object
Returns the value of attribute user.
37 38 39 |
# File 'src/authenticate_with_api_key.rb', line 37 def user @user end |
Instance Method Details
#determine_api_key_id_and_secret ⇒ Object
39 40 41 |
# File 'src/authenticate_with_api_key.rb', line 39 def determine_api_key_id_and_secret self.api_key_id, self.api_key_secret = api_key.split("_") end |
#execute ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'src/authenticate_with_api_key.rb', line 27 def execute determine_api_key_id_and_secret load_api_key_record verify_api_key load_user user_and_credential end |
#load_api_key_record ⇒ Object
43 44 45 46 47 |
# File 'src/authenticate_with_api_key.rb', line 43 def load_api_key_record self.api_key_record = Types::Token.load(api_key_id) rescue Foobara::Entity::NotFoundError add_runtime_error(ApiKeyDoesNotExistError) end |
#load_user ⇒ Object
57 58 59 |
# File 'src/authenticate_with_api_key.rb', line 57 def load_user self.user ||= Types::User.that_owns(api_key_record, "api_keys") end |
#user_and_credential ⇒ Object
61 62 63 |
# File 'src/authenticate_with_api_key.rb', line 61 def user_and_credential [user, api_key_record] end |
#verify_api_key ⇒ Object
49 50 51 52 53 54 55 |
# File 'src/authenticate_with_api_key.rb', line 49 def verify_api_key valid = run_subcommand!(VerifyToken, token_string: api_key) unless valid[:verified] add_runtime_error(InvalidApiKeyError) end end |