|
1 | | -import type { FetchLike } from '@modelcontextprotocol/core'; |
| 1 | +import type { FetchLike, OAuthAccessTokenResponseType, OAuthErrorFields, OAuthErrorType, OAuthTokenExchangeResponseType } from '@modelcontextprotocol/core'; |
| 2 | +import { OAuthClientAssertionType, OAuthErrorTypes, OAuthGrantType, OAuthTokenType } from '@modelcontextprotocol/core'; |
2 | 3 | import qs from 'qs'; |
3 | 4 |
|
4 | 5 | import { discoverAuthorizationServerMetadata } from './auth.js'; |
5 | | -// ============================================================================ |
6 | | -// CONSTANTS |
7 | | -// ============================================================================ |
8 | | - |
9 | | -const OAuthErrorTypes = [ |
10 | | - 'invalid_request', |
11 | | - 'invalid_client', |
12 | | - 'invalid_grant', |
13 | | - 'unauthorized_client', |
14 | | - 'unsupported_grant_type', |
15 | | - 'invalid_scope' |
16 | | -] as const; |
17 | | - |
18 | | -// ============================================================================ |
19 | | -// ENUMS |
20 | | -// ============================================================================ |
21 | | - |
22 | | -const enum OAuthGrantType { |
23 | | - JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer', |
24 | | - TOKEN_EXCHANGE = 'urn:ietf:params:oauth:grant-type:token-exchange' |
25 | | -} |
26 | | - |
27 | | -const enum OAuthTokenType { |
28 | | - ACCESS_TOKEN = 'urn:ietf:params:oauth:token-type:access_token', |
29 | | - ID_TOKEN = 'urn:ietf:params:oauth:token-type:id_token', |
30 | | - JWT_ID_JAG = 'urn:ietf:params:oauth:token-type:id-jag', |
31 | | - SAML2 = 'urn:ietf:params:oauth:token-type:saml2' |
32 | | -} |
33 | | - |
34 | | -const enum OAuthClientAssertionType { |
35 | | - JWT_BEARER = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer' |
36 | | -} |
37 | | - |
38 | 6 | // ============================================================================ |
39 | 7 | // TYPES |
40 | 8 | // ============================================================================ |
41 | 9 |
|
42 | | -type OAuthErrorType = (typeof OAuthErrorTypes)[number]; |
43 | | - |
44 | | -type OAuthError = { |
45 | | - error: OAuthErrorType; |
46 | | - error_description?: string; |
47 | | - error_uri?: string; |
48 | | -}; |
49 | | - |
50 | | -type OAuthAccessTokenResponseType = { |
51 | | - access_token: string; |
52 | | - token_type: string; |
53 | | - scope?: string; |
54 | | - expires_in?: number; |
55 | | - refresh_token?: string; |
56 | | -}; |
57 | | - |
58 | | -type OAuthTokenExchangeResponseType = { |
59 | | - access_token: string; |
60 | | - issued_token_type: OAuthTokenType; |
61 | | - token_type: string; |
62 | | - scope?: string; |
63 | | - expires_in?: number; |
64 | | - refresh_token?: string; |
65 | | -}; |
| 10 | +type OAuthError = OAuthErrorFields; |
66 | 11 |
|
67 | 12 | type ClientIdFields = { |
68 | 13 | client_id: string; |
|
0 commit comments