|
1 | 1 | import { type HttpMetaParams } from "../../interfaces"; |
2 | 2 | import { type Token } from "../entities/v1"; |
3 | 3 |
|
4 | | -export interface CreateTokenParamsWithPassword { |
5 | | - readonly grantType: "password"; |
| 4 | +/** |
| 5 | + * @deprecated Use `CreateTokenParamsWithPassword` instead |
| 6 | + */ |
| 7 | +export type CreateTokenParamsWithPassword = CreateTokenWithPasswordParams; |
| 8 | + |
| 9 | +interface BaseCreateTokenParams<T extends string> { |
| 10 | + /** Set equal to `authorization_code` if code is provided in order to gain user-level access. Otherwise, set equal to `client_credentials` to obtain app-level access only. */ |
| 11 | + readonly grantType: T; |
| 12 | + /** The client ID, obtained during app registration. */ |
6 | 13 | readonly clientId: string; |
| 14 | + /** The client secret, obtained during app registration. */ |
7 | 15 | readonly clientSecret: string; |
8 | | - readonly username: string; |
9 | | - readonly password: string; |
| 16 | + /** Set a URI to redirect the user to. If this parameter is set to urn:ietf:wg:oauth:2.0:oob then the token will be shown instead. Must match one of the `redirect_uris` declared during app registration. */ |
| 17 | + readonly redirectUri: string; |
| 18 | + /** List of requested OAuth scopes, separated by spaces (or by pluses, if using query parameters). If code was provided, then this must be equal to the `scope` requested from the user. Otherwise, it must be a subset of `scopes` declared during app registration. If not provided, defaults to read. */ |
10 | 19 | readonly scope?: string; |
11 | 20 | } |
12 | 21 |
|
13 | | -export type CreateTokenParams = CreateTokenParamsWithPassword; |
| 22 | +export interface CreateTokenWithAuthorizationCodeParams |
| 23 | + extends BaseCreateTokenParams<"authorization_code"> { |
| 24 | + /** A user authorization code, obtained via GET /oauth/authorize. */ |
| 25 | + readonly code: string; |
| 26 | +} |
| 27 | + |
| 28 | +export type CreateTokenWithClientCredentialsParams = |
| 29 | + BaseCreateTokenParams<"client_credentials">; |
| 30 | + |
| 31 | +export interface CreateTokenWithPasswordParams |
| 32 | + extends BaseCreateTokenParams<"password"> { |
| 33 | + readonly password: string; |
| 34 | + readonly username: string; |
| 35 | +} |
| 36 | + |
| 37 | +export type CreateTokenParams = |
| 38 | + | CreateTokenWithClientCredentialsParams |
| 39 | + | CreateTokenWithPasswordParams |
| 40 | + | CreateTokenWithAuthorizationCodeParams; |
14 | 41 |
|
15 | 42 | export interface TokenRepository { |
16 | 43 | create( |
|
0 commit comments