Sha256: 9eea1219a1976c682371ad6afff08fdce58aae4bd9178cf5f97236c7cf67193e

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

module CognitoTokenVerifier
  class Error < StandardError; end

  class ConfigSetupError < StandardError
    def initialize(config)
      @aws_region = config.aws_region
      @user_pool_id = config.user_pool_id
    end

    def message
      "Configuration of CognitoTokenVerifier is incomplete: please verify aws_region (#{@aws_region}) and Cognito user_pool_id (#{@user_pool_id})."
    end
  end

  class TokenMissing < CognitoTokenVerifier::Error
    def message
      "Cognito token not provided.  Please retransmit request with Cognito token in authorization header."
    end
  end
  
  class TokenExpired < StandardError
    def message
      "Cognito token has expired.  Please reauthorize and try again."
    end
  end

  class IncorrectTokenType < CognitoTokenVerifier::Error
    def initialize(token)
      @token_use = token.decoded_token['token_use']
    end
    
    def message
      "Incorrect token type. Received #{@token_use} while expecting one of #{[CognitoTokenVerifier.config.token_use].flatten}."
    end
  end

  class InvalidIss < CognitoTokenVerifier::Error
    def initialize(token)
      @iss = token.decoded_token['iss']
    end

    def message
      "Invalid token ISS reference. Received #{@iss} while expecting #{CognitoTokenVerifier.config.iss}."
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cognito_token_verifier-0.1.0 lib/cognito_token_verifier/errors.rb