@atproto/oauth-provider 0.9.2 → 0.9.3
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/CHANGELOG.md +16 -0
- package/dist/client/client.js +6 -6
- package/dist/client/client.js.map +1 -1
- package/dist/device/device-manager.js +1 -1
- package/dist/device/device-manager.js.map +1 -1
- package/dist/dpop/dpop-manager.js +15 -15
- package/dist/dpop/dpop-manager.js.map +1 -1
- package/dist/errors/access-denied-error.d.ts +4 -7
- package/dist/errors/access-denied-error.d.ts.map +1 -1
- package/dist/errors/access-denied-error.js +4 -13
- package/dist/errors/access-denied-error.js.map +1 -1
- package/dist/errors/account-selection-required-error.d.ts +2 -2
- package/dist/errors/account-selection-required-error.d.ts.map +1 -1
- package/dist/errors/account-selection-required-error.js +2 -2
- package/dist/errors/account-selection-required-error.js.map +1 -1
- package/dist/errors/authorization-error.d.ts +10 -0
- package/dist/errors/authorization-error.d.ts.map +1 -0
- package/dist/errors/authorization-error.js +31 -0
- package/dist/errors/authorization-error.js.map +1 -0
- package/dist/errors/consent-required-error.d.ts +2 -2
- package/dist/errors/consent-required-error.d.ts.map +1 -1
- package/dist/errors/consent-required-error.js +2 -2
- package/dist/errors/consent-required-error.js.map +1 -1
- package/dist/errors/error-parser.d.ts.map +1 -1
- package/dist/errors/error-parser.js +2 -1
- package/dist/errors/error-parser.js.map +1 -1
- package/dist/errors/invalid-authorization-details-error.d.ts +2 -2
- package/dist/errors/invalid-authorization-details-error.d.ts.map +1 -1
- package/dist/errors/invalid-authorization-details-error.js +2 -2
- package/dist/errors/invalid-authorization-details-error.js.map +1 -1
- package/dist/errors/invalid-scope-error.d.ts +2 -2
- package/dist/errors/invalid-scope-error.d.ts.map +1 -1
- package/dist/errors/invalid-scope-error.js +2 -2
- package/dist/errors/invalid-scope-error.js.map +1 -1
- package/dist/errors/login-required-error.d.ts +2 -3
- package/dist/errors/login-required-error.d.ts.map +1 -1
- package/dist/errors/login-required-error.js +2 -7
- package/dist/errors/login-required-error.js.map +1 -1
- package/dist/lib/http/response.d.ts +4 -4
- package/dist/lib/http/response.d.ts.map +1 -1
- package/dist/lib/http/response.js +8 -7
- package/dist/lib/http/response.js.map +1 -1
- package/dist/lib/http/stream.d.ts +1 -0
- package/dist/lib/http/stream.d.ts.map +1 -1
- package/dist/lib/http/stream.js +6 -0
- package/dist/lib/http/stream.js.map +1 -1
- package/dist/lib/util/error.d.ts +2 -0
- package/dist/lib/util/error.d.ts.map +1 -0
- package/dist/lib/util/error.js +11 -0
- package/dist/lib/util/error.js.map +1 -0
- package/dist/lib/util/zod-error.d.ts +3 -1
- package/dist/lib/util/zod-error.d.ts.map +1 -1
- package/dist/lib/util/zod-error.js +20 -10
- package/dist/lib/util/zod-error.js.map +1 -1
- package/dist/oauth-errors.d.ts +1 -1
- package/dist/oauth-errors.d.ts.map +1 -1
- package/dist/oauth-errors.js +1 -1
- package/dist/oauth-errors.js.map +1 -1
- package/dist/oauth-hooks.d.ts +3 -2
- package/dist/oauth-hooks.d.ts.map +1 -1
- package/dist/oauth-hooks.js +4 -3
- package/dist/oauth-hooks.js.map +1 -1
- package/dist/oauth-provider.d.ts.map +1 -1
- package/dist/oauth-provider.js +18 -21
- package/dist/oauth-provider.js.map +1 -1
- package/dist/request/request-manager.d.ts.map +1 -1
- package/dist/request/request-manager.js +12 -12
- package/dist/request/request-manager.js.map +1 -1
- package/dist/router/create-api-middleware.d.ts.map +1 -1
- package/dist/router/create-api-middleware.js +60 -45
- package/dist/router/create-api-middleware.js.map +1 -1
- package/dist/router/create-authorization-page-middleware.d.ts.map +1 -1
- package/dist/router/create-authorization-page-middleware.js +19 -17
- package/dist/router/create-authorization-page-middleware.js.map +1 -1
- package/dist/router/create-oauth-middleware.d.ts.map +1 -1
- package/dist/router/create-oauth-middleware.js +21 -18
- package/dist/router/create-oauth-middleware.js.map +1 -1
- package/dist/router/send-redirect.js +2 -2
- package/dist/router/send-redirect.js.map +1 -1
- package/dist/token/token-manager.js +1 -1
- package/dist/types/authorization-response-error.d.ts +5 -0
- package/dist/types/authorization-response-error.d.ts.map +1 -0
- package/dist/types/authorization-response-error.js +21 -0
- package/dist/types/authorization-response-error.js.map +1 -0
- package/dist/types/par-response-error.d.ts +5 -0
- package/dist/types/par-response-error.d.ts.map +1 -0
- package/dist/types/par-response-error.js +22 -0
- package/dist/types/par-response-error.js.map +1 -0
- package/package.json +5 -5
- package/src/client/client.ts +6 -6
- package/src/device/device-manager.ts +1 -1
- package/src/dpop/dpop-manager.ts +16 -16
- package/src/errors/access-denied-error.ts +6 -33
- package/src/errors/account-selection-required-error.ts +2 -2
- package/src/errors/authorization-error.ts +45 -0
- package/src/errors/consent-required-error.ts +2 -2
- package/src/errors/error-parser.ts +2 -1
- package/src/errors/invalid-authorization-details-error.ts +2 -2
- package/src/errors/invalid-scope-error.ts +2 -2
- package/src/errors/login-required-error.ts +2 -12
- package/src/lib/http/response.ts +14 -13
- package/src/lib/http/stream.ts +6 -0
- package/src/lib/util/error.ts +7 -0
- package/src/lib/util/zod-error.ts +23 -11
- package/src/oauth-errors.ts +1 -1
- package/src/oauth-hooks.ts +3 -2
- package/src/oauth-provider.ts +18 -28
- package/src/request/request-manager.ts +12 -18
- package/src/router/create-api-middleware.ts +84 -62
- package/src/router/create-authorization-page-middleware.ts +19 -21
- package/src/router/create-oauth-middleware.ts +28 -27
- package/src/router/send-redirect.ts +2 -2
- package/src/token/token-manager.ts +1 -1
- package/src/types/authorization-response-error.ts +27 -0
- package/src/types/par-response-error.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/errors/invalid-parameters-error.d.ts +0 -6
- package/dist/errors/invalid-parameters-error.d.ts.map +0 -1
- package/dist/errors/invalid-parameters-error.js +0 -11
- package/dist/errors/invalid-parameters-error.js.map +0 -1
- package/src/errors/invalid-parameters-error.ts +0 -12
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-authorization-page-middleware.d.ts","sourceRoot":"","sources":["../../src/router/create-authorization-page-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAOhE,OAAO,EACL,UAAU,EAQX,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAMzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAQhE,wBAAgB,iCAAiC,CAC/C,GAAG,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,EAChC,GAAG,SAAS,eAAe,GAAG,eAAe,EAC7C,GAAG,SAAS,cAAc,GAAG,cAAc,EAE3C,MAAM,EAAE,aAAa,EACrB,EAAE,OAAO,EAAE,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,GACvC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,
|
1
|
+
{"version":3,"file":"create-authorization-page-middleware.d.ts","sourceRoot":"","sources":["../../src/router/create-authorization-page-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAOhE,OAAO,EACL,UAAU,EAQX,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAMzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAQhE,wBAAgB,iCAAiC,CAC/C,GAAG,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,EAChC,GAAG,SAAS,eAAe,GAAG,eAAe,EAC7C,GAAG,SAAS,cAAc,GAAG,cAAc,EAE3C,MAAM,EAAE,aAAa,EACrB,EAAE,OAAO,EAAE,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,GACvC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAoH3B"}
|
@@ -2,10 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.createAuthorizationPageMiddleware = createAuthorizationPageMiddleware;
|
4
4
|
const oauth_types_1 = require("@atproto/oauth-types");
|
5
|
-
const
|
5
|
+
const authorization_error_js_1 = require("../errors/authorization-error.js");
|
6
6
|
const invalid_request_error_js_1 = require("../errors/invalid-request-error.js");
|
7
7
|
const index_js_1 = require("../lib/http/index.js");
|
8
|
-
const
|
8
|
+
const error_js_1 = require("../lib/util/error.js");
|
9
9
|
const request_uri_js_1 = require("../request/request-uri.js");
|
10
10
|
const send_authorization_page_js_1 = require("./assets/send-authorization-page.js");
|
11
11
|
const send_error_page_js_1 = require("./assets/send-error-page.js");
|
@@ -27,13 +27,13 @@ function createAuthorizationPageMiddleware(server, { onError }) {
|
|
27
27
|
const query = Object.fromEntries(this.url.searchParams);
|
28
28
|
const clientCredentials = await oauth_types_1.oauthClientCredentialsSchema
|
29
29
|
.parseAsync(query, { path: ['query'] })
|
30
|
-
.catch(throwInvalidRequest);
|
30
|
+
.catch((err) => throwInvalidRequest(err, 'Invalid client credentials'));
|
31
31
|
if ('client_secret' in clientCredentials) {
|
32
32
|
throw new invalid_request_error_js_1.InvalidRequestError('Client secret must not be provided');
|
33
33
|
}
|
34
34
|
const authorizationRequest = await oauth_types_1.oauthAuthorizationRequestQuerySchema
|
35
35
|
.parseAsync(query, { path: ['query'] })
|
36
|
-
.catch(throwInvalidRequest);
|
36
|
+
.catch((err) => throwInvalidRequest(err, 'Invalid request parameters'));
|
37
37
|
const deviceInfo = await server.deviceManager.load(req, res);
|
38
38
|
try {
|
39
39
|
const result = await server.authorize(clientCredentials, authorizationRequest, deviceInfo.deviceId, deviceInfo.deviceMetadata);
|
@@ -45,18 +45,20 @@ function createAuthorizationPageMiddleware(server, { onError }) {
|
|
45
45
|
}
|
46
46
|
}
|
47
47
|
catch (err) {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
48
|
+
onError?.(req, res, err, 'Authorization request denied');
|
49
|
+
if (err instanceof authorization_error_js_1.AuthorizationError) {
|
50
|
+
try {
|
51
|
+
return sendAuthorizeRedirect(res, {
|
52
|
+
issuer: server.issuer,
|
53
|
+
parameters: err.parameters,
|
54
|
+
redirect: err.toJSON(),
|
55
|
+
});
|
56
|
+
}
|
57
|
+
catch {
|
58
|
+
// If we fail to send the redirect, we fall back to sending an error
|
59
|
+
}
|
58
60
|
}
|
59
|
-
|
61
|
+
return sendErrorPage(req, res, err);
|
60
62
|
}
|
61
63
|
}));
|
62
64
|
// This is a private endpoint that will be called by the user after the
|
@@ -92,8 +94,8 @@ function createAuthorizationPageMiddleware(server, { onError }) {
|
|
92
94
|
};
|
93
95
|
}
|
94
96
|
}
|
95
|
-
function throwInvalidRequest(err) {
|
96
|
-
throw new invalid_request_error_js_1.InvalidRequestError((0,
|
97
|
+
function throwInvalidRequest(err, prefix) {
|
98
|
+
throw new invalid_request_error_js_1.InvalidRequestError((0, error_js_1.formatError)(err, prefix), err);
|
97
99
|
}
|
98
100
|
function sendAuthorizeRedirect(res, { issuer, parameters, redirect }) {
|
99
101
|
const redirectUri = (0, send_redirect_js_1.buildRedirectUri)(parameters);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-authorization-page-middleware.js","sourceRoot":"","sources":["../../src/router/create-authorization-page-middleware.ts"],"names":[],"mappings":";;AAiCA,
|
1
|
+
{"version":3,"file":"create-authorization-page-middleware.js","sourceRoot":"","sources":["../../src/router/create-authorization-page-middleware.ts"],"names":[],"mappings":";;AAiCA,8EA2HC;AA3JD,sDAG6B;AAC7B,6EAAqE;AACrE,iFAAwE;AACxE,mDAS6B;AAC7B,mDAAkD;AAGlD,8DAA4D;AAE5D,oFAA8E;AAC9E,oEAAkE;AAClE,yEAA6D;AAE7D,yDAK2B;AAE3B,SAAgB,iCAAiC,CAK/C,MAAqB,EACrB,EAAE,OAAO,EAA+B;IAExC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EAAE,GAAG,CAAC,CAAA;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAY,EAAE,MAAc;IACvD,MAAM,IAAI,8CAAmB,CAAC,IAAA,sBAAW,EAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAA;AAC9D,CAAC;AAED,SAAS,qBAAqB,CAC5B,GAAmB,EACnB,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAA+B;IAE7D,MAAM,WAAW,GAAG,IAAA,mCAAgB,EAAC,UAAU,CAAC,CAAA;IAChD,MAAM,IAAI,GAAG,IAAA,oCAAiB,EAAC,UAAU,CAAC,CAAA;IAC1C,MAAM,MAAM,GAAG,IAAA,sCAAmB,EAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;IAChE,OAAO,IAAA,+BAAY,EAAC,GAAG,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAA;AACzD,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-oauth-middleware.d.ts","sourceRoot":"","sources":["../../src/router/create-oauth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAYhE,OAAO,EACL,UAAU,EAOX,MAAM,sBAAsB,CAAA;
|
1
|
+
{"version":3,"file":"create-oauth-middleware.d.ts","sourceRoot":"","sources":["../../src/router/create-oauth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAYhE,OAAO,EACL,UAAU,EAOX,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAqChE,wBAAgB,qBAAqB,CACnC,GAAG,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,EAChC,GAAG,SAAS,eAAe,GAAG,eAAe,EAC7C,GAAG,SAAS,cAAc,GAAG,cAAc,EAE3C,MAAM,EAAE,aAAa,EACrB,EAAE,OAAO,EAAE,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,GACvC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAgL3B"}
|
@@ -8,7 +8,8 @@ const invalid_grant_error_js_1 = require("../errors/invalid-grant-error.js");
|
|
8
8
|
const invalid_request_error_js_1 = require("../errors/invalid-request-error.js");
|
9
9
|
const www_authenticate_error_js_1 = require("../errors/www-authenticate-error.js");
|
10
10
|
const index_js_1 = require("../lib/http/index.js");
|
11
|
-
const
|
11
|
+
const error_js_1 = require("../lib/util/error.js");
|
12
|
+
const oauth_errors_js_1 = require("../oauth-errors.js");
|
12
13
|
// CORS preflight
|
13
14
|
const corsHeaders = function (req, res, next) {
|
14
15
|
res.setHeader('Access-Control-Max-Age', '86400'); // 1 day
|
@@ -52,10 +53,10 @@ function createOAuthMiddleware(server, { onError }) {
|
|
52
53
|
// https://datatracker.ietf.org/doc/html/rfc6749#autoid-56
|
53
54
|
const credentials = await oauth_types_1.oauthClientCredentialsSchema
|
54
55
|
.parseAsync(payload, { path: ['body'] })
|
55
|
-
.catch(throwInvalidClient);
|
56
|
+
.catch((err) => throwInvalidClient(err, 'Client credentials missing'));
|
56
57
|
const authorizationRequest = await oauth_types_1.oauthAuthorizationRequestParSchema
|
57
58
|
.parseAsync(payload, { path: ['body'] })
|
58
|
-
.catch(throwInvalidRequest);
|
59
|
+
.catch((err) => throwInvalidRequest(err, 'Invalid authorization request'));
|
59
60
|
const dpopProof = await server.checkDpopProof(req.method, this.url, req.headers);
|
60
61
|
return server.pushedAuthorizationRequest(credentials, authorizationRequest, dpopProof);
|
61
62
|
}, 201));
|
@@ -71,10 +72,10 @@ function createOAuthMiddleware(server, { onError }) {
|
|
71
72
|
const clientMetadata = await server.deviceManager.getRequestMetadata(req);
|
72
73
|
const clientCredentials = await oauth_types_1.oauthClientCredentialsSchema
|
73
74
|
.parseAsync(payload, { path: ['body'] })
|
74
|
-
.catch(throwInvalidGrant);
|
75
|
+
.catch((err) => throwInvalidGrant(err, 'Client credentials missing'));
|
75
76
|
const tokenRequest = await oauth_types_1.oauthTokenRequestSchema
|
76
77
|
.parseAsync(payload, { path: ['body'] })
|
77
|
-
.catch(throwInvalidGrant);
|
78
|
+
.catch((err) => throwInvalidGrant(err, 'Invalid request payload'));
|
78
79
|
const dpopProof = await server.checkDpopProof(req.method, this.url, req.headers);
|
79
80
|
return server.token(clientCredentials, clientMetadata, tokenRequest, dpopProof);
|
80
81
|
}));
|
@@ -83,10 +84,10 @@ function createOAuthMiddleware(server, { onError }) {
|
|
83
84
|
const payload = await (0, index_js_1.parseHttpRequest)(req, ['json', 'urlencoded']);
|
84
85
|
const credentials = await oauth_types_1.oauthClientCredentialsSchema
|
85
86
|
.parseAsync(payload, { path: ['body'] })
|
86
|
-
.catch(throwInvalidRequest);
|
87
|
+
.catch((err) => throwInvalidRequest(err, 'Client credentials missing'));
|
87
88
|
const tokenIdentification = await oauth_types_1.oauthTokenIdentificationSchema
|
88
89
|
.parseAsync(payload, { path: ['body'] })
|
89
|
-
.catch(throwInvalidRequest);
|
90
|
+
.catch((err) => throwInvalidRequest(err, 'Invalid request payload'));
|
90
91
|
const dpopProof = await server.checkDpopProof(req.method, this.url, req.headers);
|
91
92
|
try {
|
92
93
|
await server.revoke(credentials, tokenIdentification, dpopProof);
|
@@ -116,30 +117,32 @@ function createOAuthMiddleware(server, { onError }) {
|
|
116
117
|
res.setHeader(name, dpopNonce);
|
117
118
|
res.appendHeader('Access-Control-Expose-Headers', name);
|
118
119
|
}
|
119
|
-
const
|
120
|
-
return {
|
120
|
+
const json = await buildOAuthResponse.call(this, req, res);
|
121
|
+
return { json, status };
|
121
122
|
}
|
122
123
|
catch (err) {
|
123
|
-
onError?.(req, res, err,
|
124
|
+
onError?.(req, res, err, err instanceof oauth_errors_js_1.OAuthError
|
125
|
+
? `OAuth "${err.error}" error`
|
126
|
+
: 'Unexpected error');
|
124
127
|
if (!res.headersSent && err instanceof www_authenticate_error_js_1.WWWAuthenticateError) {
|
125
128
|
const name = 'WWW-Authenticate';
|
126
129
|
res.setHeader(name, err.wwwAuthenticateHeader);
|
127
130
|
res.appendHeader('Access-Control-Expose-Headers', name);
|
128
131
|
}
|
129
132
|
const status = (0, error_parser_js_1.buildErrorStatus)(err);
|
130
|
-
const
|
131
|
-
return {
|
133
|
+
const json = (0, error_parser_js_1.buildErrorPayload)(err);
|
134
|
+
return { json, status };
|
132
135
|
}
|
133
136
|
});
|
134
137
|
}
|
135
138
|
}
|
136
|
-
function throwInvalidGrant(err) {
|
137
|
-
throw new invalid_grant_error_js_1.InvalidGrantError((0,
|
139
|
+
function throwInvalidGrant(err, prefix) {
|
140
|
+
throw new invalid_grant_error_js_1.InvalidGrantError((0, error_js_1.formatError)(err, prefix), err);
|
138
141
|
}
|
139
|
-
function throwInvalidClient(err) {
|
140
|
-
throw new invalid_client_error_js_1.InvalidClientError((0,
|
142
|
+
function throwInvalidClient(err, prefix) {
|
143
|
+
throw new invalid_client_error_js_1.InvalidClientError((0, error_js_1.formatError)(err, prefix), err);
|
141
144
|
}
|
142
|
-
function throwInvalidRequest(err) {
|
143
|
-
throw new invalid_request_error_js_1.InvalidRequestError((0,
|
145
|
+
function throwInvalidRequest(err, prefix) {
|
146
|
+
throw new invalid_request_error_js_1.InvalidRequestError((0, error_js_1.formatError)(err, prefix), err);
|
144
147
|
}
|
145
148
|
//# sourceMappingURL=create-oauth-middleware.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-oauth-middleware.js","sourceRoot":"","sources":["../../src/router/create-oauth-middleware.ts"],"names":[],"mappings":";;
|
1
|
+
{"version":3,"file":"create-oauth-middleware.js","sourceRoot":"","sources":["../../src/router/create-oauth-midd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;gBACzD,CAAC;gBAED,MAAM,MAAM,GAAG,IAAA,kCAAgB,EAAC,GAAG,CAAC,CAAA;gBACpC,MAAM,IAAI,GAAG,IAAA,mCAAiB,EAAC,GAAG,CAAC,CAAA;gBAEnC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;YACzB,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAY,EAAE,MAAc;IACrD,MAAM,IAAI,0CAAiB,CAAC,IAAA,sBAAW,EAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAA;AAC5D,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAY,EAAE,MAAc;IACtD,MAAM,IAAI,4CAAkB,CAAC,IAAA,sBAAW,EAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAA;AAC7D,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAY,EAAE,MAAc;IACvD,MAAM,IAAI,8CAAmB,CAAC,IAAA,sBAAW,EAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAA;AAC9D,CAAC"}
|
@@ -5,7 +5,7 @@ exports.buildRedirectUri = buildRedirectUri;
|
|
5
5
|
exports.buildRedirectMode = buildRedirectMode;
|
6
6
|
exports.buildRedirectParams = buildRedirectParams;
|
7
7
|
exports.sendRedirect = sendRedirect;
|
8
|
-
const
|
8
|
+
const authorization_error_js_1 = require("../errors/authorization-error.js");
|
9
9
|
const index_js_1 = require("../lib/html/index.js");
|
10
10
|
const send_web_page_js_1 = require("../lib/send-web-page.js");
|
11
11
|
// https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-11#section-7.5.4
|
@@ -26,7 +26,7 @@ function buildRedirectUri(parameters) {
|
|
26
26
|
const uri = parameters.redirect_uri;
|
27
27
|
if (uri)
|
28
28
|
return uri;
|
29
|
-
throw new
|
29
|
+
throw new authorization_error_js_1.AuthorizationError(parameters, 'No redirect_uri', 'invalid_request');
|
30
30
|
}
|
31
31
|
function buildRedirectMode(parameters) {
|
32
32
|
const mode = parameters.response_mode || 'query'; // @TODO default should depend on response_type
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"send-redirect.js","sourceRoot":"","sources":["../../src/router/send-redirect.ts"],"names":[],"mappings":";;;AAiCA,4CAOC;AAED,8CAKC;AAED,kDAoBC;AAQD,oCAiBC;AAzFD,
|
1
|
+
{"version":3,"file":"send-redirect.js","sourceRoot":"","sources":["../../src/router/send-redirect.ts"],"names":[],"mappings":";;;AAiCA,4CAOC;AAED,8CAKC;AAED,kDAoBC;AAQD,oCAiBC;AAzFD,6EAAqE;AACrE,mDAA+C;AAC/C,8DAAqD;AAGrD,+EAA+E;AAC/E,MAAM,oBAAoB,GAAG,GAAG,CAAA;AAEnB,QAAA,qBAAqB,GAAG;IACnC,MAAM;IACN,UAAU;IACV,cAAc;IACd,YAAY;IACZ,YAAY;CACJ,CAAA;AAEG,QAAA,mBAAmB,GAAG;IACjC,OAAO;IACP,mBAAmB;IACnB,WAAW;CACH,CAAA;AAQV,SAAgB,gBAAgB,CAC9B,UAA+C;IAE/C,MAAM,GAAG,GAAG,UAAU,CAAC,YAAY,CAAA;IACnC,IAAI,GAAG;QAAE,OAAO,GAAG,CAAA;IAEnB,MAAM,IAAI,2CAAkB,CAAC,UAAU,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAA;AAChF,CAAC;AAED,SAAgB,iBAAiB,CAC/B,UAA+C;IAE/C,MAAM,IAAI,GAAG,UAAU,CAAC,aAAa,IAAI,OAAO,CAAA,CAAC,+CAA+C;IAChG,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAgB,mBAAmB,CACjC,MAAc,EACd,UAA+C,EAC/C,QAAyC;IAEzC,MAAM,MAAM,GAA4C;QACtD,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,UAAU;KAC5B,CAAA;IAED,IAAI,UAAU,CAAC,KAAK,IAAI,IAAI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AE,CAAC,IAAA,aAAE,EAAA,6BAA6B,CAAC;KAC3C,CAAC,CAAA;AACJ,CAAC"}
|
@@ -188,7 +188,7 @@ class TokenManager {
|
|
188
188
|
// @TODO Add another store method that atomically consumes the refresh token
|
189
189
|
// with a lock.
|
190
190
|
const tokenInfo = await this.findByRefreshToken(token).catch((err) => {
|
191
|
-
throw
|
191
|
+
throw invalid_grant_error_js_1.InvalidGrantError.from(err, `Invalid refresh token`);
|
192
192
|
});
|
193
193
|
if (!tokenInfo) {
|
194
194
|
throw new invalid_grant_error_js_1.InvalidGrantError(`Invalid refresh token`);
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
export declare const authorizationResponseErrorSchema: z.ZodUnion<[z.ZodEnum<["invalid_request", "unauthorized_client", "access_denied", "unsupported_response_type", "invalid_scope", "server_error", "temporarily_unavailable"]>, z.ZodEnum<["interaction_required", "login_required", "account_selection_required", "consent_required", "invalid_request_uri", "invalid_request_object", "request_not_supported", "request_uri_not_supported", "registration_not_supported"]>, z.ZodLiteral<"invalid_authorization_details">]>;
|
3
|
+
export type AuthorizationResponseError = z.infer<typeof authorizationResponseErrorSchema>;
|
4
|
+
export declare function isAuthorizationResponseError<T>(value: T): value is T & AuthorizationResponseError;
|
5
|
+
//# sourceMappingURL=authorization-response-error.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"authorization-response-error.d.ts","sourceRoot":"","sources":["../../src/types/authorization-response-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,gCAAgC,4cAU3C,CAAA;AAEF,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAC9C,OAAO,gCAAgC,CACxC,CAAA;AAED,wBAAgB,4BAA4B,CAAC,CAAC,EAC5C,KAAK,EAAE,CAAC,GACP,KAAK,IAAI,CAAC,GAAG,0BAA0B,CAEzC"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.authorizationResponseErrorSchema = void 0;
|
4
|
+
exports.isAuthorizationResponseError = isAuthorizationResponseError;
|
5
|
+
const zod_1 = require("zod");
|
6
|
+
const oauth_types_1 = require("@atproto/oauth-types");
|
7
|
+
exports.authorizationResponseErrorSchema = zod_1.z.union([
|
8
|
+
oauth_types_1.oauthAuthorizationResponseErrorSchema,
|
9
|
+
// OIDC authentication error response are not part of the ATproto flavoured
|
10
|
+
// OAuth but we allow them because they provide better feedback to the client
|
11
|
+
// (in particular when SSO is used).
|
12
|
+
oauth_types_1.oidcAuthorizationResponseErrorSchema,
|
13
|
+
// This error is defined by rfc9396 (not part of the OAuth 2.1 or OIDC). But
|
14
|
+
// since, in ATproto flavoured OAuth, client registration is a dynamic part of
|
15
|
+
// the authorization process, we allow it.
|
16
|
+
zod_1.z.literal('invalid_authorization_details'),
|
17
|
+
]);
|
18
|
+
function isAuthorizationResponseError(value) {
|
19
|
+
return exports.authorizationResponseErrorSchema.safeParse(value).success;
|
20
|
+
}
|
21
|
+
//# sourceMappingURL=authorization-response-error.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"authorization-response-error.js","sourceRoot":"","sources":["../../src/types/authorization-response-error.ts"],"names":[],"mappings":";;;AAsBA,oEAIC;AA1BD,6BAAuB;AACvB,sDAG6B;AAEhB,QAAA,gCAAgC,GAAG,OAAC,CAAC,KAAK,CAAC;IACtD,mDAAqC;IACrC,2EAA2E;IAC3E,6EAA6E;IAC7E,oCAAoC;IACpC,kDAAoC;IACpC,4EAA4E;IAC5E,8EAA8E;IAC9E,0CAA0C;IAC1C,OAAC,CAAC,OAAO,CAAC,+BAA+B,CAAC;CAC3C,CAAC,CAAA;AAMF,SAAgB,4BAA4B,CAC1C,KAAQ;IAER,OAAO,wCAAgC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAA;AAClE,CAAC"}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
export declare const parResponseErrorSchema: z.ZodIntersection<z.ZodUnion<[z.ZodEnum<["invalid_request", "unauthorized_client", "access_denied", "unsupported_response_type", "invalid_scope", "server_error", "temporarily_unavailable"]>, z.ZodEnum<["interaction_required", "login_required", "account_selection_required", "consent_required", "invalid_request_uri", "invalid_request_object", "request_not_supported", "request_uri_not_supported", "registration_not_supported"]>, z.ZodLiteral<"invalid_authorization_details">]>, z.ZodEnum<["invalid_request", "unauthorized_client", "unsupported_response_type", "invalid_scope", "server_error", "temporarily_unavailable"]>>;
|
3
|
+
export type PARResponseError = z.infer<typeof parResponseErrorSchema>;
|
4
|
+
export declare function isPARResponseError<T>(value: T): value is T & PARResponseError;
|
5
|
+
//# sourceMappingURL=par-response-error.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"par-response-error.d.ts","sourceRoot":"","sources":["../../src/types/par-response-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAQvB,eAAO,MAAM,sBAAsB,+mBAUlC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAErE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,gBAAgB,CAE7E"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parResponseErrorSchema = void 0;
|
4
|
+
exports.isPARResponseError = isPARResponseError;
|
5
|
+
const zod_1 = require("zod");
|
6
|
+
const authorization_response_error_js_1 = require("./authorization-response-error.js");
|
7
|
+
// https://datatracker.ietf.org/doc/html/rfc9126#section-2.3-1
|
8
|
+
// > Since initial processing of the pushed authorization request does not
|
9
|
+
// > involve resource owner interaction, error codes related to user
|
10
|
+
// > interaction, such as "access_denied", are never returned.
|
11
|
+
exports.parResponseErrorSchema = zod_1.z.intersection(authorization_response_error_js_1.authorizationResponseErrorSchema, zod_1.z.enum([
|
12
|
+
'invalid_request',
|
13
|
+
'unauthorized_client',
|
14
|
+
'unsupported_response_type',
|
15
|
+
'invalid_scope',
|
16
|
+
'server_error',
|
17
|
+
'temporarily_unavailable',
|
18
|
+
]));
|
19
|
+
function isPARResponseError(value) {
|
20
|
+
return exports.parResponseErrorSchema.safeParse(value).success;
|
21
|
+
}
|
22
|
+
//# sourceMappingURL=par-response-error.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"par-response-error.js","sourceRoot":"","sources":["../../src/types/par-response-error.ts"],"names":[],"mappings":";;;AAsBA,gDAEC;AAxBD,6BAAuB;AACvB,uFAAoF;AAEpF,8DAA8D;AAC9D,0EAA0E;AAC1E,oEAAoE;AACpE,8DAA8D;AAEjD,QAAA,sBAAsB,GAAG,OAAC,CAAC,YAAY,CAClD,kEAAgC,EAChC,OAAC,CAAC,IAAI,CAAC;IACL,iBAAiB;IACjB,qBAAqB;IACrB,2BAA2B;IAC3B,eAAe;IACf,cAAc;IACd,yBAAyB;CAC1B,CAAC,CACH,CAAA;AAID,SAAgB,kBAAkB,CAAI,KAAQ;IAC5C,OAAO,8BAAsB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAA;AACxD,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atproto/oauth-provider",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.3",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "Generic OAuth2 and OpenID Connect provider for Node.js. Currently only supports features needed for Atproto.",
|
6
6
|
"keywords": [
|
@@ -51,10 +51,10 @@
|
|
51
51
|
"@atproto/did": "0.1.5",
|
52
52
|
"@atproto/jwk": "0.4.0",
|
53
53
|
"@atproto/jwk-jose": "0.1.9",
|
54
|
-
"@atproto/oauth-types": "0.
|
55
|
-
"@atproto/oauth-provider-api": "0.1.
|
56
|
-
"@atproto/oauth-provider-frontend": "0.1.
|
57
|
-
"@atproto/oauth-provider-ui": "0.1.
|
54
|
+
"@atproto/oauth-types": "0.4.0",
|
55
|
+
"@atproto/oauth-provider-api": "0.1.6",
|
56
|
+
"@atproto/oauth-provider-frontend": "0.1.10",
|
57
|
+
"@atproto/oauth-provider-ui": "0.1.11",
|
58
58
|
"@atproto/syntax": "0.4.0"
|
59
59
|
},
|
60
60
|
"devDependencies": {
|
package/src/client/client.ts
CHANGED
@@ -24,10 +24,10 @@ import {
|
|
24
24
|
OAuthRedirectUri,
|
25
25
|
} from '@atproto/oauth-types'
|
26
26
|
import { CLIENT_ASSERTION_MAX_AGE, JAR_MAX_AGE } from '../constants.js'
|
27
|
+
import { AuthorizationError } from '../errors/authorization-error.js'
|
27
28
|
import { InvalidAuthorizationDetailsError } from '../errors/invalid-authorization-details-error.js'
|
28
29
|
import { InvalidClientError } from '../errors/invalid-client-error.js'
|
29
30
|
import { InvalidClientMetadataError } from '../errors/invalid-client-metadata-error.js'
|
30
|
-
import { InvalidParametersError } from '../errors/invalid-parameters-error.js'
|
31
31
|
import { InvalidRequestError } from '../errors/invalid-request-error.js'
|
32
32
|
import { InvalidScopeError } from '../errors/invalid-scope-error.js'
|
33
33
|
import { asArray } from '../lib/util/cast.js'
|
@@ -285,7 +285,7 @@ export class Client {
|
|
285
285
|
parameters: Readonly<OAuthAuthorizationRequestParameters>,
|
286
286
|
): Readonly<OAuthAuthorizationRequestParameters> {
|
287
287
|
if (parameters.client_id !== this.id) {
|
288
|
-
throw new
|
288
|
+
throw new AuthorizationError(
|
289
289
|
parameters,
|
290
290
|
'The "client_id" parameter field does not match the value used to authenticate the client',
|
291
291
|
)
|
@@ -314,7 +314,7 @@ export class Client {
|
|
314
314
|
}
|
315
315
|
|
316
316
|
if (!this.metadata.response_types.includes(parameters.response_type)) {
|
317
|
-
throw new
|
317
|
+
throw new AuthorizationError(
|
318
318
|
parameters,
|
319
319
|
`Invalid response_type "${parameters.response_type}" requested by the client`,
|
320
320
|
)
|
@@ -322,7 +322,7 @@ export class Client {
|
|
322
322
|
|
323
323
|
if (parameters.response_type.includes('code')) {
|
324
324
|
if (!this.metadata.grant_types.includes('authorization_code')) {
|
325
|
-
throw new
|
325
|
+
throw new AuthorizationError(
|
326
326
|
parameters,
|
327
327
|
`This client is not allowed to use the "authorization_code" grant type`,
|
328
328
|
)
|
@@ -336,7 +336,7 @@ export class Client {
|
|
336
336
|
compareRedirectUri(uri, redirect_uri),
|
337
337
|
)
|
338
338
|
) {
|
339
|
-
throw new
|
339
|
+
throw new AuthorizationError(
|
340
340
|
parameters,
|
341
341
|
`Invalid redirect_uri ${redirect_uri}`,
|
342
342
|
)
|
@@ -351,7 +351,7 @@ export class Client {
|
|
351
351
|
// > "redirect_uri": OPTIONAL if only one redirect URI is registered for
|
352
352
|
// > this client. REQUIRED if multiple redirect URIs are registered for this
|
353
353
|
// > client.
|
354
|
-
throw new
|
354
|
+
throw new AuthorizationError(parameters, 'redirect_uri is required')
|
355
355
|
}
|
356
356
|
}
|
357
357
|
|
@@ -261,7 +261,7 @@ export class DeviceManager {
|
|
261
261
|
const rawValue = Object.hasOwn(cookies, name) ? cookies[name] : null
|
262
262
|
if (!rawValue) return null
|
263
263
|
|
264
|
-
const result = schema.safeParse(rawValue
|
264
|
+
const result = schema.safeParse(rawValue)
|
265
265
|
if (!result.success) return null
|
266
266
|
|
267
267
|
const value = result.data
|
package/src/dpop/dpop-manager.ts
CHANGED
@@ -68,7 +68,7 @@ export class DpopManager {
|
|
68
68
|
maxTokenAge: 10, // Will ensure presence & validity of "iat" claim
|
69
69
|
clockTolerance: DPOP_NONCE_MAX_AGE / 1e3,
|
70
70
|
}).catch((err) => {
|
71
|
-
throw
|
71
|
+
throw wrapInvalidDpopProofError(err, 'Failed to verify DPoP proof')
|
72
72
|
})
|
73
73
|
|
74
74
|
// @NOTE For legacy & backwards compatibility reason, we cannot use
|
@@ -86,20 +86,20 @@ export class DpopManager {
|
|
86
86
|
const { ath, htm, htu, jti, nonce } = payload
|
87
87
|
|
88
88
|
if (nonce !== undefined && typeof nonce !== 'string') {
|
89
|
-
throw
|
89
|
+
throw new InvalidDpopProofError('Invalid DPoP "nonce" type')
|
90
90
|
}
|
91
91
|
|
92
92
|
if (!jti || typeof jti !== 'string') {
|
93
|
-
throw
|
93
|
+
throw new InvalidDpopProofError('DPoP "jti" missing')
|
94
94
|
}
|
95
95
|
|
96
96
|
// Note rfc9110#section-9.1 states that the method name is case-sensitive
|
97
97
|
if (!htm || htm !== httpMethod) {
|
98
|
-
throw
|
98
|
+
throw new InvalidDpopProofError('DPoP "htm" mismatch')
|
99
99
|
}
|
100
100
|
|
101
101
|
if (!htu || typeof htu !== 'string') {
|
102
|
-
throw
|
102
|
+
throw new InvalidDpopProofError('Invalid DPoP "htu" type')
|
103
103
|
}
|
104
104
|
|
105
105
|
// > To reduce the likelihood of false negatives, servers SHOULD employ
|
@@ -109,7 +109,7 @@ export class DpopManager {
|
|
109
109
|
//
|
110
110
|
// RFC9449 section 4.3. Checking DPoP Proofs - https://datatracker.ietf.org/doc/html/rfc9449#section-4.3
|
111
111
|
if (!htu || parseHtu(htu) !== normalizeHtuUrl(httpUrl)) {
|
112
|
-
throw
|
112
|
+
throw new InvalidDpopProofError('DPoP "htu" mismatch')
|
113
113
|
}
|
114
114
|
|
115
115
|
if (!nonce && this.dpopNonce) {
|
@@ -123,17 +123,17 @@ export class DpopManager {
|
|
123
123
|
if (accessToken) {
|
124
124
|
const accessTokenHash = createHash('sha256').update(accessToken).digest()
|
125
125
|
if (ath !== accessTokenHash.toString('base64url')) {
|
126
|
-
throw
|
126
|
+
throw new InvalidDpopProofError('DPoP "ath" mismatch')
|
127
127
|
}
|
128
128
|
} else if (ath !== undefined) {
|
129
|
-
throw
|
129
|
+
throw new InvalidDpopProofError('DPoP "ath" claim not allowed')
|
130
130
|
}
|
131
131
|
|
132
132
|
// @NOTE we can assert there is a jwk because the jwtVerify used the
|
133
133
|
// EmbeddedJWK key getter mechanism.
|
134
134
|
const jwk = protectedHeader.jwk!
|
135
135
|
const jkt = await calculateJwkThumbprint(jwk, 'sha256').catch((err) => {
|
136
|
-
throw
|
136
|
+
throw wrapInvalidDpopProofError(err, 'Failed to calculate jkt')
|
137
137
|
})
|
138
138
|
|
139
139
|
return { jti, jkt, htm, htu }
|
@@ -147,12 +147,12 @@ function extractProof(
|
|
147
147
|
switch (typeof dpopHeader) {
|
148
148
|
case 'string':
|
149
149
|
if (dpopHeader) return dpopHeader
|
150
|
-
throw
|
150
|
+
throw new InvalidDpopProofError('DPoP header cannot be empty')
|
151
151
|
case 'object':
|
152
152
|
// @NOTE the "0" case should never happen a node.js HTTP server will only
|
153
153
|
// return an array if the header is set multiple times.
|
154
154
|
if (dpopHeader.length === 1 && dpopHeader[0]) return dpopHeader[0]!
|
155
|
-
throw
|
155
|
+
throw new InvalidDpopProofError('DPoP header must contain a single proof')
|
156
156
|
default:
|
157
157
|
return null
|
158
158
|
}
|
@@ -177,7 +177,7 @@ function normalizeHtuUrl(url: Readonly<URL>): string {
|
|
177
177
|
function parseHtu(htu: string): string {
|
178
178
|
const url = ifURL(htu)
|
179
179
|
if (!url) {
|
180
|
-
throw
|
180
|
+
throw new InvalidDpopProofError('DPoP "htu" is not a valid URL')
|
181
181
|
}
|
182
182
|
|
183
183
|
// @NOTE the checks bellow can be removed once once jwtPayloadSchema is used
|
@@ -185,11 +185,11 @@ function parseHtu(htu: string): string {
|
|
185
185
|
// (though the htuSchema).
|
186
186
|
|
187
187
|
if (url.password || url.username) {
|
188
|
-
throw
|
188
|
+
throw new InvalidDpopProofError('DPoP "htu" must not contain credentials')
|
189
189
|
}
|
190
190
|
|
191
191
|
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
192
|
-
throw
|
192
|
+
throw new InvalidDpopProofError('DPoP "htu" must be http or https')
|
193
193
|
}
|
194
194
|
|
195
195
|
// @NOTE For legacy & backwards compatibility reason, we allow a query and
|
@@ -200,9 +200,9 @@ function parseHtu(htu: string): string {
|
|
200
200
|
return normalizeHtuUrl(url)
|
201
201
|
}
|
202
202
|
|
203
|
-
function
|
203
|
+
function wrapInvalidDpopProofError(
|
204
|
+
err: unknown,
|
204
205
|
title: string,
|
205
|
-
err?: unknown,
|
206
206
|
): InvalidDpopProofError {
|
207
207
|
const msg =
|
208
208
|
err instanceof JOSEError || err instanceof ValidationError
|
@@ -1,39 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
OAuthAuthorizationRequestParameters,
|
4
|
-
OidcAuthenticationErrorResponse,
|
5
|
-
} from '@atproto/oauth-types'
|
6
|
-
import { buildErrorPayload } from './error-parser.js'
|
7
|
-
import { OAuthError } from './oauth-error.js'
|
1
|
+
import { OAuthAuthorizationRequestParameters } from '@atproto/oauth-types'
|
2
|
+
import { AuthorizationError } from './authorization-error.js'
|
8
3
|
|
9
|
-
export
|
10
|
-
| OAuthAuthenticationErrorResponse
|
11
|
-
// OIDC authentication error response are not part of the ATproto flavoured
|
12
|
-
// OAuth but we allow them because they provide better feedback to the client
|
13
|
-
// (in particular when SSO is used).
|
14
|
-
| OidcAuthenticationErrorResponse
|
15
|
-
// This error is defined by rfc9396 (not part of the OAuth 2.1 or OIDC). But
|
16
|
-
// since, in ATproto flavoured OAuth, client registration is a dynamic part of
|
17
|
-
// the authorization process, we allow it.
|
18
|
-
| 'invalid_authorization_details'
|
19
|
-
|
20
|
-
export class AccessDeniedError extends OAuthError {
|
4
|
+
export class AccessDeniedError extends AuthorizationError {
|
21
5
|
constructor(
|
22
|
-
|
23
|
-
error_description
|
24
|
-
error: AuthenticationErrorResponse = 'access_denied',
|
6
|
+
parameters: OAuthAuthorizationRequestParameters,
|
7
|
+
error_description = 'Access denied',
|
25
8
|
cause?: unknown,
|
26
9
|
) {
|
27
|
-
super(
|
28
|
-
}
|
29
|
-
|
30
|
-
static from(
|
31
|
-
parameters: OAuthAuthorizationRequestParameters,
|
32
|
-
cause: unknown,
|
33
|
-
error: AuthenticationErrorResponse,
|
34
|
-
): AccessDeniedError {
|
35
|
-
if (cause instanceof AccessDeniedError) return cause
|
36
|
-
const { error_description } = buildErrorPayload(cause)
|
37
|
-
return new AccessDeniedError(parameters, error_description, error, cause)
|
10
|
+
super(parameters, error_description, 'access_denied', cause)
|
38
11
|
}
|
39
12
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { OAuthAuthorizationRequestParameters } from '@atproto/oauth-types'
|
2
|
-
import {
|
2
|
+
import { AuthorizationError } from './authorization-error.js'
|
3
3
|
|
4
|
-
export class AccountSelectionRequiredError extends
|
4
|
+
export class AccountSelectionRequiredError extends AuthorizationError {
|
5
5
|
constructor(
|
6
6
|
parameters: OAuthAuthorizationRequestParameters,
|
7
7
|
error_description = 'Account selection required',
|