-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
ClientConfigurationError.ts
207 lines (183 loc) · 9.31 KB
/
ClientConfigurationError.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { ClientAuthError } from "./ClientAuthError";
import { TelemetryOptions } from "../Configuration";
interface IClientConfigurationErrorMessage {
code: string,
desc: string
}
export const ClientConfigurationErrorMessage: Record<string, IClientConfigurationErrorMessage> = {
configurationNotSet: {
code: "no_config_set",
desc: "Configuration has not been set. Please call the UserAgentApplication constructor with a valid Configuration object."
},
storageNotSupported: {
code: "storage_not_supported",
desc: "The value for the cacheLocation is not supported."
},
noRedirectCallbacksSet: {
code: "no_redirect_callbacks",
desc: "No redirect callbacks have been set. Please call handleRedirectCallback() with the appropriate function arguments before continuing. " +
"More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics."
},
invalidCallbackObject: {
code: "invalid_callback_object",
desc: "The object passed for the callback was invalid. " +
"More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics."
},
scopesRequired: {
code: "scopes_required",
desc: "Scopes are required to obtain an access token."
},
emptyScopes: {
code: "empty_input_scopes_error",
desc: "Scopes cannot be passed as empty array."
},
nonArrayScopes: {
code: "nonarray_input_scopes_error",
desc: "Scopes cannot be passed as non-array."
},
invalidPrompt: {
code: "invalid_prompt_value",
desc: "Supported prompt values are 'login', 'select_account', 'consent' and 'none'",
},
invalidAuthorityType: {
code: "invalid_authority_type",
desc: "The given authority is not a valid type of authority supported by MSAL. Please see here for valid authorities: <insert URL here>."
},
authorityUriInsecure: {
code: "authority_uri_insecure",
desc: "Authority URIs must use https."
},
authorityUriInvalidPath: {
code: "authority_uri_invalid_path",
desc: "Given authority URI is invalid."
},
unsupportedAuthorityValidation: {
code: "unsupported_authority_validation",
desc: "The authority validation is not supported for this authority type."
},
untrustedAuthority: {
code: "untrusted_authority",
desc: "The provided authority is not a trusted authority. Please include this authority in the knownAuthorities config parameter or set validateAuthority=false."
},
b2cAuthorityUriInvalidPath: {
code: "b2c_authority_uri_invalid_path",
desc: "The given URI for the B2C authority is invalid."
},
b2cKnownAuthoritiesNotSet: {
code: "b2c_known_authorities_not_set",
desc: "Must set known authorities when validateAuthority is set to True and using B2C"
},
claimsRequestParsingError: {
code: "claims_request_parsing_error",
desc: "Could not parse the given claims request object."
},
emptyRequestError: {
code: "empty_request_error",
desc: "Request object is required."
},
invalidCorrelationIdError: {
code: "invalid_guid_sent_as_correlationId",
desc: "Please set the correlationId as a valid guid"
},
telemetryConfigError: {
code: "telemetry_config_error",
desc: "Telemetry config is not configured with required values"
},
ssoSilentError: {
code: "sso_silent_error",
desc: "request must contain either sid or login_hint"
},
invalidAuthorityMetadataError: {
code: "authority_metadata_error",
desc: "Invalid authorityMetadata. Must be a JSON object containing authorization_endpoint, end_session_endpoint, and issuer fields."
}
};
/**
* Error thrown when there is an error in configuration of the .js library.
*/
export class ClientConfigurationError extends ClientAuthError {
constructor(errorCode: string, errorMessage?: string) {
super(errorCode, errorMessage);
this.name = "ClientConfigurationError";
Object.setPrototypeOf(this, ClientConfigurationError.prototype);
}
static createNoSetConfigurationError(): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.configurationNotSet.code,
`${ClientConfigurationErrorMessage.configurationNotSet.desc}`);
}
static createStorageNotSupportedError(givenCacheLocation: string) : ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.storageNotSupported.code,
`${ClientConfigurationErrorMessage.storageNotSupported.desc} Given location: ${givenCacheLocation}`);
}
static createRedirectCallbacksNotSetError(): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.noRedirectCallbacksSet.code, ClientConfigurationErrorMessage.noRedirectCallbacksSet.desc);
}
static createInvalidCallbackObjectError(callbackObject: object): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidCallbackObject.code,
`${ClientConfigurationErrorMessage.invalidCallbackObject.desc} Given value for callback function: ${callbackObject}`);
}
static createEmptyScopesArrayError(scopesValue: string): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.emptyScopes.code,
`${ClientConfigurationErrorMessage.emptyScopes.desc} Given value: ${scopesValue}.`);
}
static createScopesNonArrayError(scopesValue: string): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.nonArrayScopes.code,
`${ClientConfigurationErrorMessage.nonArrayScopes.desc} Given value: ${scopesValue}.`);
}
static createScopesRequiredError(scopesValue: string[]): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.scopesRequired.code,
`${ClientConfigurationErrorMessage.scopesRequired.desc} Given value: ${scopesValue}`);
}
static createInvalidPromptError(promptValue: string): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidPrompt.code,
`${ClientConfigurationErrorMessage.invalidPrompt.desc} Given value: ${promptValue}`);
}
static createClaimsRequestParsingError(claimsRequestParseError: string): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.claimsRequestParsingError.code,
`${ClientConfigurationErrorMessage.claimsRequestParsingError.desc} Given value: ${claimsRequestParseError}`);
}
static createEmptyRequestError(): ClientConfigurationError {
const { code, desc } = ClientConfigurationErrorMessage.emptyRequestError;
return new ClientConfigurationError(code, desc);
}
static createInvalidCorrelationIdError(): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidCorrelationIdError.code,
ClientConfigurationErrorMessage.invalidCorrelationIdError.desc);
}
static createKnownAuthoritiesNotSetError(): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.b2cKnownAuthoritiesNotSet.code,
ClientConfigurationErrorMessage.b2cKnownAuthoritiesNotSet.desc);
}
static createInvalidAuthorityTypeError(): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthorityType.code,
ClientConfigurationErrorMessage.invalidAuthorityType.desc);
}
static createUntrustedAuthorityError(host: string): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.untrustedAuthority.code,
`${ClientConfigurationErrorMessage.untrustedAuthority.desc} Provided Authority: ${host}`);
}
static createTelemetryConfigError(config: TelemetryOptions): ClientConfigurationError {
const { code, desc } = ClientConfigurationErrorMessage.telemetryConfigError;
const requiredKeys = {
applicationName: "string",
applicationVersion: "string",
telemetryEmitter: "function"
};
const missingKeys = Object.keys(requiredKeys)
.reduce((keys, key) => {
return config[key] ? keys : keys.concat([ `${key} (${requiredKeys[key]})` ]);
}, []);
return new ClientConfigurationError(code, `${desc} mising values: ${missingKeys.join(",")}`);
}
static createSsoSilentError(): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.ssoSilentError.code,
ClientConfigurationErrorMessage.ssoSilentError.desc);
}
static createInvalidAuthorityMetadataError(): ClientConfigurationError {
return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthorityMetadataError.code, ClientConfigurationErrorMessage.invalidAuthorityMetadataError.desc);
}
}