code = $code; $this->detail = $detail; } /** * Returns the reason code * * @return string the reason code, one of the class constants */ public function get_code() { return $this->code; } /** * Returns the underlying error detail, for logs * * @return string the underlying error detail, or an empty string */ public function get_detail() { return $this->detail; } /** * Returns the admin-facing message for the reason code * * @return string the translated message */ public function get_message() { switch ( $this->code ) { case self::NO_KEY: return __( 'No JWT private secret or JWKS URL is configured', 'ah-jwt-auth' ); case self::MALFORMED_KEY: return __( 'The provided key/key array is empty or malformed', 'ah-jwt-auth' ); case self::MALFORMED_TOKEN: return __( 'The provided JWT is malformed', 'ah-jwt-auth' ); case self::INVALID_TOKEN: return __( 'The provided JWT was invalid', 'ah-jwt-auth' ); case self::INVALID_SIGNATURE: return __( 'Cannot verify the signature of the JWT. Please double check that your private secret or JWKS URL is configured correctly', 'ah-jwt-auth' ); case self::NOT_YET_VALID: return __( 'The provided JWT is trying to be used before it\'s eligible as defined by the \'nbf\' and/or \'iat\' claim', 'ah-jwt-auth' ); case self::EXPIRED: return __( 'The provided JWT has since expired, as defined by the \'exp\' claim', 'ah-jwt-auth' ); case self::MISSING_AUDIENCE: return __( 'The JWT does not contain the required aud claim.', 'ah-jwt-auth' ); case self::AUDIENCE_MISMATCH: return __( 'The JWT aud claim does not match the configured audience.', 'ah-jwt-auth' ); case self::MISSING_ISSUER: return __( 'The JWT does not contain the required iss claim.', 'ah-jwt-auth' ); case self::ISSUER_MISMATCH: return __( 'The JWT iss claim does not match the configured issuer.', 'ah-jwt-auth' ); default: return __( 'There was an unhandled exception while verifying the JWT', 'ah-jwt-auth' ); } } }