@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kevin Malakoff
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @mcp-z/oauth-google
|
|
2
|
+
|
|
3
|
+
Docs: https://mcp-z.github.io/oauth-google
|
|
4
|
+
OAuth client for Google APIs with multi-account support and PKCE.
|
|
5
|
+
|
|
6
|
+
## Common uses
|
|
7
|
+
|
|
8
|
+
- Gmail/Drive/Sheets OAuth in MCP servers
|
|
9
|
+
- CLI and desktop OAuth flows
|
|
10
|
+
- Service account auth for server-to-server access
|
|
11
|
+
- DCR (self-hosted) for shared HTTP servers
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @mcp-z/oauth-google keyv
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Create a Google Cloud app
|
|
20
|
+
|
|
21
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com/).
|
|
22
|
+
2. Create or select a project.
|
|
23
|
+
3. Enable the API you need (Gmail, Drive, or Sheets).
|
|
24
|
+
4. Create OAuth 2.0 credentials (Desktop app).
|
|
25
|
+
5. Copy the Client ID and Client Secret.
|
|
26
|
+
|
|
27
|
+
## OAuth modes
|
|
28
|
+
|
|
29
|
+
### Loopback OAuth (interactive)
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { LoopbackOAuthProvider } from '@mcp-z/oauth-google';
|
|
33
|
+
import Keyv from 'keyv';
|
|
34
|
+
import { KeyvFile } from 'keyv-file';
|
|
35
|
+
|
|
36
|
+
const provider = new LoopbackOAuthProvider({
|
|
37
|
+
service: 'gmail',
|
|
38
|
+
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
39
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
40
|
+
scope: 'https://www.googleapis.com/auth/gmail.modify',
|
|
41
|
+
tokenStore: new Keyv({ store: new KeyvFile({ filename: '.tokens/google.json' }) })
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Service account
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { ServiceAccountProvider } from '@mcp-z/oauth-google';
|
|
49
|
+
|
|
50
|
+
const provider = new ServiceAccountProvider({
|
|
51
|
+
keyFilePath: '/path/to/service-account.json',
|
|
52
|
+
scopes: ['https://www.googleapis.com/auth/drive']
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### DCR (self-hosted)
|
|
57
|
+
|
|
58
|
+
Use `DcrOAuthProvider` for bearer validation and `createDcrRouter` to host the DCR endpoints.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { DcrOAuthProvider, createDcrRouter } from '@mcp-z/oauth-google';
|
|
62
|
+
|
|
63
|
+
const provider = new DcrOAuthProvider({
|
|
64
|
+
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
65
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
66
|
+
scope: 'openid email profile',
|
|
67
|
+
verifyEndpoint: 'https://your-host.com/oauth/verify'
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const router = createDcrRouter({
|
|
71
|
+
store,
|
|
72
|
+
issuerUrl: 'https://your-host.com',
|
|
73
|
+
baseUrl: 'https://your-host.com',
|
|
74
|
+
scopesSupported: ['openid', 'email', 'profile'],
|
|
75
|
+
clientConfig: {
|
|
76
|
+
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
77
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Config helpers
|
|
83
|
+
|
|
84
|
+
Use `parseConfig()` and `parseDcrConfig()` to load CLI + env settings for servers.
|
|
85
|
+
|
|
86
|
+
## Schemas and handler types
|
|
87
|
+
|
|
88
|
+
- `schemas` - Shared Zod schemas used by tools
|
|
89
|
+
- `EnrichedExtra` - Handler extra type with auth context
|
|
90
|
+
|
|
91
|
+
## Requirements
|
|
92
|
+
|
|
93
|
+
- Node.js >= 22
|
|
@@ -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
|
+
*/
|
|
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,112 @@
|
|
|
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
|
+
*/ "use strict";
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
function _export(target, all) {
|
|
12
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
_export(exports, {
|
|
18
|
+
get DcrOAuthProvider () {
|
|
19
|
+
return _dcrts.DcrOAuthProvider;
|
|
20
|
+
},
|
|
21
|
+
get DcrTokenVerifier () {
|
|
22
|
+
return _tokenverifierts.DcrTokenVerifier;
|
|
23
|
+
},
|
|
24
|
+
get LoopbackOAuthProvider () {
|
|
25
|
+
return _loopbackoauthts.LoopbackOAuthProvider;
|
|
26
|
+
},
|
|
27
|
+
get ServiceAccountProvider () {
|
|
28
|
+
return _serviceaccountts.ServiceAccountProvider;
|
|
29
|
+
},
|
|
30
|
+
get createConfig () {
|
|
31
|
+
return _configts.createConfig;
|
|
32
|
+
},
|
|
33
|
+
get createDcrRouter () {
|
|
34
|
+
return _dcrrouterts.createDcrRouter;
|
|
35
|
+
},
|
|
36
|
+
get parseConfig () {
|
|
37
|
+
return _configts.parseConfig;
|
|
38
|
+
},
|
|
39
|
+
get parseDcrConfig () {
|
|
40
|
+
return _configts.parseDcrConfig;
|
|
41
|
+
},
|
|
42
|
+
get schemas () {
|
|
43
|
+
return _indexts;
|
|
44
|
+
},
|
|
45
|
+
get verifyBearerToken () {
|
|
46
|
+
return _dcrverifyts.verifyBearerToken;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var _dcrrouterts = require("./lib/dcr-router.js");
|
|
50
|
+
var _dcrverifyts = require("./lib/dcr-verify.js");
|
|
51
|
+
var _tokenverifierts = require("./lib/token-verifier.js");
|
|
52
|
+
var _dcrts = require("./providers/dcr.js");
|
|
53
|
+
var _loopbackoauthts = require("./providers/loopback-oauth.js");
|
|
54
|
+
var _serviceaccountts = require("./providers/service-account.js");
|
|
55
|
+
var _indexts = /*#__PURE__*/ _interop_require_wildcard(require("./schemas/index.js"));
|
|
56
|
+
var _configts = require("./setup/config.js");
|
|
57
|
+
_export_star(require("./types.js"), exports);
|
|
58
|
+
function _export_star(from, to) {
|
|
59
|
+
Object.keys(from).forEach(function(k) {
|
|
60
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
61
|
+
Object.defineProperty(to, k, {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function() {
|
|
64
|
+
return from[k];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return from;
|
|
70
|
+
}
|
|
71
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
72
|
+
if (typeof WeakMap !== "function") return null;
|
|
73
|
+
var cacheBabelInterop = new WeakMap();
|
|
74
|
+
var cacheNodeInterop = new WeakMap();
|
|
75
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
76
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
77
|
+
})(nodeInterop);
|
|
78
|
+
}
|
|
79
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
80
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
81
|
+
return obj;
|
|
82
|
+
}
|
|
83
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
84
|
+
return {
|
|
85
|
+
default: obj
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
89
|
+
if (cache && cache.has(obj)) {
|
|
90
|
+
return cache.get(obj);
|
|
91
|
+
}
|
|
92
|
+
var newObj = {
|
|
93
|
+
__proto__: null
|
|
94
|
+
};
|
|
95
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
96
|
+
for(var key in obj){
|
|
97
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
98
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
99
|
+
if (desc && (desc.get || desc.set)) {
|
|
100
|
+
Object.defineProperty(newObj, key, desc);
|
|
101
|
+
} else {
|
|
102
|
+
newObj[key] = obj[key];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
newObj.default = obj;
|
|
107
|
+
if (cache) {
|
|
108
|
+
cache.set(obj, newObj);
|
|
109
|
+
}
|
|
110
|
+
return newObj;
|
|
111
|
+
}
|
|
112
|
+
/* 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/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":["DcrOAuthProvider","DcrTokenVerifier","LoopbackOAuthProvider","ServiceAccountProvider","createConfig","createDcrRouter","parseConfig","parseDcrConfig","schemas","verifyBearerToken"],"mappings":"AAAA;;;;;;CAMC;;;;;;;;;;;QAKQA;eAAAA,uBAAgB;;QADDC;eAAAA,iCAAgB;;QAE/BC;eAAAA,sCAAqB;;QACMC;eAAAA,wCAAsB;;QAEjDC;eAAAA,sBAAY;;QAPZC;eAAAA,4BAAe;;QAODC;eAAAA,qBAAW;;QAAEC;eAAAA,wBAAc;;QADtCC;;;QALsBC;eAAAA,8BAAiB;;;2BADG;2BACK;+BACX;qBACc;+BACxB;gCAC4B;+DACzC;wBACiC;qBAC5C"}
|
|
@@ -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;
|
|
@@ -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;
|