@shware/security 2.5.3 → 3.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/dist/auth/index.cjs +519 -561
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +104 -106
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.mts +109 -0
- package/dist/auth/index.d.mts.map +1 -0
- package/dist/auth/index.mjs +512 -536
- package/dist/auth/index.mjs.map +1 -1
- package/dist/auth/types.cjs +0 -19
- package/dist/auth/types.d.cts +44 -44
- package/dist/auth/types.d.cts.map +1 -0
- package/dist/auth/types.d.mts +50 -0
- package/dist/auth/types.d.mts.map +1 -0
- package/dist/auth/types.mjs +1 -1
- package/dist/core/index.cjs +18 -59
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +13 -24
- package/dist/core/index.d.cts.map +1 -0
- package/dist/core/index.d.mts +21 -0
- package/dist/core/index.d.mts.map +1 -0
- package/dist/core/index.mjs +17 -33
- package/dist/core/index.mjs.map +1 -1
- package/dist/email/schema.cjs +13 -38
- package/dist/email/schema.cjs.map +1 -1
- package/dist/email/schema.d.cts +11 -12
- package/dist/email/schema.d.cts.map +1 -0
- package/dist/email/schema.d.mts +12 -0
- package/dist/email/schema.d.mts.map +1 -0
- package/dist/email/schema.mjs +10 -11
- package/dist/email/schema.mjs.map +1 -1
- package/dist/index.cjs +18 -54
- package/dist/index.d.cts +10 -15
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +5 -17
- package/dist/oauth2/client.cjs +109 -145
- package/dist/oauth2/client.cjs.map +1 -1
- package/dist/oauth2/client.d.cts +55 -56
- package/dist/oauth2/client.d.cts.map +1 -0
- package/dist/oauth2/client.d.mts +58 -0
- package/dist/oauth2/client.d.mts.map +1 -0
- package/dist/oauth2/client.mjs +104 -116
- package/dist/oauth2/client.mjs.map +1 -1
- package/dist/oauth2/error.cjs +19 -44
- package/dist/oauth2/error.cjs.map +1 -1
- package/dist/oauth2/error.d.cts +8 -6
- package/dist/oauth2/error.d.cts.map +1 -0
- package/dist/oauth2/{error.d.ts → error.d.mts} +8 -6
- package/dist/oauth2/error.d.mts.map +1 -0
- package/dist/oauth2/error.mjs +18 -19
- package/dist/oauth2/error.mjs.map +1 -1
- package/dist/oauth2/provider/apple.cjs +75 -88
- package/dist/oauth2/provider/apple.cjs.map +1 -1
- package/dist/oauth2/provider/apple.d.cts +31 -30
- package/dist/oauth2/provider/apple.d.cts.map +1 -0
- package/dist/oauth2/provider/apple.d.mts +42 -0
- package/dist/oauth2/provider/apple.d.mts.map +1 -0
- package/dist/oauth2/provider/apple.mjs +71 -60
- package/dist/oauth2/provider/apple.mjs.map +1 -1
- package/dist/oauth2/provider/common.cjs +86 -109
- package/dist/oauth2/provider/common.cjs.map +1 -1
- package/dist/oauth2/provider/common.d.cts +19 -18
- package/dist/oauth2/provider/common.d.cts.map +1 -0
- package/dist/oauth2/provider/common.d.mts +30 -0
- package/dist/oauth2/provider/common.d.mts.map +1 -0
- package/dist/oauth2/provider/common.mjs +80 -79
- package/dist/oauth2/provider/common.mjs.map +1 -1
- package/dist/oauth2/provider/facebook.cjs +93 -109
- package/dist/oauth2/provider/facebook.cjs.map +1 -1
- package/dist/oauth2/provider/facebook.d.cts +29 -28
- package/dist/oauth2/provider/facebook.d.cts.map +1 -0
- package/dist/oauth2/provider/facebook.d.mts +45 -0
- package/dist/oauth2/provider/facebook.d.mts.map +1 -0
- package/dist/oauth2/provider/facebook.mjs +89 -81
- package/dist/oauth2/provider/facebook.mjs.map +1 -1
- package/dist/oauth2/provider/github.cjs +64 -91
- package/dist/oauth2/provider/github.cjs.map +1 -1
- package/dist/oauth2/provider/github.d.cts +52 -51
- package/dist/oauth2/provider/github.d.cts.map +1 -0
- package/dist/oauth2/provider/github.d.mts +60 -0
- package/dist/oauth2/provider/github.d.mts.map +1 -0
- package/dist/oauth2/provider/github.mjs +60 -63
- package/dist/oauth2/provider/github.mjs.map +1 -1
- package/dist/oauth2/provider/google.cjs +105 -122
- package/dist/oauth2/provider/google.cjs.map +1 -1
- package/dist/oauth2/provider/google.d.cts +34 -33
- package/dist/oauth2/provider/google.d.cts.map +1 -0
- package/dist/oauth2/provider/google.d.mts +44 -0
- package/dist/oauth2/provider/google.d.mts.map +1 -0
- package/dist/oauth2/provider/google.mjs +101 -94
- package/dist/oauth2/provider/google.mjs.map +1 -1
- package/dist/oauth2/provider/index.cjs +13 -46
- package/dist/oauth2/provider/index.d.cts +7 -7
- package/dist/oauth2/provider/index.d.mts +7 -0
- package/dist/oauth2/provider/index.mjs +1 -10
- package/dist/oauth2/provider/wechat.cjs +77 -99
- package/dist/oauth2/provider/wechat.cjs.map +1 -1
- package/dist/oauth2/provider/wechat.d.cts +28 -27
- package/dist/oauth2/provider/wechat.d.cts.map +1 -0
- package/dist/oauth2/provider/wechat.d.mts +39 -0
- package/dist/oauth2/provider/wechat.d.mts.map +1 -0
- package/dist/oauth2/provider/wechat.mjs +74 -72
- package/dist/oauth2/provider/wechat.mjs.map +1 -1
- package/dist/oauth2/provider/x.cjs +102 -125
- package/dist/oauth2/provider/x.cjs.map +1 -1
- package/dist/oauth2/provider/x.d.cts +51 -50
- package/dist/oauth2/provider/x.d.cts.map +1 -0
- package/dist/oauth2/provider/x.d.mts +69 -0
- package/dist/oauth2/provider/x.d.mts.map +1 -0
- package/dist/oauth2/provider/x.mjs +99 -103
- package/dist/oauth2/provider/x.mjs.map +1 -1
- package/dist/oauth2/types.cjs +12 -37
- package/dist/oauth2/types.cjs.map +1 -1
- package/dist/oauth2/types.d.cts +176 -180
- package/dist/oauth2/types.d.cts.map +1 -0
- package/dist/oauth2/types.d.mts +207 -0
- package/dist/oauth2/types.d.mts.map +1 -0
- package/dist/oauth2/types.mjs +12 -13
- package/dist/oauth2/types.mjs.map +1 -1
- package/dist/session/common.cjs +17 -43
- package/dist/session/common.cjs.map +1 -1
- package/dist/session/common.d.cts +4 -4
- package/dist/session/common.d.cts.map +1 -0
- package/dist/session/{common.d.ts → common.d.mts} +4 -4
- package/dist/session/common.d.mts.map +1 -0
- package/dist/session/common.mjs +14 -16
- package/dist/session/common.mjs.map +1 -1
- package/dist/session/db.cjs +88 -123
- package/dist/session/db.cjs.map +1 -1
- package/dist/session/db.d.cts +36 -36
- package/dist/session/db.d.cts.map +1 -0
- package/dist/session/db.d.mts +44 -0
- package/dist/session/db.d.mts.map +1 -0
- package/dist/session/db.mjs +84 -95
- package/dist/session/db.mjs.map +1 -1
- package/dist/session/map-session.cjs +71 -103
- package/dist/session/map-session.cjs.map +1 -1
- package/dist/session/map-session.d.cts +24 -24
- package/dist/session/map-session.d.cts.map +1 -0
- package/dist/session/map-session.d.mts +27 -0
- package/dist/session/map-session.d.mts.map +1 -0
- package/dist/session/map-session.mjs +70 -78
- package/dist/session/map-session.mjs.map +1 -1
- package/dist/session/redis.cjs +270 -319
- package/dist/session/redis.cjs.map +1 -1
- package/dist/session/redis.d.cts +51 -51
- package/dist/session/redis.d.cts.map +1 -0
- package/dist/session/redis.d.mts +58 -0
- package/dist/session/redis.d.mts.map +1 -0
- package/dist/session/redis.mjs +266 -291
- package/dist/session/redis.mjs.map +1 -1
- package/dist/session/types.cjs +0 -19
- package/dist/session/types.d.cts +34 -33
- package/dist/session/types.d.cts.map +1 -0
- package/dist/session/types.d.mts +45 -0
- package/dist/session/types.d.mts.map +1 -0
- package/dist/session/types.mjs +1 -1
- package/dist/utils/http.cjs +31 -55
- package/dist/utils/http.cjs.map +1 -1
- package/dist/utils/http.d.cts +7 -10
- package/dist/utils/http.d.cts.map +1 -0
- package/dist/utils/{http.d.ts → http.d.mts} +7 -10
- package/dist/utils/http.d.mts.map +1 -0
- package/dist/utils/http.mjs +24 -24
- package/dist/utils/http.mjs.map +1 -1
- package/dist/utils/oauth2.cjs +6 -30
- package/dist/utils/oauth2.cjs.map +1 -1
- package/dist/utils/oauth2.d.cts +3 -1
- package/dist/utils/oauth2.d.cts.map +1 -0
- package/dist/utils/oauth2.d.mts +5 -0
- package/dist/utils/oauth2.d.mts.map +1 -0
- package/dist/utils/oauth2.mjs +5 -5
- package/dist/utils/oauth2.mjs.map +1 -1
- package/dist/utils/timing.cjs +49 -70
- package/dist/utils/timing.cjs.map +1 -1
- package/dist/utils/timing.d.cts +10 -8
- package/dist/utils/timing.d.cts.map +1 -0
- package/dist/utils/timing.d.mts +15 -0
- package/dist/utils/timing.d.mts.map +1 -0
- package/dist/utils/timing.mjs +48 -45
- package/dist/utils/timing.mjs.map +1 -1
- package/dist/utils/valid.cjs +50 -71
- package/dist/utils/valid.cjs.map +1 -1
- package/dist/utils/valid.d.cts +17 -16
- package/dist/utils/valid.d.cts.map +1 -0
- package/dist/utils/valid.d.mts +28 -0
- package/dist/utils/valid.d.mts.map +1 -0
- package/dist/utils/valid.mjs +47 -44
- package/dist/utils/valid.mjs.map +1 -1
- package/package.json +22 -12
- package/dist/auth/index.d.ts +0 -111
- package/dist/auth/types.cjs.map +0 -1
- package/dist/auth/types.d.ts +0 -50
- package/dist/auth/types.mjs.map +0 -1
- package/dist/core/index.d.ts +0 -32
- package/dist/email/schema.d.ts +0 -13
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/oauth2/client.d.ts +0 -59
- package/dist/oauth2/provider/apple.d.ts +0 -41
- package/dist/oauth2/provider/common.d.ts +0 -29
- package/dist/oauth2/provider/facebook.d.ts +0 -44
- package/dist/oauth2/provider/github.d.ts +0 -59
- package/dist/oauth2/provider/google.d.ts +0 -43
- package/dist/oauth2/provider/index.cjs.map +0 -1
- package/dist/oauth2/provider/index.d.ts +0 -7
- package/dist/oauth2/provider/index.mjs.map +0 -1
- package/dist/oauth2/provider/wechat.d.ts +0 -38
- package/dist/oauth2/provider/x.d.ts +0 -68
- package/dist/oauth2/types.d.ts +0 -211
- package/dist/session/__tests__/redis.test.cjs +0 -247
- package/dist/session/__tests__/redis.test.cjs.map +0 -1
- package/dist/session/__tests__/redis.test.d.cts +0 -2
- package/dist/session/__tests__/redis.test.d.ts +0 -2
- package/dist/session/__tests__/redis.test.mjs +0 -252
- package/dist/session/__tests__/redis.test.mjs.map +0 -1
- package/dist/session/db.d.ts +0 -44
- package/dist/session/map-session.d.ts +0 -27
- package/dist/session/redis.d.ts +0 -58
- package/dist/session/types.cjs.map +0 -1
- package/dist/session/types.d.ts +0 -44
- package/dist/session/types.mjs.map +0 -1
- package/dist/utils/oauth2.d.ts +0 -3
- package/dist/utils/timing.d.ts +0 -13
- package/dist/utils/valid.d.ts +0 -27
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { OAuth2Token, Provider } from "../types.mjs";
|
|
2
|
+
//#region src/oauth2/provider/x.d.ts
|
|
3
|
+
interface XOptions {
|
|
4
|
+
userFields?: UserField[];
|
|
5
|
+
}
|
|
6
|
+
declare function createXProvider(options?: XOptions): Provider;
|
|
7
|
+
declare const x: Provider;
|
|
8
|
+
type UserField = 'affiliation' | 'connection_status' | 'created_at' | 'description' | 'entities' | 'id' | 'is_identity_verified' | 'location' | 'most_recent_tweet_id' | 'name' | 'parody' | 'pinned_tweet_id' | 'profile_banner_url' | 'profile_image_url' | 'protected' | 'public_metrics' | 'receives_your_dm' | 'subscription' | 'subscription_type' | 'url' | 'username' | 'verified' | 'verified_followers_count' | 'verified_type' | 'withheld';
|
|
9
|
+
interface XUser {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
username: string;
|
|
14
|
+
location?: string;
|
|
15
|
+
entities?: {
|
|
16
|
+
url: {
|
|
17
|
+
urls: UrlEntity[];
|
|
18
|
+
};
|
|
19
|
+
description: {
|
|
20
|
+
hashtags: HashtagEntity[];
|
|
21
|
+
cashtags: HashtagEntity[];
|
|
22
|
+
mentions: MentionEntity[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
verified?: boolean;
|
|
26
|
+
description?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
profile_image_url?: string;
|
|
29
|
+
protected?: boolean;
|
|
30
|
+
pinned_tweet_id?: string;
|
|
31
|
+
created_at?: string;
|
|
32
|
+
}
|
|
33
|
+
interface XUserInfo {
|
|
34
|
+
data: XUser;
|
|
35
|
+
includes?: {
|
|
36
|
+
tweets?: {
|
|
37
|
+
id: string;
|
|
38
|
+
text: string;
|
|
39
|
+
}[];
|
|
40
|
+
users?: XUser[];
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
type UrlEntity = {
|
|
44
|
+
start: number;
|
|
45
|
+
end: number;
|
|
46
|
+
url: string;
|
|
47
|
+
display_url: string;
|
|
48
|
+
expanded_url: string;
|
|
49
|
+
};
|
|
50
|
+
type HashtagEntity = {
|
|
51
|
+
start: number;
|
|
52
|
+
end: number;
|
|
53
|
+
tag: string;
|
|
54
|
+
};
|
|
55
|
+
type MentionEntity = {
|
|
56
|
+
start: number;
|
|
57
|
+
end: string;
|
|
58
|
+
username: string;
|
|
59
|
+
};
|
|
60
|
+
interface XToken extends OAuth2Token {
|
|
61
|
+
token_type: string;
|
|
62
|
+
expires_in: number;
|
|
63
|
+
access_token: string;
|
|
64
|
+
scope: string;
|
|
65
|
+
refresh_token: string;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { XOptions, XToken, XUser, XUserInfo, createXProvider, x };
|
|
69
|
+
//# sourceMappingURL=x.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x.d.mts","names":[],"sources":["../../../src/oauth2/provider/x.ts"],"mappings":";;UAUiB;EACf,aAAa;;iBAaC,gBAAgB,UAAU,WAAW;cAwFxC,GAAC;KAET;UA2BY;EACf;EACA;EACA;EACA;EACA;EACA;IACE;MAAO,MAAM;;IACb;MACE,UAAU;MACV,UAAU;MACV,UAAU;;;EAGd;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf,MAAM;EACN;IAAa;MAAW;MAAY;;IAAkB,QAAQ;;;KAG3D;EACH;EACA;EACA;EACA;EACA;;KAEG;EAAkB;EAAe;EAAa;;KAC9C;EAAkB;EAAe;EAAa;;UAElC,eAAe;EAC9B;EACA;EACA;EACA;EACA"}
|
|
@@ -1,108 +1,104 @@
|
|
|
1
|
-
// src/oauth2/provider/x.ts
|
|
2
|
-
import { invariant } from "@shware/utils";
|
|
3
1
|
import { OAuth2Error } from "../error.mjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"username",
|
|
16
|
-
"location",
|
|
17
|
-
"verified"
|
|
2
|
+
import { createAuthorizationUri, exchangeAuthorizationCode, refreshAccessToken, revokeToken } from "./common.mjs";
|
|
3
|
+
import { invariant } from "@shware/utils";
|
|
4
|
+
//#region src/oauth2/provider/x.ts
|
|
5
|
+
const defaultUserFields = [
|
|
6
|
+
"id",
|
|
7
|
+
"name",
|
|
8
|
+
"profile_image_url",
|
|
9
|
+
"url",
|
|
10
|
+
"username",
|
|
11
|
+
"location",
|
|
12
|
+
"verified"
|
|
18
13
|
];
|
|
19
14
|
function createXProvider(options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
15
|
+
return {
|
|
16
|
+
authorizationUri: "https://x.com/i/oauth2/authorize",
|
|
17
|
+
tokenUri: "https://api.x.com/2/oauth2/token",
|
|
18
|
+
tokenRefreshUri: "https://api.x.com/2/oauth2/token",
|
|
19
|
+
tokenRevokeUri: "https://api.x.com/2/oauth2/revoke",
|
|
20
|
+
userInfoUri: "https://api.x.com/2/users/me",
|
|
21
|
+
defaultScope: [
|
|
22
|
+
"users.read",
|
|
23
|
+
"tweet.read",
|
|
24
|
+
"offline.access"
|
|
25
|
+
],
|
|
26
|
+
createAuthorizationUri(params) {
|
|
27
|
+
if (!params.pkce) throw new Error("pkce is required for x");
|
|
28
|
+
return createAuthorizationUri({
|
|
29
|
+
...params,
|
|
30
|
+
scope: params.scope ?? this.defaultScope,
|
|
31
|
+
authorizationUri: this.authorizationUri
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
async exchangeAuthorizationCode(params) {
|
|
35
|
+
if (!params.pkce) throw new Error("pkce is required for x");
|
|
36
|
+
const response = await exchangeAuthorizationCode({
|
|
37
|
+
...params,
|
|
38
|
+
tokenUri: this.tokenUri,
|
|
39
|
+
authentication: "basic"
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
const { error, error_description } = await response.json();
|
|
43
|
+
throw new OAuth2Error(response.status, error, error_description);
|
|
44
|
+
}
|
|
45
|
+
return await response.json();
|
|
46
|
+
},
|
|
47
|
+
async getUserInfo({ access_token }) {
|
|
48
|
+
invariant(access_token, "access_token is required");
|
|
49
|
+
invariant(this.userInfoUri, "userInfoUri is required");
|
|
50
|
+
const userFields = options?.userFields ?? defaultUserFields;
|
|
51
|
+
const headers = {
|
|
52
|
+
Accept: "application/json",
|
|
53
|
+
Authorization: `Bearer ${access_token}`
|
|
54
|
+
};
|
|
55
|
+
const url = new URL(this.userInfoUri);
|
|
56
|
+
userFields.forEach((field) => url.searchParams.append("user.fields", field));
|
|
57
|
+
const response = await fetch(this.userInfoUri, { headers });
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
const { errors } = await response.json();
|
|
60
|
+
throw new OAuth2Error(response.status, "invalid_request", `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`);
|
|
61
|
+
}
|
|
62
|
+
const profile = await response.json();
|
|
63
|
+
return {
|
|
64
|
+
data: profile,
|
|
65
|
+
claims: {
|
|
66
|
+
sub: profile.data.id,
|
|
67
|
+
name: profile.data.name,
|
|
68
|
+
picture: profile.data.profile_image_url,
|
|
69
|
+
email: profile.data.email,
|
|
70
|
+
email_verified: profile.data.verified || false,
|
|
71
|
+
preferred_username: profile.data.username,
|
|
72
|
+
profile: `https://x.com/${profile.data.username}`,
|
|
73
|
+
website: profile.data.url
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
async refreshAccessToken(params) {
|
|
78
|
+
invariant(this.tokenRefreshUri, "tokenRefreshUri is required");
|
|
79
|
+
const response = await refreshAccessToken({
|
|
80
|
+
...params,
|
|
81
|
+
tokenUri: this.tokenRefreshUri,
|
|
82
|
+
authentication: "basic"
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
const { error, error_description } = await response.json();
|
|
86
|
+
throw new OAuth2Error(response.status, error, error_description);
|
|
87
|
+
}
|
|
88
|
+
return await response.json();
|
|
89
|
+
},
|
|
90
|
+
async revokeToken(params) {
|
|
91
|
+
invariant(this.tokenRevokeUri, "tokenRevokeUri is required");
|
|
92
|
+
return revokeToken({
|
|
93
|
+
...params,
|
|
94
|
+
tokenRevokeUri: this.tokenRevokeUri,
|
|
95
|
+
authentication: "basic"
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
102
99
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
};
|
|
100
|
+
const x = createXProvider();
|
|
101
|
+
//#endregion
|
|
102
|
+
export { createXProvider, x };
|
|
103
|
+
|
|
108
104
|
//# sourceMappingURL=x.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { OAuth2Token, Provider } from '../types';\nimport {\n createAuthorizationUri,\n exchangeAuthorizationCode,\n refreshAccessToken,\n revokeToken,\n} from './common';\n\nexport interface XOptions {\n userFields?: UserField[];\n}\n\nconst defaultUserFields = [\n 'id',\n 'name',\n 'profile_image_url',\n 'url',\n 'username',\n 'location',\n 'verified',\n];\n\nexport function createXProvider(options?: XOptions): Provider {\n return {\n authorizationUri: 'https://x.com/i/oauth2/authorize',\n tokenUri: 'https://api.x.com/2/oauth2/token',\n tokenRefreshUri: 'https://api.x.com/2/oauth2/token',\n tokenRevokeUri: 'https://api.x.com/2/oauth2/revoke',\n // https://docs.x.com/x-api/users/user-lookup-me\n userInfoUri: 'https://api.x.com/2/users/me',\n defaultScope: ['users.read', 'tweet.read', 'offline.access'],\n createAuthorizationUri(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n const response = await exchangeAuthorizationCode({\n ...params,\n tokenUri: this.tokenUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async getUserInfo({ access_token }) {\n invariant(access_token, 'access_token is required');\n invariant(this.userInfoUri, 'userInfoUri is required');\n\n const userFields = options?.userFields ?? defaultUserFields;\n const headers = { Accept: 'application/json', Authorization: `Bearer ${access_token}` };\n\n const url = new URL(this.userInfoUri);\n userFields.forEach((field) => url.searchParams.append('user.fields', field));\n\n const response = await fetch(this.userInfoUri, { headers });\n if (!response.ok) {\n const { errors } = (await response.json()) as XAPIErrorResponse;\n throw new OAuth2Error(\n response.status,\n 'invalid_request',\n `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`\n );\n }\n const profile = (await response.json()) as XUserInfo;\n return {\n data: profile,\n claims: {\n sub: profile.data.id,\n name: profile.data.name,\n picture: profile.data.profile_image_url,\n email: profile.data.email,\n email_verified: profile.data.verified || false,\n preferred_username: profile.data.username,\n profile: `https://x.com/${profile.data.username}`,\n website: profile.data.url,\n },\n };\n },\n async refreshAccessToken(params) {\n invariant(this.tokenRefreshUri, 'tokenRefreshUri is required');\n const response = await refreshAccessToken({\n ...params,\n tokenUri: this.tokenRefreshUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async revokeToken(params) {\n invariant(this.tokenRevokeUri, 'tokenRevokeUri is required');\n return revokeToken({\n ...params,\n tokenRevokeUri: this.tokenRevokeUri,\n authentication: 'basic',\n });\n },\n };\n}\n\nexport const x = createXProvider();\n\ntype UserField =\n | 'affiliation'\n | 'connection_status'\n | 'created_at'\n | 'description'\n | 'entities'\n | 'id'\n | 'is_identity_verified'\n | 'location'\n | 'most_recent_tweet_id'\n | 'name'\n | 'parody'\n | 'pinned_tweet_id'\n | 'profile_banner_url'\n | 'profile_image_url'\n | 'protected'\n | 'public_metrics'\n | 'receives_your_dm'\n | 'subscription'\n | 'subscription_type'\n | 'url'\n | 'username'\n | 'verified'\n | 'verified_followers_count'\n | 'verified_type'\n | 'withheld';\n\nexport interface XUser {\n id: string;\n name: string;\n email?: string;\n username: string;\n location?: string;\n entities?: {\n url: { urls: UrlEntity[] };\n description: {\n hashtags: HashtagEntity[];\n cashtags: HashtagEntity[];\n mentions: MentionEntity[];\n };\n };\n verified?: boolean;\n description?: string;\n url?: string;\n profile_image_url?: string;\n protected?: boolean;\n pinned_tweet_id?: string;\n created_at?: string;\n}\n\nexport interface XUserInfo {\n data: XUser;\n includes?: { tweets?: { id: string; text: string }[]; users?: XUser[] };\n}\n\ntype UrlEntity = {\n start: number;\n end: number;\n url: string;\n display_url: string;\n expanded_url: string;\n};\ntype HashtagEntity = { start: number; end: number; tag: string };\ntype MentionEntity = { start: number; end: string; username: string };\n\nexport interface XToken extends OAuth2Token {\n token_type: string;\n expires_in: number;\n access_token: string;\n scope: string;\n refresh_token: string;\n}\n\ntype XErrorResponse = { error: string; error_description: string };\ntype XAPIErrorResponse = {\n errors: { title: string; type: string; detail?: string; status?: number }[];\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"x.mjs","names":[],"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { OAuth2Token, Provider } from '../types';\nimport {\n createAuthorizationUri,\n exchangeAuthorizationCode,\n refreshAccessToken,\n revokeToken,\n} from './common';\n\nexport interface XOptions {\n userFields?: UserField[];\n}\n\nconst defaultUserFields = [\n 'id',\n 'name',\n 'profile_image_url',\n 'url',\n 'username',\n 'location',\n 'verified',\n];\n\nexport function createXProvider(options?: XOptions): Provider {\n return {\n authorizationUri: 'https://x.com/i/oauth2/authorize',\n tokenUri: 'https://api.x.com/2/oauth2/token',\n tokenRefreshUri: 'https://api.x.com/2/oauth2/token',\n tokenRevokeUri: 'https://api.x.com/2/oauth2/revoke',\n // https://docs.x.com/x-api/users/user-lookup-me\n userInfoUri: 'https://api.x.com/2/users/me',\n defaultScope: ['users.read', 'tweet.read', 'offline.access'],\n createAuthorizationUri(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n const response = await exchangeAuthorizationCode({\n ...params,\n tokenUri: this.tokenUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async getUserInfo({ access_token }) {\n invariant(access_token, 'access_token is required');\n invariant(this.userInfoUri, 'userInfoUri is required');\n\n const userFields = options?.userFields ?? defaultUserFields;\n const headers = { Accept: 'application/json', Authorization: `Bearer ${access_token}` };\n\n const url = new URL(this.userInfoUri);\n userFields.forEach((field) => url.searchParams.append('user.fields', field));\n\n const response = await fetch(this.userInfoUri, { headers });\n if (!response.ok) {\n const { errors } = (await response.json()) as XAPIErrorResponse;\n throw new OAuth2Error(\n response.status,\n 'invalid_request',\n `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`\n );\n }\n const profile = (await response.json()) as XUserInfo;\n return {\n data: profile,\n claims: {\n sub: profile.data.id,\n name: profile.data.name,\n picture: profile.data.profile_image_url,\n email: profile.data.email,\n email_verified: profile.data.verified || false,\n preferred_username: profile.data.username,\n profile: `https://x.com/${profile.data.username}`,\n website: profile.data.url,\n },\n };\n },\n async refreshAccessToken(params) {\n invariant(this.tokenRefreshUri, 'tokenRefreshUri is required');\n const response = await refreshAccessToken({\n ...params,\n tokenUri: this.tokenRefreshUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async revokeToken(params) {\n invariant(this.tokenRevokeUri, 'tokenRevokeUri is required');\n return revokeToken({\n ...params,\n tokenRevokeUri: this.tokenRevokeUri,\n authentication: 'basic',\n });\n },\n };\n}\n\nexport const x = createXProvider();\n\ntype UserField =\n | 'affiliation'\n | 'connection_status'\n | 'created_at'\n | 'description'\n | 'entities'\n | 'id'\n | 'is_identity_verified'\n | 'location'\n | 'most_recent_tweet_id'\n | 'name'\n | 'parody'\n | 'pinned_tweet_id'\n | 'profile_banner_url'\n | 'profile_image_url'\n | 'protected'\n | 'public_metrics'\n | 'receives_your_dm'\n | 'subscription'\n | 'subscription_type'\n | 'url'\n | 'username'\n | 'verified'\n | 'verified_followers_count'\n | 'verified_type'\n | 'withheld';\n\nexport interface XUser {\n id: string;\n name: string;\n email?: string;\n username: string;\n location?: string;\n entities?: {\n url: { urls: UrlEntity[] };\n description: {\n hashtags: HashtagEntity[];\n cashtags: HashtagEntity[];\n mentions: MentionEntity[];\n };\n };\n verified?: boolean;\n description?: string;\n url?: string;\n profile_image_url?: string;\n protected?: boolean;\n pinned_tweet_id?: string;\n created_at?: string;\n}\n\nexport interface XUserInfo {\n data: XUser;\n includes?: { tweets?: { id: string; text: string }[]; users?: XUser[] };\n}\n\ntype UrlEntity = {\n start: number;\n end: number;\n url: string;\n display_url: string;\n expanded_url: string;\n};\ntype HashtagEntity = { start: number; end: number; tag: string };\ntype MentionEntity = { start: number; end: string; username: string };\n\nexport interface XToken extends OAuth2Token {\n token_type: string;\n expires_in: number;\n access_token: string;\n scope: string;\n refresh_token: string;\n}\n\ntype XErrorResponse = { error: string; error_description: string };\ntype XAPIErrorResponse = {\n errors: { title: string; type: string; detail?: string; status?: number }[];\n};\n"],"mappings":";;;;AAcA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAgB,gBAAgB,SAA8B;CAC5D,OAAO;EACL,kBAAkB;EAClB,UAAU;EACV,iBAAiB;EACjB,gBAAgB;EAEhB,aAAa;EACb,cAAc;GAAC;GAAc;GAAc;EAAgB;EAC3D,uBAAuB,QAAQ;GAC7B,IAAI,CAAC,OAAO,MAAM,MAAM,IAAI,MAAM,wBAAwB;GAC1D,OAAO,uBAAuB;IAC5B,GAAG;IACH,OAAO,OAAO,SAAS,KAAK;IAC5B,kBAAkB,KAAK;GACzB,CAAC;EACH;EACA,MAAM,0BAA0B,QAAQ;GACtC,IAAI,CAAC,OAAO,MAAM,MAAM,IAAI,MAAM,wBAAwB;GAC1D,MAAM,WAAW,MAAM,0BAA0B;IAC/C,GAAG;IACH,UAAU,KAAK;IACf,gBAAgB;GAClB,CAAC;GACD,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,OAAO,sBAAuB,MAAM,SAAS,KAAK;IAC1D,MAAM,IAAI,YAAY,SAAS,QAAQ,OAAO,iBAAiB;GACjE;GACA,OAAQ,MAAM,SAAS,KAAK;EAC9B;EACA,MAAM,YAAY,EAAE,gBAAgB;GAClC,UAAU,cAAc,0BAA0B;GAClD,UAAU,KAAK,aAAa,yBAAyB;GAErD,MAAM,aAAa,SAAS,cAAc;GAC1C,MAAM,UAAU;IAAE,QAAQ;IAAoB,eAAe,UAAU;GAAe;GAEtF,MAAM,MAAM,IAAI,IAAI,KAAK,WAAW;GACpC,WAAW,SAAS,UAAU,IAAI,aAAa,OAAO,eAAe,KAAK,CAAC;GAE3E,MAAM,WAAW,MAAM,MAAM,KAAK,aAAa,EAAE,QAAQ,CAAC;GAC1D,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,WAAY,MAAM,SAAS,KAAK;IACxC,MAAM,IAAI,YACR,SAAS,QACT,mBACA,8BAA8B,OAAO,GAAG,CAAC,CAAC,EAAE,UAAU,OAAO,GAAG,CAAC,CAAC,EAAE,OACtE;GACF;GACA,MAAM,UAAW,MAAM,SAAS,KAAK;GACrC,OAAO;IACL,MAAM;IACN,QAAQ;KACN,KAAK,QAAQ,KAAK;KAClB,MAAM,QAAQ,KAAK;KACnB,SAAS,QAAQ,KAAK;KACtB,OAAO,QAAQ,KAAK;KACpB,gBAAgB,QAAQ,KAAK,YAAY;KACzC,oBAAoB,QAAQ,KAAK;KACjC,SAAS,iBAAiB,QAAQ,KAAK;KACvC,SAAS,QAAQ,KAAK;IACxB;GACF;EACF;EACA,MAAM,mBAAmB,QAAQ;GAC/B,UAAU,KAAK,iBAAiB,6BAA6B;GAC7D,MAAM,WAAW,MAAM,mBAAmB;IACxC,GAAG;IACH,UAAU,KAAK;IACf,gBAAgB;GAClB,CAAC;GACD,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,OAAO,sBAAuB,MAAM,SAAS,KAAK;IAC1D,MAAM,IAAI,YAAY,SAAS,QAAQ,OAAO,iBAAiB;GACjE;GACA,OAAQ,MAAM,SAAS,KAAK;EAC9B;EACA,MAAM,YAAY,QAAQ;GACxB,UAAU,KAAK,gBAAgB,4BAA4B;GAC3D,OAAO,YAAY;IACjB,GAAG;IACH,gBAAgB,KAAK;IACrB,gBAAgB;GAClB,CAAC;EACH;CACF;AACF;AAEA,MAAa,IAAI,gBAAgB"}
|
package/dist/oauth2/types.cjs
CHANGED
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/oauth2/types.ts
|
|
3
|
+
const OIDC_SCOPES = [
|
|
4
|
+
"openid",
|
|
5
|
+
"profile",
|
|
6
|
+
"email",
|
|
7
|
+
"phone",
|
|
8
|
+
"address",
|
|
9
|
+
"offline_access"
|
|
10
|
+
];
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.OIDC_SCOPES = OIDC_SCOPES;
|
|
19
13
|
|
|
20
|
-
// src/oauth2/types.ts
|
|
21
|
-
var types_exports = {};
|
|
22
|
-
__export(types_exports, {
|
|
23
|
-
OidcScopes: () => OidcScopes
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(types_exports);
|
|
26
|
-
var OidcScopes = /* @__PURE__ */ ((OidcScopes2) => {
|
|
27
|
-
OidcScopes2["openid"] = "openid";
|
|
28
|
-
OidcScopes2["profile"] = "profile";
|
|
29
|
-
OidcScopes2["email"] = "email";
|
|
30
|
-
OidcScopes2["phone"] = "phone";
|
|
31
|
-
OidcScopes2["address"] = "address";
|
|
32
|
-
OidcScopes2["offline_access"] = "offline_access";
|
|
33
|
-
return OidcScopes2;
|
|
34
|
-
})(OidcScopes || {});
|
|
35
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
-
0 && (module.exports = {
|
|
37
|
-
OidcScopes
|
|
38
|
-
});
|
|
39
14
|
//# sourceMappingURL=types.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/oauth2/types.ts"],"sourcesContent":["// reference: https://datatracker.ietf.org/doc/html/rfc7636\nexport interface PkceParameters {\n code_verifier: string;\n code_challenge: string;\n code_challenge_method: 'S256' | 'plain';\n}\n\nexport interface OAuth2AuthorizationRequest {\n state: string;\n registrationId: string;\n authorizationRequestUri: string;\n additionalParameters: PkceParameters;\n}\n\ninterface CreateAuthorizationUriParams {\n state: string;\n clientId: string;\n redirectUri: string;\n scope: string[] | undefined;\n pkce?: Omit<PkceParameters, 'code_verifier'>;\n}\n\nexport interface ExchangeCodeParams {\n code: string;\n clientId: string;\n clientSecret: string;\n redirectUri: string;\n pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;\n}\n\nexport interface RefreshTokenParams {\n clientId: string;\n clientSecret: string;\n refreshToken: string;\n}\n\nexport interface RevokeTokenParams {\n token: string;\n clientId: string;\n clientSecret: string;\n}\n\nexport interface LoginOAuth2NativeParams {\n clientId: string;\n clientSecret: string;\n redirectUri: string;\n pkce?: PkceParameters;\n credentials: NativeCredential;\n}\n\n// reference: https://datatracker.ietf.org/doc/html/rfc6749#section-5.1\nexport interface OAuth2Token {\n /**\n * REQUIRED.\n * The access token issued by the authorization server.\n */\n access_token: string;\n\n /**\n * REQUIRED.\n * The type of the token issued as described in Section 7.1. Value is case insensitive.\n */\n token_type: 'Bearer' | 'bearer' | 'mac' | (string & {});\n\n /**\n * RECOMMENDED.\n * The lifetime in seconds of the access token. For example, the value \"3600\" denotes that the\n * access token will expire in one hour from the time the response was generated. If omitted, the\n * authorization server SHOULD provide the expiration time via other means or document the default\n * value.\n */\n expires_in?: number;\n\n /**\n * OPTIONAL.\n * The refresh token, which can be used to obtain new access tokens using the same authorization\n * grant as described in Section 6.\n */\n refresh_token?: string;\n\n /**\n * OPTIONAL.\n * If identical to the scope requested by the client; otherwise, REQUIRED. The scope of the\n * access token as described by Section 3.3.\n */\n scope?: string;\n\n id_token?: string;\n\n [key: string]: unknown;\n}\n\nexport interface OidcToken extends OAuth2Token {\n id_token: string;\n}\n\nexport type NativeCredential = {\n state?: string;\n code?: string;\n client_id?: string;\n redirect_uri?: string;\n id_token?: string;\n access_token?: string;\n};\n\nexport
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/oauth2/types.ts"],"sourcesContent":["// reference: https://datatracker.ietf.org/doc/html/rfc7636\nexport interface PkceParameters {\n code_verifier: string;\n code_challenge: string;\n code_challenge_method: 'S256' | 'plain';\n}\n\nexport interface OAuth2AuthorizationRequest {\n state: string;\n registrationId: string;\n authorizationRequestUri: string;\n additionalParameters: PkceParameters;\n}\n\ninterface CreateAuthorizationUriParams {\n state: string;\n clientId: string;\n redirectUri: string;\n scope: string[] | undefined;\n pkce?: Omit<PkceParameters, 'code_verifier'>;\n}\n\nexport interface ExchangeCodeParams {\n code: string;\n clientId: string;\n clientSecret: string;\n redirectUri: string;\n pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;\n}\n\nexport interface RefreshTokenParams {\n clientId: string;\n clientSecret: string;\n refreshToken: string;\n}\n\nexport interface RevokeTokenParams {\n token: string;\n clientId: string;\n clientSecret: string;\n}\n\nexport interface LoginOAuth2NativeParams {\n clientId: string;\n clientSecret: string;\n redirectUri: string;\n pkce?: PkceParameters;\n credentials: NativeCredential;\n}\n\n// reference: https://datatracker.ietf.org/doc/html/rfc6749#section-5.1\nexport interface OAuth2Token {\n /**\n * REQUIRED.\n * The access token issued by the authorization server.\n */\n access_token: string;\n\n /**\n * REQUIRED.\n * The type of the token issued as described in Section 7.1. Value is case insensitive.\n */\n token_type: 'Bearer' | 'bearer' | 'mac' | (string & {});\n\n /**\n * RECOMMENDED.\n * The lifetime in seconds of the access token. For example, the value \"3600\" denotes that the\n * access token will expire in one hour from the time the response was generated. If omitted, the\n * authorization server SHOULD provide the expiration time via other means or document the default\n * value.\n */\n expires_in?: number;\n\n /**\n * OPTIONAL.\n * The refresh token, which can be used to obtain new access tokens using the same authorization\n * grant as described in Section 6.\n */\n refresh_token?: string;\n\n /**\n * OPTIONAL.\n * If identical to the scope requested by the client; otherwise, REQUIRED. The scope of the\n * access token as described by Section 3.3.\n */\n scope?: string;\n\n id_token?: string;\n\n [key: string]: unknown;\n}\n\nexport interface OidcToken extends OAuth2Token {\n id_token: string;\n}\n\nexport type NativeCredential = {\n state?: string;\n code?: string;\n client_id?: string;\n redirect_uri?: string;\n id_token?: string;\n access_token?: string;\n};\n\nexport const OIDC_SCOPES = [\n 'openid',\n 'profile',\n 'email',\n 'phone',\n 'address',\n 'offline_access',\n] as const;\n\nexport type OidcScope = (typeof OIDC_SCOPES)[number];\n\n// https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims\nexport interface StandardClaims {\n sub: string;\n name?: string;\n given_name?: string;\n family_name?: string;\n middle_name?: string;\n nickname?: string;\n preferred_username?: string;\n profile?: string;\n picture?: string;\n website?: string;\n email?: string;\n email_verified?: boolean;\n gender?: 'female' | 'male' | (string & {});\n birthdate?: string; // ISO 8601-1 [ISO8601‑1] YYYY-MM-DD format.\n zoneinfo?: string; // IANA Time Zone Database [IANA.time‑zones]\n locale?: string; // BCP47 [RFC5646] language tag.\n phone_number?: string; // E.164\n phone_number_verified?: boolean;\n address?: {\n formatted: string;\n street_address: string;\n locality: string;\n region: string;\n postal_code: string;\n country: string;\n }; // [RFC8259] JSON object\n updated_at?: number;\n}\n\nexport interface UserInfo<T = unknown> {\n claims: StandardClaims;\n data: T;\n}\n\nexport interface Provider {\n /** Authorization URI for the provider. */\n authorizationUri: string;\n\n /** Token URI for the provider. */\n tokenUri: string;\n\n /** Token revoke URI for the provider. */\n tokenRevokeUri?: string;\n\n /** Token refresh URI for the provider. */\n tokenRefreshUri?: string;\n\n /** User info URI for the provider. */\n userInfoUri?: string;\n\n /** User info authentication method for the provider. */\n userInfoAuthenticationMethod?: string;\n\n /**\n * Name of the attribute that will be used to extract the username from the call to 'userInfoUri'.\n * */\n userNameAttribute?: string;\n\n /** JWK set URI for the provider */\n jwkSetUri?: string;\n\n /**\n * URI that can either be an OpenID Connect discovery endpoint or an OAuth 2.0 Authorization\n * Server Metadata endpoint defined by RFC 8414.\n * */\n issuerUri?: string;\n\n /** Default scopes for the provider. */\n defaultScope: string[];\n\n /** step 1: generate authorization uri and redirect user to it */\n createAuthorizationUri: (params: CreateAuthorizationUriParams) => URL;\n\n /** step 2: exchange code for token */\n exchangeAuthorizationCode: (params: ExchangeCodeParams) => Promise<OAuth2Token>;\n\n /** step 3: get user info */\n getUserInfo: (token: OAuth2Token) => Promise<UserInfo>;\n\n /** others: refresh access token */\n refreshAccessToken?: (params: RefreshTokenParams) => Promise<OAuth2Token>;\n\n /** others: revoke token */\n revokeToken?: (params: RevokeTokenParams) => Promise<void>;\n\n loginOAuth2Native?: (\n params: LoginOAuth2NativeParams\n ) => Promise<{ token: OAuth2Token; userInfo: UserInfo }>;\n}\n\nexport interface OneTapProvider extends Provider {\n getTokenInfo: (id_token: string) => Promise<{ token: OAuth2Token; userInfo: UserInfo }>;\n}\n\nexport interface Registration {\n /**\n * Reference to the OAuth 2.0 provider to use. May reference an element from the 'provider'\n * property or used one of the commonly used providers (google, github, facebook, okta).\n * */\n provider?: string;\n\n /** Client ID for the registration. */\n clientId: string;\n\n /** Client secret of the registration. */\n clientSecret: string;\n\n /** Client authentication method. May be left blank when using a pre-defined provider. */\n clientAuthenticationMethod?: string;\n\n /** Authorization grant type. May be left blank when using a pre-defined provider. */\n authorizationGrantType?:\n | 'authorization_code' // default\n | 'client_credentials'\n | 'device_code'\n | 'jwt_bearer'\n // Deprecated. The latest OAuth 2.0 Security Best Current Practice disallows the use of the\n // Resource Owner Password Credentials grant.\n | 'password'\n | 'refresh_token'\n | 'token_exchange';\n\n /** Redirect URI. May be left blank when using a pre-defined provider. */\n redirectUri?: string;\n\n /** Authorization scopes. When left blank the provider's default scopes, if any, will be used. */\n scope?: string[];\n\n /** Client name. May be left blank when using a pre-defined provider. */\n clientName?: string;\n}\n\nexport interface OAuth2ClientConfig {\n baseUri: string;\n errorUri: string;\n successUri: string;\n provider: { [name: string]: Provider | undefined };\n registration:\n | { [name: string]: Registration | undefined }\n | (() => Promise<{ [name: string]: Registration | undefined }>);\n}\n"],"mappings":";;AAyGA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;AACF"}
|