-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathInteractionRequiredAuthError.ts
More file actions
123 lines (111 loc) · 3.86 KB
/
Copy pathInteractionRequiredAuthError.ts
File metadata and controls
123 lines (111 loc) · 3.86 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { AuthError } from "./AuthError.js";
import * as InteractionRequiredAuthErrorCodes from "./InteractionRequiredAuthErrorCodes.js";
export { InteractionRequiredAuthErrorCodes };
/**
* InteractionRequiredServerErrorMessage contains string constants used by error codes and messages returned by the server indicating interaction is required
*/
export const InteractionRequiredServerErrorMessage = [
InteractionRequiredAuthErrorCodes.interactionRequired,
InteractionRequiredAuthErrorCodes.consentRequired,
InteractionRequiredAuthErrorCodes.loginRequired,
InteractionRequiredAuthErrorCodes.badToken,
InteractionRequiredAuthErrorCodes.uiNotAllowed,
InteractionRequiredAuthErrorCodes.interruptedUser,
];
export const InteractionRequiredAuthSubErrorMessage = [
"message_only",
"additional_action",
"basic_action",
"user_password_expired",
"consent_required",
"bad_token",
"ui_not_allowed",
"interrupted_user",
];
/**
* Error thrown when user interaction is required.
*/
export class InteractionRequiredAuthError extends AuthError {
/**
* The time the error occured at
*/
timestamp: string;
/**
* TraceId associated with the error
*/
traceId: string;
/**
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-common/docs/claims-challenge.md
*
* A string with extra claims needed for the token request to succeed
* web site: redirect the user to the authorization page and set the extra claims
* web api: include the claims in the WWW-Authenticate header that are sent back to the client so that it knows to request a token with the extra claims
* desktop application or browser context: include the claims when acquiring the token interactively
* app to app context (client_credentials): include the claims in the AcquireTokenByClientCredential request
*/
claims: string;
/**
* Server error number;
*/
readonly errorNo?: string;
constructor(
errorCode?: string,
errorMessage?: string,
subError?: string,
timestamp?: string,
traceId?: string,
correlationId?: string,
claims?: string,
errorNo?: string
) {
super(errorCode, errorMessage, subError);
Object.setPrototypeOf(this, InteractionRequiredAuthError.prototype);
this.timestamp = timestamp || "";
this.traceId = traceId || "";
this.correlationId = correlationId || "";
this.claims = claims || "";
this.name = "InteractionRequiredAuthError";
this.errorNo = errorNo;
}
}
/**
* Helper function used to determine if an error thrown by the server requires interaction to resolve
* @param errorCode
* @param errorString
* @param subError
*/
export function isInteractionRequiredError(
errorCode?: string,
errorString?: string,
subError?: string
): boolean {
const isInteractionRequiredErrorCode =
!!errorCode &&
InteractionRequiredServerErrorMessage.indexOf(errorCode) > -1;
const isInteractionRequiredSubError =
!!subError &&
InteractionRequiredAuthSubErrorMessage.indexOf(subError) > -1;
const isInteractionRequiredErrorDesc =
!!errorString &&
InteractionRequiredServerErrorMessage.some((irErrorCode) => {
return errorString.indexOf(irErrorCode) > -1;
});
return (
isInteractionRequiredErrorCode ||
isInteractionRequiredErrorDesc ||
isInteractionRequiredSubError
);
}
/**
* Creates an InteractionRequiredAuthError
*/
export function createInteractionRequiredAuthError(
errorCode: string,
errorMessage?: string
): InteractionRequiredAuthError {
return new InteractionRequiredAuthError(errorCode, errorMessage);
}