-
Notifications
You must be signed in to change notification settings - Fork 413
/
Copy pathindex.ts
100 lines (83 loc) · 2.79 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
export abstract class SdkError extends Error {
public abstract code: string;
}
/**
* Errors that come from Auth0 in the `redirect_uri` callback may contain reflected user input via the OpenID Connect `error` and `error_description` query parameter.
* You should **not** render the error `message`, or `error` and `error_description` properties without properly escaping them first.
*/
export class OAuth2Error extends SdkError {
public code: string;
constructor({ code, message }: { code: string; message?: string }) {
super(
message ??
"An error occured while interacting with the authorization server."
);
this.name = "OAuth2Error";
this.code = code;
}
}
export class DiscoveryError extends SdkError {
public code: string = "discovery_error";
constructor(message?: string) {
super(message ?? "Discovery failed for the OpenID Connect configuration.");
this.name = "DiscoveryError";
}
}
export class MissingStateError extends SdkError {
public code: string = "missing_state";
constructor(message?: string) {
super(message ?? "The state parameter is missing.");
this.name = "MissingStateError";
}
}
export class InvalidStateError extends SdkError {
public code: string = "invalid_state";
constructor(message?: string) {
super(message ?? "The state parameter is invalid.");
this.name = "InvalidStateError";
}
}
export class AuthorizationError extends SdkError {
public code: string = "authorization_error";
public cause: OAuth2Error;
constructor({ cause, message }: { cause: OAuth2Error; message?: string }) {
super(message ?? "An error occured during the authorization flow.");
this.cause = cause;
this.name = "AuthorizationError";
}
}
export class AuthorizationCodeGrantError extends SdkError {
public code: string = "authorization_code_grant_error";
public cause: OAuth2Error;
constructor({ cause, message }: { cause: OAuth2Error; message?: string }) {
super(
message ??
"An error occured while trying to exchange the authorization code."
);
this.cause = cause;
this.name = "AuthorizationCodeGrantError";
}
}
export class BackchannelLogoutError extends SdkError {
public code: string = "backchannel_logout_error";
constructor(message?: string) {
super(
message ??
"An error occured while completing the backchannel logout request."
);
this.name = "BackchannelLogoutError";
}
}
export enum AccessTokenErrorCode {
MISSING_SESSION = "missing_session",
MISSING_REFRESH_TOKEN = "missing_refresh_token",
FAILED_TO_REFRESH_TOKEN = "failed_to_refresh_token"
}
export class AccessTokenError extends SdkError {
public code: string;
constructor(code: string, message: string) {
super(message);
this.name = "AccessTokenError";
this.code = code;
}
}