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)
Tags
author

Volodymyr Panivko sveneld300@gmail.com

Table of Contents

Properties

$allowed  : bool
$attributes  : array<string|int, mixed>
$error  : string|null
$errorDescription  : string|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).
getAttributes()  : array<string, mixed>
getError()  : string|null
getErrorDescription()  : string|null
getScopes()  : array<int, string>|null
getStatusCode()  : int
isAllowed()  : bool
unauthorized()  : self
Creates a result indicating the request is unauthorized (401).
__construct()  : mixed

Properties

Methods

allow()

Creates a result indicating access is allowed.

public static allow([array<string, mixed> $attributes = [] ]) : self
Parameters
$attributes : array<string, mixed> = []

Attributes to attach to the request (e.g., user_id, scopes)

Return values
self

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

getAttributes()

public getAttributes() : array<string, mixed>
Return values
array<string, mixed>

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

__construct()

private __construct(bool $allowed, int $statusCode, string|null $error, string|null $errorDescription, array<int, string>|null $scopes, array<string, mixed> $attributes) : mixed
Parameters
$allowed : bool
$statusCode : int
$error : string|null
$errorDescription : string|null
$scopes : array<int, string>|null

Scopes to include in WWW-Authenticate challenge

$attributes : array<string, mixed>

Attributes to attach to the request on success


        
On this page

Search results