forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomAuthenticationProvider.ts
More file actions
55 lines (50 loc) · 1.5 KB
/
CustomAuthenticationProvider.ts
File metadata and controls
55 lines (50 loc) · 1.5 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
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module CustomAuthenticationProvider
*/
import { AuthenticationProvider } from "./IAuthenticationProvider";
import { AuthProvider } from "./IAuthProvider";
/**
* @class
* Class representing CustomAuthenticationProvider
* @extends AuthenticationProvider
*/
export class CustomAuthenticationProvider implements AuthenticationProvider {
/**
* @private
* A member to hold authProvider callback
*/
private provider: AuthProvider;
/**
* @public
* @constructor
* Creates an instance of CustomAuthenticationProvider
* @param {AuthProviderCallback} provider - An authProvider function
* @returns An instance of CustomAuthenticationProvider
*/
public constructor(provider: AuthProvider) {
this.provider = provider;
}
/**
* @public
* @async
* To get the access token
* @returns The promise that resolves to an access token
*/
public async getAccessToken(): Promise<any> {
return new Promise((resolve: (accessToken: string) => void, reject: (error: any) => void) => {
this.provider((error: any, accessToken: string | null) => {
if (accessToken) {
resolve(accessToken);
} else {
reject(error);
}
});
});
}
}