@atproto/oauth-types 0.1.5 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +28 -0
- package/dist/atproto-loopback-client-metadata.d.ts +4 -1
- package/dist/atproto-loopback-client-metadata.d.ts.map +1 -1
- package/dist/atproto-loopback-client-metadata.js +1 -2
- package/dist/atproto-loopback-client-metadata.js.map +1 -1
- package/dist/constants.d.ts +0 -6
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -17
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/oauth-authorization-code-grant-token-request.d.ts +2 -2
- package/dist/oauth-authorization-code-grant-token-request.d.ts.map +1 -1
- package/dist/oauth-authorization-code-grant-token-request.js +2 -1
- package/dist/oauth-authorization-code-grant-token-request.js.map +1 -1
- package/dist/oauth-authorization-details.d.ts +42 -4
- package/dist/oauth-authorization-details.d.ts.map +1 -1
- package/dist/oauth-authorization-details.js +21 -1
- package/dist/oauth-authorization-details.js.map +1 -1
- package/dist/oauth-authorization-request-jar.d.ts +1 -1
- package/dist/oauth-authorization-request-par.d.ts +11 -11
- package/dist/oauth-authorization-request-parameters.d.ts +10 -10
- package/dist/oauth-authorization-request-parameters.d.ts.map +1 -1
- package/dist/oauth-authorization-request-parameters.js +3 -2
- package/dist/oauth-authorization-request-parameters.js.map +1 -1
- package/dist/oauth-authorization-request-query.d.ts +11 -11
- package/dist/oauth-authorization-server-metadata.d.ts +69 -66
- package/dist/oauth-authorization-server-metadata.d.ts.map +1 -1
- package/dist/oauth-authorization-server-metadata.js +14 -10
- package/dist/oauth-authorization-server-metadata.js.map +1 -1
- package/dist/oauth-client-id-discoverable.d.ts +3 -2
- package/dist/oauth-client-id-discoverable.d.ts.map +1 -1
- package/dist/oauth-client-id-discoverable.js +54 -31
- package/dist/oauth-client-id-discoverable.js.map +1 -1
- package/dist/oauth-client-id-loopback.d.ts +5 -5
- package/dist/oauth-client-id-loopback.d.ts.map +1 -1
- package/dist/oauth-client-id-loopback.js +32 -31
- package/dist/oauth-client-id-loopback.js.map +1 -1
- package/dist/oauth-client-metadata.d.ts +112 -102
- package/dist/oauth-client-metadata.d.ts.map +1 -1
- package/dist/oauth-client-metadata.js +18 -8
- package/dist/oauth-client-metadata.js.map +1 -1
- package/dist/oauth-issuer-identifier.d.ts +2 -1
- package/dist/oauth-issuer-identifier.d.ts.map +1 -1
- package/dist/oauth-issuer-identifier.js +8 -23
- package/dist/oauth-issuer-identifier.js.map +1 -1
- package/dist/oauth-protected-resource-metadata.d.ts +15 -12
- package/dist/oauth-protected-resource-metadata.d.ts.map +1 -1
- package/dist/oauth-protected-resource-metadata.js +15 -5
- package/dist/oauth-protected-resource-metadata.js.map +1 -1
- package/dist/oauth-redirect-uri.d.ts +10 -0
- package/dist/oauth-redirect-uri.d.ts.map +1 -0
- package/dist/oauth-redirect-uri.js +35 -0
- package/dist/oauth-redirect-uri.js.map +1 -0
- package/dist/oauth-refresh-token-grant-token-request.d.ts +0 -3
- package/dist/oauth-refresh-token-grant-token-request.d.ts.map +1 -1
- package/dist/oauth-refresh-token-grant-token-request.js +0 -2
- package/dist/oauth-refresh-token-grant-token-request.js.map +1 -1
- package/dist/oauth-token-request.d.ts +2 -5
- package/dist/oauth-token-request.d.ts.map +1 -1
- package/dist/oauth-token-response.d.ts +9 -12
- package/dist/oauth-token-response.d.ts.map +1 -1
- package/dist/oauth-token-response.js +4 -2
- package/dist/oauth-token-response.js.map +1 -1
- package/dist/uri.d.ts +20 -0
- package/dist/uri.d.ts.map +1 -0
- package/dist/uri.js +127 -0
- package/dist/uri.js.map +1 -0
- package/dist/util.js +5 -6
- package/dist/util.js.map +1 -1
- package/package.json +2 -2
- package/src/atproto-loopback-client-metadata.ts +8 -3
- package/src/constants.ts +0 -16
- package/src/index.ts +2 -0
- package/src/oauth-authorization-code-grant-token-request.ts +2 -1
- package/src/oauth-authorization-details.ts +21 -1
- package/src/oauth-authorization-request-parameters.ts +3 -2
- package/src/oauth-authorization-server-metadata.ts +14 -10
- package/src/oauth-client-id-discoverable.ts +69 -51
- package/src/oauth-client-id-loopback.ts +40 -40
- package/src/oauth-client-metadata.ts +18 -8
- package/src/oauth-issuer-identifier.ts +14 -24
- package/src/oauth-protected-resource-metadata.ts +15 -5
- package/src/oauth-redirect-uri.ts +56 -0
- package/src/oauth-refresh-token-grant-token-request.ts +0 -2
- package/src/oauth-token-response.ts +4 -2
- package/src/uri.ts +171 -0
- package/tsconfig.build.tsbuildinfo +1 -0
@@ -1,12 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import { TypeOf } from 'zod';
|
2
|
+
import { OAuthRedirectUri } from './oauth-redirect-uri.js';
|
2
3
|
import { OAuthScope } from './oauth-scope.js';
|
3
|
-
declare const
|
4
|
-
export type OAuthClientIdLoopback =
|
4
|
+
export declare const oauthClientIdLoopbackSchema: import("zod").ZodEffects<import("zod").ZodString, "http://localhost" | `http://localhost?${string}` | "http://localhost/" | `http://localhost/?${string}`, string>;
|
5
|
+
export type OAuthClientIdLoopback = TypeOf<typeof oauthClientIdLoopbackSchema>;
|
5
6
|
export declare function isOAuthClientIdLoopback(clientId: string): clientId is OAuthClientIdLoopback;
|
6
7
|
export declare function assertOAuthLoopbackClientId(clientId: string): asserts clientId is OAuthClientIdLoopback;
|
7
8
|
export declare function parseOAuthLoopbackClientId(clientId: string): {
|
8
9
|
scope?: OAuthScope;
|
9
|
-
redirect_uris?: [
|
10
|
+
redirect_uris?: [OAuthRedirectUri, ...OAuthRedirectUri[]];
|
10
11
|
};
|
11
|
-
export {};
|
12
12
|
//# sourceMappingURL=oauth-client-id-loopback.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"oauth-client-id-loopback.d.ts","sourceRoot":"","sources":["../src/oauth-client-id-loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"oauth-client-id-loopback.d.ts","sourceRoot":"","sources":["../src/oauth-client-id-loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,KAAK,CAAA;AAE1C,OAAO,EAGL,gBAAgB,EACjB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAA;AAI/D,eAAO,MAAM,2BAA2B,oKAgBvC,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAA;AAE9E,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,GACf,QAAQ,IAAI,qBAAqB,CAOnC;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,QAAQ,IAAI,qBAAqB,CAE3C;AAID,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG;IAC5D,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,aAAa,CAAC,EAAE,CAAC,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAAC,CAAA;CAC1D,CAoDA"}
|
@@ -1,9 +1,29 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.oauthClientIdLoopbackSchema = void 0;
|
4
|
+
exports.isOAuthClientIdLoopback = isOAuthClientIdLoopback;
|
5
|
+
exports.assertOAuthLoopbackClientId = assertOAuthLoopbackClientId;
|
6
|
+
exports.parseOAuthLoopbackClientId = parseOAuthLoopbackClientId;
|
7
|
+
const zod_1 = require("zod");
|
8
|
+
const oauth_client_id_js_1 = require("./oauth-client-id.js");
|
9
|
+
const oauth_redirect_uri_js_1 = require("./oauth-redirect-uri.js");
|
4
10
|
const oauth_scope_js_1 = require("./oauth-scope.js");
|
5
|
-
const
|
6
|
-
|
11
|
+
const PREFIX = 'http://localhost';
|
12
|
+
exports.oauthClientIdLoopbackSchema = oauth_client_id_js_1.oauthClientIdSchema.superRefine((value, ctx) => {
|
13
|
+
try {
|
14
|
+
assertOAuthLoopbackClientId(value);
|
15
|
+
return true;
|
16
|
+
}
|
17
|
+
catch (error) {
|
18
|
+
ctx.addIssue({
|
19
|
+
code: zod_1.ZodIssueCode.custom,
|
20
|
+
message: error instanceof TypeError
|
21
|
+
? error.message
|
22
|
+
: 'Invalid loopback client ID',
|
23
|
+
});
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
});
|
7
27
|
function isOAuthClientIdLoopback(clientId) {
|
8
28
|
try {
|
9
29
|
parseOAuthLoopbackClientId(clientId);
|
@@ -13,24 +33,21 @@ function isOAuthClientIdLoopback(clientId) {
|
|
13
33
|
return false;
|
14
34
|
}
|
15
35
|
}
|
16
|
-
exports.isOAuthClientIdLoopback = isOAuthClientIdLoopback;
|
17
36
|
function assertOAuthLoopbackClientId(clientId) {
|
18
37
|
void parseOAuthLoopbackClientId(clientId);
|
19
38
|
}
|
20
|
-
exports.assertOAuthLoopbackClientId = assertOAuthLoopbackClientId;
|
21
39
|
// @TODO: should we turn this into a zod schema? (more coherent error with other
|
22
40
|
// validation functions)
|
23
41
|
function parseOAuthLoopbackClientId(clientId) {
|
24
|
-
if (!clientId.startsWith(
|
25
|
-
throw new TypeError(`Loopback ClientID must start with "${
|
42
|
+
if (!clientId.startsWith(PREFIX)) {
|
43
|
+
throw new TypeError(`Loopback ClientID must start with "${PREFIX}"`);
|
26
44
|
}
|
27
|
-
else if (clientId.includes('#',
|
45
|
+
else if (clientId.includes('#', PREFIX.length)) {
|
28
46
|
throw new TypeError('Loopback ClientID must not contain a hash component');
|
29
47
|
}
|
30
|
-
const queryStringIdx = clientId.length >
|
31
|
-
|
32
|
-
|
33
|
-
: OAUTH_CLIENT_ID_LOOPBACK_URL.length;
|
48
|
+
const queryStringIdx = clientId.length > PREFIX.length && clientId[PREFIX.length] === '/'
|
49
|
+
? PREFIX.length + 1
|
50
|
+
: PREFIX.length;
|
34
51
|
if (clientId.length === queryStringIdx) {
|
35
52
|
return {}; // no query string to parse
|
36
53
|
}
|
@@ -53,29 +70,13 @@ function parseOAuthLoopbackClientId(clientId) {
|
|
53
70
|
}
|
54
71
|
}
|
55
72
|
const redirect_uris = searchParams.has('redirect_uri')
|
56
|
-
? searchParams
|
73
|
+
? searchParams
|
74
|
+
.getAll('redirect_uri')
|
75
|
+
.map((value) => oauth_redirect_uri_js_1.oauthLoopbackRedirectURISchema.parse(value))
|
57
76
|
: undefined;
|
58
|
-
if (redirect_uris) {
|
59
|
-
for (const uri of redirect_uris) {
|
60
|
-
const url = (0, util_js_1.safeUrl)(uri);
|
61
|
-
if (!url) {
|
62
|
-
throw new TypeError(`Invalid redirect_uri in client ID: ${uri}`);
|
63
|
-
}
|
64
|
-
if (url.protocol !== 'http:') {
|
65
|
-
throw new TypeError(`Loopback ClientID must use "http:" redirect_uri's (got ${uri})`);
|
66
|
-
}
|
67
|
-
if (url.hostname === 'localhost') {
|
68
|
-
throw new TypeError(`Loopback ClientID must not use "localhost" as redirect_uri hostname (got ${uri})`);
|
69
|
-
}
|
70
|
-
if (!(0, util_js_1.isLoopbackHost)(url.hostname)) {
|
71
|
-
throw new TypeError(`Loopback ClientID must use loopback addresses as redirect_uri's (got ${uri})`);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
77
|
return {
|
76
78
|
scope,
|
77
79
|
redirect_uris,
|
78
80
|
};
|
79
81
|
}
|
80
|
-
exports.parseOAuthLoopbackClientId = parseOAuthLoopbackClientId;
|
81
82
|
//# sourceMappingURL=oauth-client-id-loopback.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"oauth-client-id-loopback.js","sourceRoot":"","sources":["../src/oauth-client-id-loopback.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"oauth-client-id-loopback.js","sourceRoot":"","sources":["../src/oauth-client-id-loopback.ts"],"names":[],"mappings":";;;AA+BA,0DASC;AAED,kEAIC;AAID,gEAuDC;AAzGD,6BAA0C;AAC1C,6DAA0D;AAC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