@oa2/core
Version:
A comprehensive, RFC-compliant OAuth 2.0 authorization server implementation in TypeScript
1 lines • 6.67 kB
Source Map (JSON)
{"version":3,"file":"errors.d.ts","sources":["../src/errors.ts"],"sourcesContent":["import { OAuth2ErrorCode } from './types';\n\n/**\n * Default Descriptions\n */\nexport const defaultErrorDescriptions: Record<OAuth2ErrorCode, string> = {\n invalid_request:\n 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.',\n unauthorized_client: 'The client is not authorized to request an authorization code using this method.',\n access_denied: 'The resource owner or authorization server denied the request.',\n unsupported_response_type:\n 'The authorization server does not support obtaining an authorization code using this response type.',\n invalid_scope: 'The requested scope is invalid, unknown, or malformed.',\n server_error:\n 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.',\n temporarily_unavailable:\n 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.',\n invalid_grant:\n 'The provided authorization grant (e.g., authorization code, refresh token) or the refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.',\n unsupported_grant_type: 'The authorization grant type is not supported by the authorization server.',\n};\n\n/**\n * Base class for all OAuth2 related errors.\n */\nexport class OAuth2Error extends Error {\n public readonly code: OAuth2ErrorCode;\n public readonly description?: string;\n public readonly statusCode: number;\n\n constructor(code: OAuth2ErrorCode, description?: string, statusCode: number = 400) {\n super(`[${code}] ${description || defaultErrorDescriptions[code] || 'Unknown error'}`);\n this.name = 'OAuth2Error';\n this.code = code;\n this.description = description || defaultErrorDescriptions[code] || 'Unknown error';\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Represents an 'invalid_request' error as per OAuth2 specification.\n * This error indicates that the request is missing a required parameter,\n * includes an invalid parameter value, includes a parameter more than once,\n * or is otherwise malformed.\n */\nexport class InvalidRequestError extends OAuth2Error {\n constructor(description?: string) {\n super('invalid_request', description, 400);\n this.name = 'InvalidRequestError';\n }\n}\n\n/**\n * Represents an 'unauthorized_client' error as per OAuth2 specification.\n * This error indicates that the client is not authorized to request an authorization\n * code using this method.\n */\nexport class UnauthorizedClientError extends OAuth2Error {\n constructor(description?: string) {\n super('unauthorized_client', description, 400);\n this.name = 'UnauthorizedClientError';\n }\n}\n\n/**\n * Represents an 'access_denied' error as per OAuth2 specification.\n * This error indicates that the resource owner or authorization server denied the request.\n */\nexport class AccessDeniedError extends OAuth2Error {\n constructor(description?: string) {\n super('access_denied', description, 400);\n this.name = 'AccessDeniedError';\n }\n}\n\n/**\n * Represents an 'unsupported_response_type' error as per OAuth2 specification.\n * This error indicates that the authorization server does not support\n * obtaining an authorization code using this response type.\n */\nexport class UnsupportedResponseTypeError extends OAuth2Error {\n constructor(description?: string) {\n super('unsupported_response_type', description, 400);\n this.name = 'UnsupportedResponseTypeError';\n }\n}\n\n/**\n * Represents an 'invalid_scope' error as per OAuth2 specification.\n * This error indicates that the requested scope is invalid, unknown, or malformed.\n */\nexport class InvalidScopeError extends OAuth2Error {\n constructor(description?: string) {\n super('invalid_scope', description, 400);\n this.name = 'InvalidScopeError';\n }\n}\n\n/**\n * Represents a 'server_error' as per OAuth2 specification.\n * This error indicates that the authorization server encountered an unexpected\n * condition that prevented it from fulfilling the request.\n */\nexport class ServerError extends OAuth2Error {\n constructor(description?: string) {\n super('server_error', description, 500);\n this.name = 'ServerError';\n }\n}\n\n/**\n * Represents a 'temporarily_unavailable' error as per OAuth2 specification.\n * This error indicates that the authorization server is currently unable to handle\n * the request due to a temporary overloading or maintenance of the server.\n */\nexport class TemporarilyUnavailableError extends OAuth2Error {\n constructor(description?: string) {\n super('temporarily_unavailable', description, 503);\n this.name = 'TemporarilyUnavailableError';\n }\n}\n\n/**\n * Represents an 'invalid_grant' error as per OAuth2 specification.\n * This error indicates that the provided authorization grant (e.g., authorization code,\n * refresh token) or the refresh token is invalid, expired, revoked, does not match the\n * redirection URI used in the authorization request, or was issued to another client.\n */\nexport class InvalidGrantError extends OAuth2Error {\n constructor(description?: string) {\n super('invalid_grant', description, 400);\n this.name = 'InvalidGrantError';\n }\n}\n\n/**\n * Represents an 'unsupported_grant_type' error as per OAuth2 specification.\n * This error indicates that the authorization grant type is not supported by the\n * authorization server.\n * @see RFC 6749, Section 5.2 Error Response\n */\nexport class UnsupportedGrantTypeError extends OAuth2Error {\n constructor(description?: string) {\n super('unsupported_grant_type', description, 400);\n this.name = 'UnsupportedGrantTypeError';\n }\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACO,cAAA,wBAAA,EAAA,MAAA,CAAA,eAAA;AACP;AACA;AACA;AACO,cAAA,WAAA,SAAA,KAAA;AACP,mBAAA,eAAA;AACA;AACA;AACA,sBAAA,eAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,mBAAA,SAAA,WAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,uBAAA,SAAA,WAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,iBAAA,SAAA,WAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,4BAAA,SAAA,WAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,iBAAA,SAAA,WAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,WAAA,SAAA,WAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,2BAAA,SAAA,WAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,iBAAA,SAAA,WAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,yBAAA,SAAA,WAAA;AACP;AACA;;;;"}