class Ros::ApiTokenStrategy

Attributes

access_key_id[RW]
auth_string[RW]
auth_type[RW]
secret_access_key[RW]
token[RW]
urn[RW]

Public Instance Methods

authenticate!() click to toggle source
# 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() click to toggle source
# File lib/ros/api_token_strategy.rb, line 26
def authenticate_basic
  # TODO: Credential.authorization must be an instance variable
  Ros::Sdk::Credential.authorization = 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() click to toggle source
# 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.authorization = 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?() click to toggle source
# File lib/ros/api_token_strategy.rb, line 17
def valid?; token.present? end