-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
AuthProvider.ts
63 lines (56 loc) · 1.82 KB
/
AuthProvider.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
import type { AccessToken } from '../AccessToken';
/**
* The type of token an auth provider can return - user tokens and app tokens are supported.
*/
export type AuthProviderTokenType = 'user' | 'app';
/**
* Describes a class that manages and supplies access tokens.
*
* Ideally, it should be able to request a new access token via user input
* when previously unauthorized scopes are requested.
*
* As a starting point, {@StaticAuthProvider} takes an access token,
* but can't do anything to upgrade it by itself. {@RefreshingAuthProvider}
* can make use of refresh tokens to refresh your tokens on expiry or failure.
*
* @neverExpand
*/
export interface AuthProvider {
/**
* The client ID.
*/
clientId: string;
/**
* The type of the tokens generated by the provider, i.e. whether this is a user or app token.
*/
tokenType: AuthProviderTokenType;
/**
* The type of Authorization header to send. Defaults to "Bearer".
*/
authorizationType?: string;
/**
* The scopes that are currently available using the access token.
*/
currentScopes: string[];
/**
* Retrieves an access token from the provider.
*
* This should automatically request a new token when the current token
* is not authorized to use the requested scope(s).
*
* When implementing this, you should not do anything major when no
* scopes are requested - the cached token should be valid for that -
* unless you know exactly what you're doing.
*
* @param scopes The requested scope(s).
*/
getAccessToken: (scopes?: string[]) => Promise<AccessToken | null>;
/**
* Requests that the provider fetches a new token from Twitch.
*
* This method is optional to implement. For some use cases,
* it might not be desirable to e.g. ask the user to log in
* again at just any time.
*/
refresh?: () => Promise<AccessToken | null>;
}