Class: Ros::ApiTokenStrategy
- Inherits:
-
Warden::Strategies::Base
- Object
- Warden::Strategies::Base
- Ros::ApiTokenStrategy
- Defined in:
- lib/ros/api_token_strategy.rb
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#auth_string ⇒ Object
Returns the value of attribute auth_string.
-
#auth_type ⇒ Object
Returns the value of attribute auth_type.
-
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
-
#token ⇒ Object
Returns the value of attribute token.
-
#urn ⇒ Object
Returns the value of attribute urn.
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #authenticate_basic ⇒ Object
- #authenticate_bearer ⇒ Object
- #valid? ⇒ Boolean
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
5 6 7 |
# File 'lib/ros/api_token_strategy.rb', line 5 def access_key_id @access_key_id end |
#auth_string ⇒ Object
Returns the value of attribute auth_string.
5 6 7 |
# File 'lib/ros/api_token_strategy.rb', line 5 def auth_string @auth_string end |
#auth_type ⇒ Object
Returns the value of attribute auth_type.
5 6 7 |
# File 'lib/ros/api_token_strategy.rb', line 5 def auth_type @auth_type end |
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
5 6 7 |
# File 'lib/ros/api_token_strategy.rb', line 5 def secret_access_key @secret_access_key end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/ros/api_token_strategy.rb', line 5 def token @token end |
#urn ⇒ Object
Returns the value of attribute urn.
5 6 7 |
# File 'lib/ros/api_token_strategy.rb', line 5 def urn @urn end |
Instance Method Details
#authenticate! ⇒ Object
19 20 21 22 23 24 |
# File 'lib/ros/api_token_strategy.rb', line 19 def authenticate! user = send("authenticate_#{auth_type}") if auth_type.in? %w(basic bearer) return success!(user) if user # This is returned to IAM service fail!({ errors: [{ status: 401, code: 'unauthorized', title: 'Unauthorized' }] }.to_json) end |
#authenticate_basic ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/ros/api_token_strategy.rb', line 26 def authenticate_basic # TODO: Credential.authorization must be an instance variable Ros::Sdk::Credential. = auth_string return unless credential = Ros::IAM::Credential.where(access_key_id: access_key_id).first "Ros::IAM::#{credential.owner_type}".constantize.find(credential.owner_id).first # NOTE: Swallow the auth error and return nil which causes user to be nil, which cuases FailureApp to be invoked rescue JsonApiClient::Errors::NotAuthorized => e end |
#authenticate_bearer ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/ros/api_token_strategy.rb', line 35 def authenticate_bearer return unless urn = Urn.from_jwt(token) return unless urn.model_name.in? %w(Root User) # TODO: Credential.authorization must be an instance variable Ros::Sdk::Credential. = auth_string "Ros::IAM::#{urn.model_name}".constantize.find_by_urn(urn.resource_id) # NOTE: Swallow the auth error and return nil which causes user to be nil, which cuases FailureApp to be invoked rescue JsonApiClient::Errors::NotAuthorized => e end |
#valid? ⇒ Boolean
17 |
# File 'lib/ros/api_token_strategy.rb', line 17 def valid?; token.present? end |