MCP PHP SDK

AuthorizationResult

FinalYes

Describes the outcome of an authorization decision.

Use the static factory methods to create instances:

  • allow() - Access is granted
  • unauthorized() - No valid credentials provided (401)
  • forbidden() - Valid credentials but insufficient permissions (403)
  • badRequest() - Malformed request (400)
  • unavailable() - Token validation temporarily unavailable (503)
Tags
author

Volodymyr Panivko sveneld300@gmail.com

Table of Contents

Properties

$accessToken  : AccessToken|null
$allowed  : bool
$error  : string|null
$errorDescription  : string|null
$retryAfter  : int|null
$scopes  : array<string|int, mixed>|null
$statusCode  : int

Methods

allow()  : self
Creates a result indicating access is allowed.
badRequest()  : self
Creates a result indicating a bad request (400).
forbidden()  : self
Creates a result indicating the request is forbidden (403).
getAccessToken()  : AccessToken|null
The validated token; set only on an allowed result.
getError()  : string|null
getErrorDescription()  : string|null
getRetryAfter()  : int|null
getScopes()  : array<int, string>|null
getStatusCode()  : int
isAllowed()  : bool
unauthorized()  : self
Creates a result indicating the request is unauthorized (401).
unavailable()  : self
__construct()  : mixed

Properties

Methods

badRequest()

Creates a result indicating a bad request (400).

public static badRequest([string|null $error = 'invalid_request' ][, string|null $errorDescription = null ]) : self

Use when the Authorization header is malformed.

Parameters
$error : string|null = 'invalid_request'

OAuth error code (defaults to "invalid_request")

$errorDescription : string|null = null

Human-readable error description

Return values
self

forbidden()

Creates a result indicating the request is forbidden (403).

public static forbidden([string|null $error = 'insufficient_scope' ][, string|null $errorDescription = null ][, array<int, string>|null $scopes = null ]) : self

Use when the token is valid but lacks required permissions/scopes.

Parameters
$error : string|null = 'insufficient_scope'

OAuth error code (defaults to "insufficient_scope")

$errorDescription : string|null = null

Human-readable error description

$scopes : array<int, string>|null = null

Required scopes to include in challenge

Return values
self

getErrorDescription()

public getErrorDescription() : string|null
Return values
string|null

getScopes()

public getScopes() : array<int, string>|null
Return values
array<int, string>|null

unauthorized()

Creates a result indicating the request is unauthorized (401).

public static unauthorized([string|null $error = null ][, string|null $errorDescription = null ][, array<int, string>|null $scopes = null ]) : self

Use when no valid credentials are provided or the token is invalid.

Parameters
$error : string|null = null

OAuth error code (e.g., "invalid_token")

$errorDescription : string|null = null

Human-readable error description

$scopes : array<int, string>|null = null

Required scopes to include in challenge

Return values
self

unavailable()

public static unavailable([int|null $retryAfter = null ]) : self
Parameters
$retryAfter : int|null = null

Suggested delay before retrying, in seconds

Tags
throws
InvalidArgumentException

if the delay is negative

Return values
self

__construct()

private __construct(bool $allowed, int $statusCode, string|null $error, string|null $errorDescription, array<int, string>|null $scopes, AccessToken|null $accessToken[, int|null $retryAfter = null ]) : mixed
Parameters
$allowed : bool
$statusCode : int
$error : string|null
$errorDescription : string|null
$scopes : array<int, string>|null

Scopes to include in WWW-Authenticate challenge

$accessToken : AccessToken|null
$retryAfter : int|null = null
On this page

Search results