Skip to content

Commit 46e32f9

Browse files
committed
Refactored the type as per review
1 parent bb49eac commit 46e32f9

2 files changed

Lines changed: 62 additions & 58 deletions

File tree

packages/client/src/client/xaaUtil.ts

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,13 @@
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';
23
import qs from 'qs';
34

45
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-
386
// ============================================================================
397
// TYPES
408
// ============================================================================
419

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;
6611

6712
type ClientIdFields = {
6813
client_id: string;

packages/core/src/shared/auth.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,64 @@
11
import * as z from 'zod/v4';
22

3+
/**
4+
* OAUTH ENUMS
5+
*/
6+
export const enum OAuthGrantType {
7+
JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer',
8+
TOKEN_EXCHANGE = 'urn:ietf:params:oauth:grant-type:token-exchange'
9+
}
10+
11+
export const enum OAuthTokenType {
12+
ACCESS_TOKEN = 'urn:ietf:params:oauth:token-type:access_token',
13+
ID_TOKEN = 'urn:ietf:params:oauth:token-type:id_token',
14+
JWT_ID_JAG = 'urn:ietf:params:oauth:token-type:id-jag',
15+
SAML2 = 'urn:ietf:params:oauth:token-type:saml2'
16+
}
17+
18+
export const enum OAuthClientAssertionType {
19+
JWT_BEARER = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
20+
}
21+
22+
/**
23+
* OAUTH CONSTANTS
24+
*/
25+
export const OAuthErrorTypes = [
26+
'invalid_request',
27+
'invalid_client',
28+
'invalid_grant',
29+
'unauthorized_client',
30+
'unsupported_grant_type',
31+
'invalid_scope'
32+
] as const;
33+
34+
/**
35+
* OAUTH TYPES
36+
*/
37+
export type OAuthErrorType = (typeof OAuthErrorTypes)[number];
38+
39+
export type OAuthErrorFields = {
40+
error: OAuthErrorType;
41+
error_description?: string;
42+
error_uri?: string;
43+
};
44+
45+
export type OAuthAccessTokenResponseType = {
46+
access_token: string;
47+
token_type: string;
48+
scope?: string;
49+
expires_in?: number;
50+
refresh_token?: string;
51+
};
52+
53+
export type OAuthTokenExchangeResponseType = {
54+
access_token: string;
55+
issued_token_type: OAuthTokenType;
56+
token_type: string;
57+
scope?: string;
58+
expires_in?: number;
59+
refresh_token?: string;
60+
};
61+
362
/**
463
* Reusable URL validation that disallows javascript: scheme
564
*/

0 commit comments

Comments
 (0)