@authfn/oauth-provider 0.0.0 → 0.2.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/README.md +97 -1
- package/dist/authorize/index.d.ts +5 -0
- package/dist/authorize/index.d.ts.map +1 -0
- package/dist/authorize/index.js +247 -0
- package/dist/authorize/index.js.map +1 -0
- package/dist/http.d.ts +35 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +161 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/introspection/index.d.ts +13 -0
- package/dist/introspection/index.d.ts.map +1 -0
- package/dist/introspection/index.js +47 -0
- package/dist/introspection/index.js.map +1 -0
- package/dist/metadata/index.d.ts +10 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +41 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/pkce.d.ts +4 -0
- package/dist/pkce.d.ts.map +1 -0
- package/dist/pkce.js +17 -0
- package/dist/pkce.js.map +1 -0
- package/dist/registration/document.d.ts +49 -0
- package/dist/registration/document.d.ts.map +1 -0
- package/dist/registration/document.js +167 -0
- package/dist/registration/document.js.map +1 -0
- package/dist/registration/index.d.ts +38 -0
- package/dist/registration/index.d.ts.map +1 -0
- package/dist/registration/index.js +264 -0
- package/dist/registration/index.js.map +1 -0
- package/dist/registration/metadata.d.ts +27 -0
- package/dist/registration/metadata.d.ts.map +1 -0
- package/dist/registration/metadata.js +74 -0
- package/dist/registration/metadata.js.map +1 -0
- package/dist/registration/store.d.ts +82 -0
- package/dist/registration/store.d.ts.map +1 -0
- package/dist/registration/store.js +187 -0
- package/dist/registration/store.js.map +1 -0
- package/dist/revocation/index.d.ts +12 -0
- package/dist/revocation/index.d.ts.map +1 -0
- package/dist/revocation/index.js +34 -0
- package/dist/revocation/index.js.map +1 -0
- package/dist/runtime.d.ts +64 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +228 -0
- package/dist/runtime.js.map +1 -0
- package/dist/store.d.ts +155 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +467 -0
- package/dist/store.js.map +1 -0
- package/dist/token/code.d.ts +11 -0
- package/dist/token/code.d.ts.map +1 -0
- package/dist/token/code.js +64 -0
- package/dist/token/code.js.map +1 -0
- package/dist/token/index.d.ts +5 -0
- package/dist/token/index.d.ts.map +1 -0
- package/dist/token/index.js +39 -0
- package/dist/token/index.js.map +1 -0
- package/dist/token/refresh.d.ts +10 -0
- package/dist/token/refresh.d.ts.map +1 -0
- package/dist/token/refresh.js +47 -0
- package/dist/token/refresh.js.map +1 -0
- package/dist/types.d.ts +217 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OAuthProviderRuntime } from '../runtime.js';
|
|
2
|
+
import { type IssuedTokens } from '../store.js';
|
|
3
|
+
import type { OAuthProviderClient } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Authorization code grant (RFC 6749 4.1.3, RFC 7636 4.6). A code works once:
|
|
6
|
+
* when its own client presents a spent code again with the right
|
|
7
|
+
* redirect_uri and code_verifier, the whole grant is revoked, so tokens
|
|
8
|
+
* already issued from it stop working (RFC 6749 4.1.2, 10.5).
|
|
9
|
+
*/
|
|
10
|
+
export declare function exchangeAuthorizationCode(runtime: OAuthProviderRuntime, client: OAuthProviderClient, params: Map<string, string>): Promise<IssuedTokens>;
|
|
11
|
+
//# sourceMappingURL=code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/token/code.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAML,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMvD;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,OAAO,CAAC,YAAY,CAAC,CAoDvB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OAuthError, requireParam } from '../http.js';
|
|
2
|
+
import { verifyS256 } from '../pkce.js';
|
|
3
|
+
import { claimCode, findCode, findLiveGrant, revokeGrant, stageTokens } from '../store.js';
|
|
4
|
+
function invalidGrant(description) {
|
|
5
|
+
return new OAuthError('invalid_grant', description);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Authorization code grant (RFC 6749 4.1.3, RFC 7636 4.6). A code works once:
|
|
9
|
+
* when its own client presents a spent code again with the right
|
|
10
|
+
* redirect_uri and code_verifier, the whole grant is revoked, so tokens
|
|
11
|
+
* already issued from it stop working (RFC 6749 4.1.2, 10.5).
|
|
12
|
+
*/
|
|
13
|
+
export async function exchangeAuthorizationCode(runtime, client, params) {
|
|
14
|
+
const code = requireParam(params, 'code');
|
|
15
|
+
const verifier = requireParam(params, 'code_verifier');
|
|
16
|
+
const now = runtime.now();
|
|
17
|
+
const record = await findCode(runtime.store, code);
|
|
18
|
+
if (!record) {
|
|
19
|
+
throw invalidGrant('Authorization code is invalid');
|
|
20
|
+
}
|
|
21
|
+
// Bind the presenter to the code before anything else: only the client the
|
|
22
|
+
// code was issued to, holding the PKCE verifier, may trigger replay
|
|
23
|
+
// revocation. Anyone else holding a spent code gets invalid_grant and the
|
|
24
|
+
// grant stays untouched.
|
|
25
|
+
if (record.clientId !== client.clientId) {
|
|
26
|
+
throw invalidGrant('Authorization code was issued to another client');
|
|
27
|
+
}
|
|
28
|
+
if (params.get('redirect_uri') !== record.redirectUri) {
|
|
29
|
+
throw invalidGrant('redirect_uri does not match the authorization request');
|
|
30
|
+
}
|
|
31
|
+
if (!verifyS256(verifier, record.codeChallenge)) {
|
|
32
|
+
throw invalidGrant('code_verifier does not match the code_challenge');
|
|
33
|
+
}
|
|
34
|
+
if (record.consumedAt) {
|
|
35
|
+
await revokeGrant(runtime.store, record.grantId, 'code_replay', now);
|
|
36
|
+
throw invalidGrant('Authorization code has already been used');
|
|
37
|
+
}
|
|
38
|
+
if (record.expiresAt.getTime() <= now.getTime()) {
|
|
39
|
+
throw invalidGrant('Authorization code has expired');
|
|
40
|
+
}
|
|
41
|
+
const resource = params.get('resource');
|
|
42
|
+
if (resource !== undefined && resource !== record.resource) {
|
|
43
|
+
throw new OAuthError('invalid_target', 'resource does not match the authorization request');
|
|
44
|
+
}
|
|
45
|
+
const grant = await findLiveGrant(runtime.store, record.grantId);
|
|
46
|
+
if (!grant) {
|
|
47
|
+
throw invalidGrant('Authorization grant is no longer valid');
|
|
48
|
+
}
|
|
49
|
+
// The tokens are staged first; the conditional claim on the code commits
|
|
50
|
+
// them and is the single-use guarantee: a concurrent redemption that loses
|
|
51
|
+
// the race is a replay, and its staged tokens never become valid.
|
|
52
|
+
const { tokens, claimId } = await stageTokens(runtime.store, grant, grant.scopes, now, record.id);
|
|
53
|
+
if (!(await claimCode(runtime.store, record.id, now, claimId))) {
|
|
54
|
+
await revokeGrant(runtime.store, record.grantId, 'code_replay', now);
|
|
55
|
+
throw invalidGrant('Authorization code has already been used');
|
|
56
|
+
}
|
|
57
|
+
// A disconnect, revocation or user removal that completed before the claim
|
|
58
|
+
// committed wins: the code stays spent and its tokens are inert.
|
|
59
|
+
if (!(await findLiveGrant(runtime.store, record.grantId))) {
|
|
60
|
+
throw invalidGrant('Authorization grant is no longer valid');
|
|
61
|
+
}
|
|
62
|
+
return tokens;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot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AAC,CAAC;QACrE,MAAM,YAAY,CAAC,0CAA0C,CAAC,CAAC;IACjE,CAAC;IACD,2EAA2E;IAC3E,iEAAiE;IACjE,IAAI,CAAC,CAAC,MAAM,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAC1D,MAAM,YAAY,CAAC,wCAAwC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Route } from '@superfunctions/http';
|
|
2
|
+
import type { OAuthProviderRuntime } from '../runtime.js';
|
|
3
|
+
export declare const OAUTH_TOKEN_PATH = "/oauth/token";
|
|
4
|
+
export declare function createTokenRoute(runtime: OAuthProviderRuntime): Route;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/token/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAK1D,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,KAAK,CA8BrE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createAuthFnRouteMeta } from 'authfn/http/router';
|
|
2
|
+
import { authenticateClient, handleOAuth, OAuthError, oauthJson, readFormBody } from '../http.js';
|
|
3
|
+
import { exchangeAuthorizationCode } from './code.js';
|
|
4
|
+
import { refreshAccessToken } from './refresh.js';
|
|
5
|
+
export const OAUTH_TOKEN_PATH = '/oauth/token';
|
|
6
|
+
export function createTokenRoute(runtime) {
|
|
7
|
+
return {
|
|
8
|
+
method: 'POST',
|
|
9
|
+
path: OAUTH_TOKEN_PATH,
|
|
10
|
+
meta: createAuthFnRouteMeta('oauthToken', 'OAuth 2.1 token endpoint', { mode: 'none' }),
|
|
11
|
+
handler: (request) => handleOAuth(async () => {
|
|
12
|
+
const params = await readFormBody(request);
|
|
13
|
+
const client = await authenticateClient(runtime, request, params);
|
|
14
|
+
const grantType = params.get('grant_type');
|
|
15
|
+
let issued;
|
|
16
|
+
if (grantType === 'authorization_code') {
|
|
17
|
+
issued = await exchangeAuthorizationCode(runtime, client, params);
|
|
18
|
+
}
|
|
19
|
+
else if (grantType === 'refresh_token') {
|
|
20
|
+
issued = await refreshAccessToken(runtime, client, params);
|
|
21
|
+
}
|
|
22
|
+
else if (!grantType) {
|
|
23
|
+
throw new OAuthError('invalid_request', 'Parameter grant_type is required');
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new OAuthError('unsupported_grant_type', 'Only authorization_code and refresh_token are supported');
|
|
27
|
+
}
|
|
28
|
+
// RFC 6749 5.1: the response carries Cache-Control: no-store.
|
|
29
|
+
return oauthJson({
|
|
30
|
+
access_token: issued.accessToken,
|
|
31
|
+
token_type: 'Bearer',
|
|
32
|
+
expires_in: issued.accessTokenExpiresIn,
|
|
33
|
+
refresh_token: issued.refreshToken,
|
|
34
|
+
scope: issued.scopes.join(' ')
|
|
35
|
+
});
|
|
36
|
+
})
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/token/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlG,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,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EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;aAC/B,CAAC,CAAC;QACL,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OAuthProviderRuntime } from '../runtime.js';
|
|
2
|
+
import { type IssuedTokens } from '../store.js';
|
|
3
|
+
import type { OAuthProviderClient } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Refresh token grant (RFC 6749 6) with rotation: every use spends the
|
|
6
|
+
* refresh token and returns a new one. Presenting a spent refresh token is
|
|
7
|
+
* reuse, which revokes the whole grant (OAuth 2.1 4.3.1).
|
|
8
|
+
*/
|
|
9
|
+
export declare function refreshAccessToken(runtime: OAuthProviderRuntime, client: OAuthProviderClient, params: Map<string, string>): Promise<IssuedTokens>;
|
|
10
|
+
//# sourceMappingURL=refresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../src/token/refresh.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMvD;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,OAAO,CAAC,YAAY,CAAC,CAqCvB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { OAuthError, requireParam } from '../http.js';
|
|
2
|
+
import { activeTokenState, claimRefreshToken, findLiveGrant, findToken, revokeGrant, stageTokens } from '../store.js';
|
|
3
|
+
function invalidGrant(description) {
|
|
4
|
+
return new OAuthError('invalid_grant', description);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Refresh token grant (RFC 6749 6) with rotation: every use spends the
|
|
8
|
+
* refresh token and returns a new one. Presenting a spent refresh token is
|
|
9
|
+
* reuse, which revokes the whole grant (OAuth 2.1 4.3.1).
|
|
10
|
+
*/
|
|
11
|
+
export async function refreshAccessToken(runtime, client, params) {
|
|
12
|
+
const token = requireParam(params, 'refresh_token');
|
|
13
|
+
const now = runtime.now();
|
|
14
|
+
const record = await findToken(runtime.store, token);
|
|
15
|
+
if (record?.kind !== 'refresh' || record.clientId !== client.clientId) {
|
|
16
|
+
throw invalidGrant('Refresh token is invalid');
|
|
17
|
+
}
|
|
18
|
+
if (record.rotatedAt) {
|
|
19
|
+
await revokeGrant(runtime.store, record.grantId, 'refresh_reuse', now);
|
|
20
|
+
throw invalidGrant('Refresh token has already been used');
|
|
21
|
+
}
|
|
22
|
+
const active = await activeTokenState(runtime.store, record, 'refresh', now);
|
|
23
|
+
if (!active) {
|
|
24
|
+
throw invalidGrant('Refresh token is expired or revoked');
|
|
25
|
+
}
|
|
26
|
+
const resource = params.get('resource');
|
|
27
|
+
if (resource !== undefined && resource !== record.resource) {
|
|
28
|
+
throw new OAuthError('invalid_target', 'resource does not match the grant');
|
|
29
|
+
}
|
|
30
|
+
const scope = params.get('scope');
|
|
31
|
+
const scopes = scope === undefined ? active.grant.scopes : [...new Set(scope.split(' '))];
|
|
32
|
+
if (scopes.some((entry) => !active.grant.scopes.includes(entry))) {
|
|
33
|
+
throw new OAuthError('invalid_scope', 'scope must not exceed the original grant');
|
|
34
|
+
}
|
|
35
|
+
// Staged tokens become valid only when this claim on the refresh token commits.
|
|
36
|
+
const { tokens, claimId } = await stageTokens(runtime.store, active.grant, scopes, now, record.id);
|
|
37
|
+
if (!(await claimRefreshToken(runtime.store, record.id, now, claimId))) {
|
|
38
|
+
await revokeGrant(runtime.store, record.grantId, 'refresh_reuse', now);
|
|
39
|
+
throw invalidGrant('Refresh token has already been used');
|
|
40
|
+
}
|
|
41
|
+
// As for a code: a grant or user that ended before the claim committed wins.
|
|
42
|
+
if (!(await findLiveGrant(runtime.store, record.grantId))) {
|
|
43
|
+
throw invalidGrant('Refresh token is expired or revoked');
|
|
44
|
+
}
|
|
45
|
+
return tokens;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.js","sourceRoot":"","sources":["../../src/token/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,WAAW,EACX,WAAW,EAEZ,MAAM,aAAa,CAAC;AAGrB,SAAS,YAAY,CAAC,WAAmB;IACvC,OAAO,IAAI,UAAU,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAA6B,EAC7B,MAA2B,EAC3B,MAA2B;IAE3B,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACrD,IAAI,MAAM,EAAE,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC;QACtE,MAAM,YAAY,CAAC,0BAA0B,CAAC,CAAC;IACjD,CAAC;IACD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,MAAM,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC;QACvE,MAAM,YAAY,CAAC,qCAAqC,CAAC,CAAC;IAC5D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E,CAAC;QACvE,MAAM,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC;QACvE,MAAM,YAAY,CAAC,qCAAqC,CAAC,CAAC;IAC5D,CAAC;IACD,6EAA6E;IAC7E,IAAI,CAAC,CAAC,MAAM,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAC1D,MAAM,YAAY,CAAC,qCAAqC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { AuthFnBundledPluginConfig } from 'authfn/plugin-types';
|
|
2
|
+
/** Access tokens live one hour. */
|
|
3
|
+
export declare const OAUTH_ACCESS_TOKEN_TTL_SECONDS: number;
|
|
4
|
+
/** Refresh tokens live 30 days; every use rotates them to a fresh 30-day token. */
|
|
5
|
+
export declare const OAUTH_REFRESH_TOKEN_TTL_SECONDS: number;
|
|
6
|
+
/** Authorization codes are single-use and live one minute. */
|
|
7
|
+
export declare const OAUTH_AUTHORIZATION_CODE_TTL_SECONDS = 60;
|
|
8
|
+
export type OAuthClientAuthMethod = 'none' | 'client_secret_basic' | 'client_secret_post';
|
|
9
|
+
/** A client registered with the authorization server ahead of time. */
|
|
10
|
+
export interface OAuthProviderClient {
|
|
11
|
+
/** The `client_id` the client sends. */
|
|
12
|
+
clientId: string;
|
|
13
|
+
/** Shown on the consent page. */
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* Redirect URIs compared exactly, except that the port of an
|
|
17
|
+
* `http://127.0.0.1` or `http://[::1]` loopback URI may vary (RFC 8252 7.3).
|
|
18
|
+
*/
|
|
19
|
+
redirectUris: string[];
|
|
20
|
+
/**
|
|
21
|
+
* A trusted (first-party) client still needs the user's consent once per
|
|
22
|
+
* resource; later authorizations within consented scopes skip the page. An
|
|
23
|
+
* untrusted client shows the consent page on every authorization.
|
|
24
|
+
*/
|
|
25
|
+
trusted?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Required for `client_secret_basic` and `client_secret_post`. Omit for a
|
|
28
|
+
* public client (`none`), which authenticates only with its `client_id` and
|
|
29
|
+
* PKCE.
|
|
30
|
+
*/
|
|
31
|
+
clientSecret?: string;
|
|
32
|
+
/** Defaults to `none` without a secret and `client_secret_basic` with one. */
|
|
33
|
+
tokenEndpointAuthMethod?: OAuthClientAuthMethod;
|
|
34
|
+
}
|
|
35
|
+
/** A protected resource that tokens can be issued for (RFC 8707). */
|
|
36
|
+
export interface OAuthProviderResource {
|
|
37
|
+
/**
|
|
38
|
+
* The resource indicator: an absolute URI without a fragment, compared
|
|
39
|
+
* exactly. Tokens issued for it carry it as their audience.
|
|
40
|
+
*/
|
|
41
|
+
resource: string;
|
|
42
|
+
/**
|
|
43
|
+
* Scopes a client may request for this resource, each a registered
|
|
44
|
+
* `<owner>:<action>`, `<owner>:*` or `*` from the AuthFn scope registry.
|
|
45
|
+
* A request without `scope` asks for all of them.
|
|
46
|
+
*/
|
|
47
|
+
scopes: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Secret the resource server sends as `Authorization: Bearer <secret>` to
|
|
50
|
+
* the introspection endpoint. Introspection reports only tokens issued for
|
|
51
|
+
* this resource as active. Omit to disable introspection for the resource.
|
|
52
|
+
*/
|
|
53
|
+
introspectionSecret?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface OAuthProviderUser {
|
|
56
|
+
id: string;
|
|
57
|
+
primaryEmail?: string;
|
|
58
|
+
}
|
|
59
|
+
/** The validated authorization request the consent page posts back. */
|
|
60
|
+
export interface OAuthAuthorizationRequestParams {
|
|
61
|
+
response_type: 'code';
|
|
62
|
+
client_id: string;
|
|
63
|
+
redirect_uri: string;
|
|
64
|
+
scope: string;
|
|
65
|
+
state?: string;
|
|
66
|
+
code_challenge: string;
|
|
67
|
+
code_challenge_method: 'S256';
|
|
68
|
+
resource: string;
|
|
69
|
+
}
|
|
70
|
+
export interface OAuthLoginRequiredInput {
|
|
71
|
+
request: Request;
|
|
72
|
+
/** The authorization URL to return to after sign-in. */
|
|
73
|
+
returnTo: string;
|
|
74
|
+
}
|
|
75
|
+
export interface OAuthConsentInput {
|
|
76
|
+
request: Request;
|
|
77
|
+
user: OAuthProviderUser;
|
|
78
|
+
client: {
|
|
79
|
+
clientId: string;
|
|
80
|
+
name: string;
|
|
81
|
+
trusted: boolean;
|
|
82
|
+
};
|
|
83
|
+
resource: string;
|
|
84
|
+
scopes: string[];
|
|
85
|
+
/**
|
|
86
|
+
* POST these parameters plus `decision: 'approve' | 'deny'` as JSON to
|
|
87
|
+
* `decisionUrl` with the session cookie and the `x-authfn-csrf` header. The
|
|
88
|
+
* response's `data.redirectTo` is where the browser goes next.
|
|
89
|
+
*/
|
|
90
|
+
params: OAuthAuthorizationRequestParams;
|
|
91
|
+
decisionUrl: string;
|
|
92
|
+
}
|
|
93
|
+
export interface OAuthProviderPluginConfig extends AuthFnBundledPluginConfig {
|
|
94
|
+
}
|
|
95
|
+
/** Registrations (or metadata document fetches) admitted per window. */
|
|
96
|
+
export interface OAuthClientRegistrationRateLimit {
|
|
97
|
+
/** Per client IP, when the IP is known. Defaults to 20. */
|
|
98
|
+
perIp?: number;
|
|
99
|
+
/** Across all callers. Defaults to 200. */
|
|
100
|
+
global?: number;
|
|
101
|
+
/** Fixed window length. Defaults to 3600 (one hour). */
|
|
102
|
+
windowSeconds?: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Self-registration for public clients such as MCP hosts. Every client
|
|
106
|
+
* registered this way is public (`token_endpoint_auth_method: none`), never
|
|
107
|
+
* trusted, and may only use `https` or `http://127.0.0.1[:port]` redirect URIs.
|
|
108
|
+
*/
|
|
109
|
+
export interface OAuthClientRegistrationConfig {
|
|
110
|
+
/** Accept RFC 7591 dynamic client registration at `{basePath}/oauth/register`. */
|
|
111
|
+
dynamic?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Accept an `https` URL as `client_id` that serves the client's metadata
|
|
114
|
+
* (a Client ID Metadata Document). It is fetched with a 5-second timeout
|
|
115
|
+
* and a 64 KB cap.
|
|
116
|
+
*/
|
|
117
|
+
metadataDocuments?: boolean;
|
|
118
|
+
rateLimit?: OAuthClientRegistrationRateLimit;
|
|
119
|
+
/**
|
|
120
|
+
* The caller's IP for the per-IP limit. Defaults to AuthFn's
|
|
121
|
+
* `rateLimit.resolveClientIp`; without either only the global limit applies.
|
|
122
|
+
* Read only an address your ingress sets, never a header callers can send.
|
|
123
|
+
*/
|
|
124
|
+
resolveClientIp?: (request: Request) => string | null | undefined | Promise<string | null | undefined>;
|
|
125
|
+
/**
|
|
126
|
+
* Fetches metadata documents; required with `metadataDocuments`. It must
|
|
127
|
+
* not reach private or internal addresses: hosts that are IP literals,
|
|
128
|
+
* `localhost` or single-label names are refused before any fetch, but a
|
|
129
|
+
* public name can still resolve to a private address.
|
|
130
|
+
*/
|
|
131
|
+
fetch?: typeof fetch;
|
|
132
|
+
}
|
|
133
|
+
export interface OAuthProviderPluginRuntimeConfig {
|
|
134
|
+
clients: OAuthProviderClient[];
|
|
135
|
+
/** Client self-registration; off unless configured. */
|
|
136
|
+
registration?: OAuthClientRegistrationConfig;
|
|
137
|
+
resources: OAuthProviderResource[];
|
|
138
|
+
/** Renders the sign-in step when the authorization request has no session. */
|
|
139
|
+
loginRequired: (input: OAuthLoginRequiredInput) => Response | Promise<Response>;
|
|
140
|
+
/** Renders the consent page. */
|
|
141
|
+
consent: (input: OAuthConsentInput) => Response | Promise<Response>;
|
|
142
|
+
/** Clock for token, code and consent timestamps; primarily useful for tests. */
|
|
143
|
+
now?: () => Date;
|
|
144
|
+
}
|
|
145
|
+
export interface OAuthGrantRecord {
|
|
146
|
+
id: string;
|
|
147
|
+
clientId: string;
|
|
148
|
+
userId: string;
|
|
149
|
+
resource: string;
|
|
150
|
+
scopes: string[];
|
|
151
|
+
revokedAt?: Date | null;
|
|
152
|
+
revokedReason?: string | null;
|
|
153
|
+
createdAt: Date;
|
|
154
|
+
updatedAt: Date;
|
|
155
|
+
}
|
|
156
|
+
export interface OAuthAuthorizationCodeRecord {
|
|
157
|
+
id: string;
|
|
158
|
+
codeHash: string;
|
|
159
|
+
grantId: string;
|
|
160
|
+
clientId: string;
|
|
161
|
+
userId: string;
|
|
162
|
+
resource: string;
|
|
163
|
+
scopes: string[];
|
|
164
|
+
redirectUri: string;
|
|
165
|
+
codeChallenge: string;
|
|
166
|
+
expiresAt: Date;
|
|
167
|
+
consumedAt?: Date | null;
|
|
168
|
+
createdAt: Date;
|
|
169
|
+
}
|
|
170
|
+
export type OAuthTokenKind = 'access' | 'refresh';
|
|
171
|
+
export interface OAuthTokenRecord {
|
|
172
|
+
id: string;
|
|
173
|
+
kind: OAuthTokenKind;
|
|
174
|
+
tokenHash: string;
|
|
175
|
+
grantId: string;
|
|
176
|
+
clientId: string;
|
|
177
|
+
userId: string;
|
|
178
|
+
resource: string;
|
|
179
|
+
scopes: string[];
|
|
180
|
+
expiresAt: Date;
|
|
181
|
+
/** A refresh token is rotated (spent) once it has been exchanged. */
|
|
182
|
+
rotatedAt?: Date | null;
|
|
183
|
+
revokedAt?: Date | null;
|
|
184
|
+
/** The code or refresh token exchanged for this token. */
|
|
185
|
+
sourceId: string;
|
|
186
|
+
/** The claim on `sourceId` that commits this token; valid only once stored there. */
|
|
187
|
+
issuingClaimId: string;
|
|
188
|
+
createdAt: Date;
|
|
189
|
+
}
|
|
190
|
+
export interface OAuthConsentRecord {
|
|
191
|
+
id: string;
|
|
192
|
+
userId: string;
|
|
193
|
+
clientId: string;
|
|
194
|
+
resource: string;
|
|
195
|
+
scopes: string[];
|
|
196
|
+
/** The disconnect generation of the user, client and resource at this approval. */
|
|
197
|
+
generation: string;
|
|
198
|
+
createdAt: Date;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* An active access token as `verifyOAuthAccessToken` reports it. The
|
|
202
|
+
* introspection endpoint answers with RFC 7662 fields instead.
|
|
203
|
+
*/
|
|
204
|
+
export interface OAuthAccessTokenInfo {
|
|
205
|
+
tokenId: string;
|
|
206
|
+
grantId: string;
|
|
207
|
+
clientId: string;
|
|
208
|
+
/** The user the token acts for. */
|
|
209
|
+
userId: string;
|
|
210
|
+
/** The resource (audience) the token is bound to. */
|
|
211
|
+
resource: string;
|
|
212
|
+
/** Granted scopes; pass the object to `requireScopes` from `authfn`. */
|
|
213
|
+
scopes: string[];
|
|
214
|
+
issuedAt: Date;
|
|
215
|
+
expiresAt: Date;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAErE,mCAAmC;AACnC,eAAO,MAAM,8BAA8B,QAAU,CAAC;AACtD,mFAAmF;AACnF,eAAO,MAAM,+BAA+B,QAAoB,CAAC;AACjE,8DAA8D;AAC9D,eAAO,MAAM,oCAAoC,KAAK,CAAC;AAEvD,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,qBAAqB,GAAG,oBAAoB,CAAC;AAE1F,uEAAuE;AACvE,MAAM,WAAW,mBAAmB;IAClC,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,uBAAuB,CAAC,EAAE,qBAAqB,CAAC;CACjD;AAED,qEAAqE;AACrE,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,E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,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,IAAI,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;CACjB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Access tokens live one hour. */
|
|
2
|
+
export const OAUTH_ACCESS_TOKEN_TTL_SECONDS = 60 * 60;
|
|
3
|
+
/** Refresh tokens live 30 days; every use rotates them to a fresh 30-day token. */
|
|
4
|
+
export const OAUTH_REFRESH_TOKEN_TTL_SECONDS = 30 * 24 * 60 * 60;
|
|
5
|
+
/** Authorization codes are single-use and live one minute. */
|
|
6
|
+
export const OAUTH_AUTHORIZATION_CODE_TTL_SECONDS = 60;
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,mCAAmC;AACnC,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,GAAG,EAAE,CAAC;AACtD,mFAAmF;AACnF,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACjE,8DAA8D;AAC9D,MAAM,CAAC,MAAM,oCAAoC,GAAG,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +1,43 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@authfn/oauth-provider",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "OAuth 2.1 authorization server plugin for AuthFn",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/21nCo/superfunctions.git",
|
|
8
|
+
"directory": "authfn/oauth-provider"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"clean": "rm -rf dist"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"authfn": "0.6.0",
|
|
31
|
+
"@superfunctions/http": "0.2.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@superfunctions/db": "0.2.0",
|
|
35
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
36
|
+
"@types/node": "^22.0.0",
|
|
37
|
+
"better-sqlite3": "^12.5.0",
|
|
38
|
+
"kysely": "^0.28.0",
|
|
39
|
+
"typescript": "^5.6.0",
|
|
40
|
+
"vitest": "^3.2.4"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "44a4db16e3f7da89d47e7466e33a0c2e674b63c7"
|
|
43
|
+
}
|