@mcp-z/oauth-google 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/cjs/index.d.cts +16 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +112 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/dcr-router.d.cts +44 -0
- package/dist/cjs/lib/dcr-router.d.ts +44 -0
- package/dist/cjs/lib/dcr-router.js +1189 -0
- package/dist/cjs/lib/dcr-router.js.map +1 -0
- package/dist/cjs/lib/dcr-utils.d.cts +160 -0
- package/dist/cjs/lib/dcr-utils.d.ts +160 -0
- package/dist/cjs/lib/dcr-utils.js +860 -0
- package/dist/cjs/lib/dcr-utils.js.map +1 -0
- package/dist/cjs/lib/dcr-verify.d.cts +53 -0
- package/dist/cjs/lib/dcr-verify.d.ts +53 -0
- package/dist/cjs/lib/dcr-verify.js +193 -0
- package/dist/cjs/lib/dcr-verify.js.map +1 -0
- package/dist/cjs/lib/fetch-with-timeout.d.cts +14 -0
- package/dist/cjs/lib/fetch-with-timeout.d.ts +14 -0
- package/dist/cjs/lib/fetch-with-timeout.js +257 -0
- package/dist/cjs/lib/fetch-with-timeout.js.map +1 -0
- package/dist/cjs/lib/token-verifier.d.cts +44 -0
- package/dist/cjs/lib/token-verifier.d.ts +44 -0
- package/dist/cjs/lib/token-verifier.js +253 -0
- package/dist/cjs/lib/token-verifier.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/providers/dcr.d.cts +107 -0
- package/dist/cjs/providers/dcr.d.ts +107 -0
- package/dist/cjs/providers/dcr.js +584 -0
- package/dist/cjs/providers/dcr.js.map +1 -0
- package/dist/cjs/providers/loopback-oauth.d.cts +119 -0
- package/dist/cjs/providers/loopback-oauth.d.ts +119 -0
- package/dist/cjs/providers/loopback-oauth.js +1334 -0
- package/dist/cjs/providers/loopback-oauth.js.map +1 -0
- package/dist/cjs/providers/service-account.d.cts +131 -0
- package/dist/cjs/providers/service-account.d.ts +131 -0
- package/dist/cjs/providers/service-account.js +800 -0
- package/dist/cjs/providers/service-account.js.map +1 -0
- package/dist/cjs/schemas/index.d.cts +20 -0
- package/dist/cjs/schemas/index.d.ts +20 -0
- package/dist/cjs/schemas/index.js +37 -0
- package/dist/cjs/schemas/index.js.map +1 -0
- package/dist/cjs/setup/config.d.cts +112 -0
- package/dist/cjs/setup/config.d.ts +112 -0
- package/dist/cjs/setup/config.js +236 -0
- package/dist/cjs/setup/config.js.map +1 -0
- package/dist/cjs/types.d.cts +173 -0
- package/dist/cjs/types.d.ts +173 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/dcr-router.d.ts +44 -0
- package/dist/esm/lib/dcr-router.js +515 -0
- package/dist/esm/lib/dcr-router.js.map +1 -0
- package/dist/esm/lib/dcr-utils.d.ts +160 -0
- package/dist/esm/lib/dcr-utils.js +270 -0
- package/dist/esm/lib/dcr-utils.js.map +1 -0
- package/dist/esm/lib/dcr-verify.d.ts +53 -0
- package/dist/esm/lib/dcr-verify.js +53 -0
- package/dist/esm/lib/dcr-verify.js.map +1 -0
- package/dist/esm/lib/fetch-with-timeout.d.ts +14 -0
- package/dist/esm/lib/fetch-with-timeout.js +30 -0
- package/dist/esm/lib/fetch-with-timeout.js.map +1 -0
- package/dist/esm/lib/token-verifier.d.ts +44 -0
- package/dist/esm/lib/token-verifier.js +53 -0
- package/dist/esm/lib/token-verifier.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/providers/dcr.d.ts +107 -0
- package/dist/esm/providers/dcr.js +242 -0
- package/dist/esm/providers/dcr.js.map +1 -0
- package/dist/esm/providers/loopback-oauth.d.ts +119 -0
- package/dist/esm/providers/loopback-oauth.js +639 -0
- package/dist/esm/providers/loopback-oauth.js.map +1 -0
- package/dist/esm/providers/service-account.d.ts +131 -0
- package/dist/esm/providers/service-account.js +353 -0
- package/dist/esm/providers/service-account.js.map +1 -0
- package/dist/esm/schemas/index.d.ts +20 -0
- package/dist/esm/schemas/index.js +18 -0
- package/dist/esm/schemas/index.js.map +1 -0
- package/dist/esm/setup/config.d.ts +112 -0
- package/dist/esm/setup/config.js +258 -0
- package/dist/esm/setup/config.js.map +1 -0
- package/dist/esm/types.d.ts +173 -0
- package/dist/esm/types.js +6 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone types for Google OAuth
|
|
3
|
+
* No dependencies on other @mcp-z packages except @mcp-z/oauth
|
|
4
|
+
*/
|
|
5
|
+
import type { AuthFlowDescriptor, CachedToken, DcrClientInformation, DcrClientMetadata, Logger, OAuth2TokenStorageProvider, ProviderTokens, ToolHandler, ToolModule, UserAuthProvider } from '@mcp-z/oauth';
|
|
6
|
+
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
7
|
+
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
import type { OAuth2Client } from 'google-auth-library';
|
|
9
|
+
import type { Keyv } from 'keyv';
|
|
10
|
+
export type { Logger, CachedToken, ToolModule, ProviderTokens, DcrClientMetadata, DcrClientInformation };
|
|
11
|
+
export { AuthRequiredError } from '@mcp-z/oauth';
|
|
12
|
+
export type { ToolHandler, AuthFlowDescriptor, OAuth2TokenStorageProvider, UserAuthProvider, RequestHandlerExtra, ServerRequest, ServerNotification };
|
|
13
|
+
/**
|
|
14
|
+
* Google service types that support OAuth
|
|
15
|
+
* OAuth clients support all Google services provided by googleapis
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type GoogleService = string;
|
|
19
|
+
/**
|
|
20
|
+
* OAuth client configuration for upstream provider
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface OAuthClientConfig {
|
|
24
|
+
/** OAuth client ID for upstream provider */
|
|
25
|
+
clientId: string;
|
|
26
|
+
/** OAuth client secret (optional for some flows) */
|
|
27
|
+
clientSecret?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Google OAuth configuration interface.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export interface OAuthConfig {
|
|
34
|
+
clientId: string;
|
|
35
|
+
/** Optional for public clients */
|
|
36
|
+
clientSecret?: string;
|
|
37
|
+
auth: 'loopback-oauth' | 'service-account' | 'dcr';
|
|
38
|
+
/** No browser interaction when true */
|
|
39
|
+
headless: boolean;
|
|
40
|
+
/** Defaults to ephemeral loopback */
|
|
41
|
+
redirectUri?: string;
|
|
42
|
+
/** Required when auth === 'service-account' */
|
|
43
|
+
serviceAccountKeyFile?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* DCR configuration for dynamic client registration
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export interface DcrConfig {
|
|
50
|
+
/** DCR mode: self-hosted (runs own OAuth server) or external (uses Auth0/Stitch) */
|
|
51
|
+
mode: 'self-hosted' | 'external';
|
|
52
|
+
/** External verification endpoint URL (required for external mode) */
|
|
53
|
+
verifyUrl?: string;
|
|
54
|
+
/** DCR client storage URI (required for self-hosted mode) */
|
|
55
|
+
storeUri?: string;
|
|
56
|
+
/** OAuth client ID for Google APIs */
|
|
57
|
+
clientId: string;
|
|
58
|
+
/** OAuth client secret (optional for public clients) */
|
|
59
|
+
clientSecret?: string;
|
|
60
|
+
/** OAuth scopes to request */
|
|
61
|
+
scope: string;
|
|
62
|
+
/** Logger instance */
|
|
63
|
+
logger?: Logger;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Configuration for loopback OAuth client
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface LoopbackOAuthConfig {
|
|
70
|
+
service: GoogleService;
|
|
71
|
+
clientId: string;
|
|
72
|
+
/** Optional for public clients */
|
|
73
|
+
clientSecret?: string | undefined;
|
|
74
|
+
scope: string;
|
|
75
|
+
/** No browser interaction when true */
|
|
76
|
+
headless: boolean;
|
|
77
|
+
logger: Logger;
|
|
78
|
+
tokenStore: Keyv<unknown>;
|
|
79
|
+
/** Defaults to ephemeral loopback */
|
|
80
|
+
redirectUri?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Auth context injected into extra by middleware
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export interface AuthContext {
|
|
87
|
+
/**
|
|
88
|
+
* OAuth2Client ready for googleapis
|
|
89
|
+
* GUARANTEED to exist when handler runs
|
|
90
|
+
*/
|
|
91
|
+
auth: OAuth2Client;
|
|
92
|
+
/**
|
|
93
|
+
* Account being used (for logging, debugging)
|
|
94
|
+
*/
|
|
95
|
+
accountId: string;
|
|
96
|
+
/**
|
|
97
|
+
* User ID (multi-tenant only)
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* Additional metadata (e.g., service account email)
|
|
101
|
+
*/
|
|
102
|
+
metadata?: {
|
|
103
|
+
serviceEmail?: string;
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Enriched extra with guaranteed auth context and logger
|
|
109
|
+
* Handlers receive this type - never plain RequestHandlerExtra
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export interface EnrichedExtra extends RequestHandlerExtra<ServerRequest, ServerNotification> {
|
|
113
|
+
/**
|
|
114
|
+
* Auth context injected by middleware
|
|
115
|
+
* GUARANTEED to exist (middleware catches auth failures)
|
|
116
|
+
*/
|
|
117
|
+
authContext: AuthContext;
|
|
118
|
+
/**
|
|
119
|
+
* Logger injected by middleware
|
|
120
|
+
* GUARANTEED to exist
|
|
121
|
+
*/
|
|
122
|
+
logger: Logger;
|
|
123
|
+
_meta?: {
|
|
124
|
+
accountId?: string;
|
|
125
|
+
[key: string]: unknown;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Registered client with full metadata
|
|
130
|
+
* Extends DcrClientInformation with internal timestamps
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
export interface RegisteredClient extends DcrClientInformation {
|
|
134
|
+
/** Creation timestamp (milliseconds since epoch) */
|
|
135
|
+
created_at: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Authorization code data structure
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export interface AuthorizationCode {
|
|
142
|
+
code: string;
|
|
143
|
+
client_id: string;
|
|
144
|
+
redirect_uri: string;
|
|
145
|
+
scope: string;
|
|
146
|
+
code_challenge?: string;
|
|
147
|
+
code_challenge_method?: string;
|
|
148
|
+
/** Google provider tokens obtained during authorization */
|
|
149
|
+
providerTokens: ProviderTokens;
|
|
150
|
+
created_at: number;
|
|
151
|
+
expires_at: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Access token data structure
|
|
155
|
+
* @public
|
|
156
|
+
*/
|
|
157
|
+
export interface AccessToken {
|
|
158
|
+
access_token: string;
|
|
159
|
+
token_type: 'Bearer';
|
|
160
|
+
expires_in: number;
|
|
161
|
+
refresh_token?: string;
|
|
162
|
+
scope: string;
|
|
163
|
+
client_id: string;
|
|
164
|
+
/** Google provider tokens */
|
|
165
|
+
providerTokens: ProviderTokens;
|
|
166
|
+
created_at: number;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Authentication required response type
|
|
170
|
+
* Re-exported from @mcp-z/oauth for consistency
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
export type { AuthRequired, AuthRequiredBranch } from './schemas/index.js';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone types for Google OAuth
|
|
3
|
+
* No dependencies on other @mcp-z packages except @mcp-z/oauth
|
|
4
|
+
*/
|
|
5
|
+
import type { AuthFlowDescriptor, CachedToken, DcrClientInformation, DcrClientMetadata, Logger, OAuth2TokenStorageProvider, ProviderTokens, ToolHandler, ToolModule, UserAuthProvider } from '@mcp-z/oauth';
|
|
6
|
+
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
7
|
+
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
import type { OAuth2Client } from 'google-auth-library';
|
|
9
|
+
import type { Keyv } from 'keyv';
|
|
10
|
+
export type { Logger, CachedToken, ToolModule, ProviderTokens, DcrClientMetadata, DcrClientInformation };
|
|
11
|
+
export { AuthRequiredError } from '@mcp-z/oauth';
|
|
12
|
+
export type { ToolHandler, AuthFlowDescriptor, OAuth2TokenStorageProvider, UserAuthProvider, RequestHandlerExtra, ServerRequest, ServerNotification };
|
|
13
|
+
/**
|
|
14
|
+
* Google service types that support OAuth
|
|
15
|
+
* OAuth clients support all Google services provided by googleapis
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type GoogleService = string;
|
|
19
|
+
/**
|
|
20
|
+
* OAuth client configuration for upstream provider
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface OAuthClientConfig {
|
|
24
|
+
/** OAuth client ID for upstream provider */
|
|
25
|
+
clientId: string;
|
|
26
|
+
/** OAuth client secret (optional for some flows) */
|
|
27
|
+
clientSecret?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Google OAuth configuration interface.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export interface OAuthConfig {
|
|
34
|
+
clientId: string;
|
|
35
|
+
/** Optional for public clients */
|
|
36
|
+
clientSecret?: string;
|
|
37
|
+
auth: 'loopback-oauth' | 'service-account' | 'dcr';
|
|
38
|
+
/** No browser interaction when true */
|
|
39
|
+
headless: boolean;
|
|
40
|
+
/** Defaults to ephemeral loopback */
|
|
41
|
+
redirectUri?: string;
|
|
42
|
+
/** Required when auth === 'service-account' */
|
|
43
|
+
serviceAccountKeyFile?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* DCR configuration for dynamic client registration
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export interface DcrConfig {
|
|
50
|
+
/** DCR mode: self-hosted (runs own OAuth server) or external (uses Auth0/Stitch) */
|
|
51
|
+
mode: 'self-hosted' | 'external';
|
|
52
|
+
/** External verification endpoint URL (required for external mode) */
|
|
53
|
+
verifyUrl?: string;
|
|
54
|
+
/** DCR client storage URI (required for self-hosted mode) */
|
|
55
|
+
storeUri?: string;
|
|
56
|
+
/** OAuth client ID for Google APIs */
|
|
57
|
+
clientId: string;
|
|
58
|
+
/** OAuth client secret (optional for public clients) */
|
|
59
|
+
clientSecret?: string;
|
|
60
|
+
/** OAuth scopes to request */
|
|
61
|
+
scope: string;
|
|
62
|
+
/** Logger instance */
|
|
63
|
+
logger?: Logger;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Configuration for loopback OAuth client
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface LoopbackOAuthConfig {
|
|
70
|
+
service: GoogleService;
|
|
71
|
+
clientId: string;
|
|
72
|
+
/** Optional for public clients */
|
|
73
|
+
clientSecret?: string | undefined;
|
|
74
|
+
scope: string;
|
|
75
|
+
/** No browser interaction when true */
|
|
76
|
+
headless: boolean;
|
|
77
|
+
logger: Logger;
|
|
78
|
+
tokenStore: Keyv<unknown>;
|
|
79
|
+
/** Defaults to ephemeral loopback */
|
|
80
|
+
redirectUri?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Auth context injected into extra by middleware
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export interface AuthContext {
|
|
87
|
+
/**
|
|
88
|
+
* OAuth2Client ready for googleapis
|
|
89
|
+
* GUARANTEED to exist when handler runs
|
|
90
|
+
*/
|
|
91
|
+
auth: OAuth2Client;
|
|
92
|
+
/**
|
|
93
|
+
* Account being used (for logging, debugging)
|
|
94
|
+
*/
|
|
95
|
+
accountId: string;
|
|
96
|
+
/**
|
|
97
|
+
* User ID (multi-tenant only)
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* Additional metadata (e.g., service account email)
|
|
101
|
+
*/
|
|
102
|
+
metadata?: {
|
|
103
|
+
serviceEmail?: string;
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Enriched extra with guaranteed auth context and logger
|
|
109
|
+
* Handlers receive this type - never plain RequestHandlerExtra
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export interface EnrichedExtra extends RequestHandlerExtra<ServerRequest, ServerNotification> {
|
|
113
|
+
/**
|
|
114
|
+
* Auth context injected by middleware
|
|
115
|
+
* GUARANTEED to exist (middleware catches auth failures)
|
|
116
|
+
*/
|
|
117
|
+
authContext: AuthContext;
|
|
118
|
+
/**
|
|
119
|
+
* Logger injected by middleware
|
|
120
|
+
* GUARANTEED to exist
|
|
121
|
+
*/
|
|
122
|
+
logger: Logger;
|
|
123
|
+
_meta?: {
|
|
124
|
+
accountId?: string;
|
|
125
|
+
[key: string]: unknown;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Registered client with full metadata
|
|
130
|
+
* Extends DcrClientInformation with internal timestamps
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
export interface RegisteredClient extends DcrClientInformation {
|
|
134
|
+
/** Creation timestamp (milliseconds since epoch) */
|
|
135
|
+
created_at: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Authorization code data structure
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export interface AuthorizationCode {
|
|
142
|
+
code: string;
|
|
143
|
+
client_id: string;
|
|
144
|
+
redirect_uri: string;
|
|
145
|
+
scope: string;
|
|
146
|
+
code_challenge?: string;
|
|
147
|
+
code_challenge_method?: string;
|
|
148
|
+
/** Google provider tokens obtained during authorization */
|
|
149
|
+
providerTokens: ProviderTokens;
|
|
150
|
+
created_at: number;
|
|
151
|
+
expires_at: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Access token data structure
|
|
155
|
+
* @public
|
|
156
|
+
*/
|
|
157
|
+
export interface AccessToken {
|
|
158
|
+
access_token: string;
|
|
159
|
+
token_type: 'Bearer';
|
|
160
|
+
expires_in: number;
|
|
161
|
+
refresh_token?: string;
|
|
162
|
+
scope: string;
|
|
163
|
+
client_id: string;
|
|
164
|
+
/** Google provider tokens */
|
|
165
|
+
providerTokens: ProviderTokens;
|
|
166
|
+
created_at: number;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Authentication required response type
|
|
170
|
+
* Re-exported from @mcp-z/oauth for consistency
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
export type { AuthRequired, AuthRequiredBranch } from './schemas/index.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone types for Google OAuth
|
|
3
|
+
* No dependencies on other @mcp-z packages except @mcp-z/oauth
|
|
4
|
+
*/ // Shared types from base @mcp-z/oauth package
|
|
5
|
+
"use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "AuthRequiredError", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return _oauth.AuthRequiredError;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var _oauth = require("@mcp-z/oauth");
|
|
16
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth-google/src/types.ts"],"sourcesContent":["/**\n * Standalone types for Google OAuth\n * No dependencies on other @mcp-z packages except @mcp-z/oauth\n */\n\n// Shared types from base @mcp-z/oauth package\nimport type { AuthFlowDescriptor, CachedToken, DcrClientInformation, DcrClientMetadata, Logger, OAuth2TokenStorageProvider, ProviderTokens, ToolHandler, ToolModule, UserAuthProvider } from '@mcp-z/oauth';\nimport type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';\nimport type { OAuth2Client } from 'google-auth-library';\nimport type { Keyv } from 'keyv';\n\n// Re-export only essential shared types for public API\nexport type { Logger, CachedToken, ToolModule, ProviderTokens, DcrClientMetadata, DcrClientInformation };\n\n// Re-export error class\nexport { AuthRequiredError } from '@mcp-z/oauth';\n\n// Re-export additional types for internal package use\nexport type { ToolHandler, AuthFlowDescriptor, OAuth2TokenStorageProvider, UserAuthProvider, RequestHandlerExtra, ServerRequest, ServerNotification };\n\n/**\n * Google service types that support OAuth\n * OAuth clients support all Google services provided by googleapis\n * @public\n */\nexport type GoogleService = string;\n\n// =============================================================================\n// Configuration Types\n// =============================================================================\n\n/**\n * OAuth client configuration for upstream provider\n * @public\n */\nexport interface OAuthClientConfig {\n /** OAuth client ID for upstream provider */\n clientId: string;\n /** OAuth client secret (optional for some flows) */\n clientSecret?: string;\n}\n\n/**\n * Google OAuth configuration interface.\n * @public\n */\nexport interface OAuthConfig {\n clientId: string;\n /** Optional for public clients */\n clientSecret?: string;\n auth: 'loopback-oauth' | 'service-account' | 'dcr';\n /** No browser interaction when true */\n headless: boolean;\n /** Defaults to ephemeral loopback */\n redirectUri?: string;\n /** Required when auth === 'service-account' */\n serviceAccountKeyFile?: string;\n}\n\n/**\n * DCR configuration for dynamic client registration\n * @public\n */\nexport interface DcrConfig {\n /** DCR mode: self-hosted (runs own OAuth server) or external (uses Auth0/Stitch) */\n mode: 'self-hosted' | 'external';\n /** External verification endpoint URL (required for external mode) */\n verifyUrl?: string;\n /** DCR client storage URI (required for self-hosted mode) */\n storeUri?: string;\n /** OAuth client ID for Google APIs */\n clientId: string;\n /** OAuth client secret (optional for public clients) */\n clientSecret?: string;\n /** OAuth scopes to request */\n scope: string;\n /** Logger instance */\n logger?: Logger;\n}\n\n/**\n * Configuration for loopback OAuth client\n * @public\n */\nexport interface LoopbackOAuthConfig {\n service: GoogleService;\n clientId: string;\n /** Optional for public clients */\n clientSecret?: string | undefined;\n scope: string;\n /** No browser interaction when true */\n headless: boolean;\n logger: Logger;\n tokenStore: Keyv<unknown>;\n /** Defaults to ephemeral loopback */\n redirectUri?: string;\n}\n\n// =============================================================================\n// Middleware Types\n// =============================================================================\n\n/**\n * Auth context injected into extra by middleware\n * @public\n */\nexport interface AuthContext {\n /**\n * OAuth2Client ready for googleapis\n * GUARANTEED to exist when handler runs\n */\n auth: OAuth2Client;\n\n /**\n * Account being used (for logging, debugging)\n */\n accountId: string;\n\n /**\n * User ID (multi-tenant only)\n */\n\n /**\n * Additional metadata (e.g., service account email)\n */\n metadata?: {\n serviceEmail?: string;\n [key: string]: unknown;\n };\n}\n\n/**\n * Enriched extra with guaranteed auth context and logger\n * Handlers receive this type - never plain RequestHandlerExtra\n * @public\n */\nexport interface EnrichedExtra extends RequestHandlerExtra<ServerRequest, ServerNotification> {\n /**\n * Auth context injected by middleware\n * GUARANTEED to exist (middleware catches auth failures)\n */\n authContext: AuthContext;\n\n /**\n * Logger injected by middleware\n * GUARANTEED to exist\n */\n logger: Logger;\n\n // Preserve backchannel support\n _meta?: {\n accountId?: string;\n [key: string]: unknown;\n };\n}\n\n// =============================================================================\n// DCR Internal Types\n// =============================================================================\n\n/**\n * Registered client with full metadata\n * Extends DcrClientInformation with internal timestamps\n * @internal\n */\nexport interface RegisteredClient extends DcrClientInformation {\n /** Creation timestamp (milliseconds since epoch) */\n created_at: number;\n}\n\n/**\n * Authorization code data structure\n * @public\n */\nexport interface AuthorizationCode {\n code: string;\n client_id: string;\n redirect_uri: string;\n scope: string;\n code_challenge?: string;\n code_challenge_method?: string;\n /** Google provider tokens obtained during authorization */\n providerTokens: ProviderTokens;\n created_at: number;\n expires_at: number;\n}\n\n/**\n * Access token data structure\n * @public\n */\nexport interface AccessToken {\n access_token: string;\n token_type: 'Bearer';\n expires_in: number;\n refresh_token?: string;\n scope: string;\n client_id: string;\n /** Google provider tokens */\n providerTokens: ProviderTokens;\n created_at: number;\n}\n\n// =============================================================================\n// Schema Types\n// =============================================================================\n\n/**\n * Authentication required response type\n * Re-exported from @mcp-z/oauth for consistency\n * @public\n */\nexport type { AuthRequired, AuthRequiredBranch } from './schemas/index.ts';\n"],"names":["AuthRequiredError"],"mappings":"AAAA;;;CAGC,GAED,8CAA8C;;;;;+BAWrCA;;;eAAAA,wBAAiB;;;qBAAQ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mcp-z/oauth-google - Shared Google OAuth implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides OAuth authentication:
|
|
5
|
+
* - Loopback OAuth (RFC 8252) - Server-managed, file-based tokens
|
|
6
|
+
* - Service Account authentication for server-to-server scenarios
|
|
7
|
+
*/
|
|
8
|
+
export { createDcrRouter, type DcrRouterConfig } from './lib/dcr-router.js';
|
|
9
|
+
export { type VerificationResult, verifyBearerToken } from './lib/dcr-verify.js';
|
|
10
|
+
export { type AuthInfo, DcrTokenVerifier } from './lib/token-verifier.js';
|
|
11
|
+
export { DcrOAuthProvider, type DcrOAuthProviderConfig } from './providers/dcr.js';
|
|
12
|
+
export { LoopbackOAuthProvider } from './providers/loopback-oauth.js';
|
|
13
|
+
export { type ServiceAccountConfig, ServiceAccountProvider } from './providers/service-account.js';
|
|
14
|
+
export * as schemas from './schemas/index.js';
|
|
15
|
+
export { createConfig, parseConfig, parseDcrConfig } from './setup/config.js';
|
|
16
|
+
export * from './types.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mcp-z/oauth-google - Shared Google OAuth implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides OAuth authentication:
|
|
5
|
+
* - Loopback OAuth (RFC 8252) - Server-managed, file-based tokens
|
|
6
|
+
* - Service Account authentication for server-to-server scenarios
|
|
7
|
+
*/ export { createDcrRouter } from './lib/dcr-router.js';
|
|
8
|
+
export { verifyBearerToken } from './lib/dcr-verify.js';
|
|
9
|
+
export { DcrTokenVerifier } from './lib/token-verifier.js';
|
|
10
|
+
export { DcrOAuthProvider } from './providers/dcr.js';
|
|
11
|
+
export { LoopbackOAuthProvider } from './providers/loopback-oauth.js';
|
|
12
|
+
export { ServiceAccountProvider } from './providers/service-account.js';
|
|
13
|
+
import * as _schemas from './schemas/index.js';
|
|
14
|
+
export { _schemas as schemas };
|
|
15
|
+
export { createConfig, parseConfig, parseDcrConfig } from './setup/config.js';
|
|
16
|
+
export * from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth-google/src/index.ts"],"sourcesContent":["/**\n * @mcp-z/oauth-google - Shared Google OAuth implementation\n *\n * Provides OAuth authentication:\n * - Loopback OAuth (RFC 8252) - Server-managed, file-based tokens\n * - Service Account authentication for server-to-server scenarios\n */\n\nexport { createDcrRouter, type DcrRouterConfig } from './lib/dcr-router.ts';\nexport { type VerificationResult, verifyBearerToken } from './lib/dcr-verify.ts';\nexport { type AuthInfo, DcrTokenVerifier } from './lib/token-verifier.ts';\nexport { DcrOAuthProvider, type DcrOAuthProviderConfig } from './providers/dcr.ts';\nexport { LoopbackOAuthProvider } from './providers/loopback-oauth.ts';\nexport { type ServiceAccountConfig, ServiceAccountProvider } from './providers/service-account.ts';\nexport * as schemas from './schemas/index.ts';\nexport { createConfig, parseConfig, parseDcrConfig } from './setup/config.ts';\nexport * from './types.ts';\n"],"names":["createDcrRouter","verifyBearerToken","DcrTokenVerifier","DcrOAuthProvider","LoopbackOAuthProvider","ServiceAccountProvider","schemas","createConfig","parseConfig","parseDcrConfig"],"mappings":"AAAA;;;;;;CAMC,GAED,SAASA,eAAe,QAA8B,sBAAsB;AAC5E,SAAkCC,iBAAiB,QAAQ,sBAAsB;AACjF,SAAwBC,gBAAgB,QAAQ,0BAA0B;AAC1E,SAASC,gBAAgB,QAAqC,qBAAqB;AACnF,SAASC,qBAAqB,QAAQ,gCAAgC;AACtE,SAAoCC,sBAAsB,QAAQ,iCAAiC;AACnG,0BAAyB,qBAAqB;AAA9C,SAAO,YAAKC,OAAO,GAA2B;AAC9C,SAASC,YAAY,EAAEC,WAAW,EAAEC,cAAc,QAAQ,oBAAoB;AAC9E,cAAc,aAAa"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DCR Router - OAuth 2.0 Authorization Server
|
|
3
|
+
*
|
|
4
|
+
* Implements OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591)
|
|
5
|
+
* and OAuth 2.0 Authorization Server endpoints (RFC 6749, RFC 8414, RFC 9728).
|
|
6
|
+
*
|
|
7
|
+
* Endpoints:
|
|
8
|
+
* - GET /.well-known/oauth-authorization-server (RFC 8414 metadata)
|
|
9
|
+
* - GET /.well-known/oauth-protected-resource (RFC 9728 metadata - root)
|
|
10
|
+
* - GET /.well-known/oauth-protected-resource/mcp (RFC 9728 metadata - sub-path)
|
|
11
|
+
* - POST /oauth/register (RFC 7591 client registration)
|
|
12
|
+
* - GET /oauth/authorize (RFC 6749 authorization endpoint)
|
|
13
|
+
* - POST /oauth/token (RFC 6749 token endpoint)
|
|
14
|
+
* - POST /oauth/revoke (RFC 7009 token revocation)
|
|
15
|
+
* - GET /oauth/verify (token verification for Resource Server)
|
|
16
|
+
*/
|
|
17
|
+
import express from 'express';
|
|
18
|
+
import type { Keyv } from 'keyv';
|
|
19
|
+
import type { OAuthClientConfig } from '../types.js';
|
|
20
|
+
/**
|
|
21
|
+
* Configuration for DCR Router (self-hosted mode only)
|
|
22
|
+
*/
|
|
23
|
+
export interface DcrRouterConfig {
|
|
24
|
+
/** Single Keyv store for all DCR data */
|
|
25
|
+
store: Keyv;
|
|
26
|
+
/** Authorization Server issuer URL */
|
|
27
|
+
issuerUrl: string;
|
|
28
|
+
/** Base URL for OAuth endpoints */
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
/** Supported OAuth scopes */
|
|
31
|
+
scopesSupported: string[];
|
|
32
|
+
/** OAuth client configuration for upstream provider */
|
|
33
|
+
clientConfig: OAuthClientConfig;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create DCR Router with OAuth 2.0 endpoints (self-hosted mode)
|
|
37
|
+
*
|
|
38
|
+
* For external mode (Auth0/Stitch), don't call this function - no router needed.
|
|
39
|
+
* The server code should check DcrConfig.mode and only call this for 'self-hosted'.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Router configuration
|
|
42
|
+
* @returns Express router with OAuth endpoints
|
|
43
|
+
*/
|
|
44
|
+
export declare function createDcrRouter(config: DcrRouterConfig): express.Router;
|