@shware/security 0.4.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.cjs +86 -20
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +8 -2
- package/dist/auth/index.d.ts +8 -2
- package/dist/auth/index.mjs +87 -21
- package/dist/auth/index.mjs.map +1 -1
- package/dist/auth/types.cjs.map +1 -1
- package/dist/auth/types.d.cts +10 -3
- package/dist/auth/types.d.ts +10 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/oauth2/client.cjs +42 -8
- package/dist/oauth2/client.cjs.map +1 -1
- package/dist/oauth2/client.d.cts +35 -12
- package/dist/oauth2/client.d.ts +35 -12
- package/dist/oauth2/client.mjs +42 -8
- package/dist/oauth2/client.mjs.map +1 -1
- package/dist/oauth2/error.cjs.map +1 -1
- package/dist/oauth2/error.d.cts +1 -1
- package/dist/oauth2/error.d.ts +1 -1
- package/dist/oauth2/error.mjs.map +1 -1
- package/dist/oauth2/provider/apple.cjs +21 -5
- package/dist/oauth2/provider/apple.cjs.map +1 -1
- package/dist/oauth2/provider/apple.d.cts +12 -4
- package/dist/oauth2/provider/apple.d.ts +12 -4
- package/dist/oauth2/provider/apple.mjs +19 -4
- package/dist/oauth2/provider/apple.mjs.map +1 -1
- package/dist/oauth2/provider/common.cjs +5 -13
- package/dist/oauth2/provider/common.cjs.map +1 -1
- package/dist/oauth2/provider/common.d.cts +6 -11
- package/dist/oauth2/provider/common.d.ts +6 -11
- package/dist/oauth2/provider/common.mjs +5 -13
- package/dist/oauth2/provider/common.mjs.map +1 -1
- package/dist/oauth2/provider/facebook.cjs +19 -3
- package/dist/oauth2/provider/facebook.cjs.map +1 -1
- package/dist/oauth2/provider/facebook.d.cts +17 -3
- package/dist/oauth2/provider/facebook.d.ts +17 -3
- package/dist/oauth2/provider/facebook.mjs +18 -3
- package/dist/oauth2/provider/facebook.mjs.map +1 -1
- package/dist/oauth2/provider/github.cjs +6 -3
- package/dist/oauth2/provider/github.cjs.map +1 -1
- package/dist/oauth2/provider/github.d.cts +11 -3
- package/dist/oauth2/provider/github.d.ts +11 -3
- package/dist/oauth2/provider/github.mjs +5 -3
- package/dist/oauth2/provider/github.mjs.map +1 -1
- package/dist/oauth2/provider/google.cjs +17 -1
- package/dist/oauth2/provider/google.cjs.map +1 -1
- package/dist/oauth2/provider/google.d.cts +11 -4
- package/dist/oauth2/provider/google.d.ts +11 -4
- package/dist/oauth2/provider/google.mjs +16 -1
- package/dist/oauth2/provider/google.mjs.map +1 -1
- package/dist/oauth2/provider/x.cjs +16 -4
- package/dist/oauth2/provider/x.cjs.map +1 -1
- package/dist/oauth2/provider/x.d.cts +11 -3
- package/dist/oauth2/provider/x.d.ts +11 -3
- package/dist/oauth2/provider/x.mjs +15 -4
- package/dist/oauth2/provider/x.mjs.map +1 -1
- package/dist/oauth2/types.cjs +20 -0
- package/dist/oauth2/types.cjs.map +1 -1
- package/dist/oauth2/types.d.cts +73 -12
- package/dist/oauth2/types.d.ts +73 -12
- package/dist/oauth2/types.mjs +13 -0
- package/dist/oauth2/types.mjs.map +1 -1
- package/dist/session/redis-session.cjs +21 -0
- package/dist/session/redis-session.cjs.map +1 -1
- package/dist/session/redis-session.d.cts +4 -0
- package/dist/session/redis-session.d.ts +4 -0
- package/dist/session/redis-session.mjs +21 -0
- package/dist/session/redis-session.mjs.map +1 -1
- package/dist/session/types.cjs.map +1 -1
- package/dist/session/types.d.cts +3 -0
- package/dist/session/types.d.ts +3 -0
- package/dist/utils/http.cjs +2 -2
- package/dist/utils/http.cjs.map +1 -1
- package/dist/utils/http.mjs +2 -2
- package/dist/utils/http.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/oidc/index.cjs +0 -39
- package/dist/oidc/index.cjs.map +0 -1
- package/dist/oidc/index.d.cts +0 -10
- package/dist/oidc/index.d.ts +0 -10
- package/dist/oidc/index.mjs +0 -14
- package/dist/oidc/index.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/github.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { Provider } from '../types';\nimport { OAuth2Error } from '../error';\nimport { createAuthorizationUri, exchangeAuthorizationCode } from './common';\n\nexport function
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth2/provider/github.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { OAuth2Token, Provider } from '../types';\nimport { OAuth2Error } from '../error';\nimport { createAuthorizationUri, exchangeAuthorizationCode } from './common';\n\nexport function createGithubProvider(): Provider {\n return {\n authorizationUri: 'https://github.com/login/oauth/authorize',\n tokenUri: 'https://github.com/login/oauth/access_token',\n userInfoUri: 'https://api.github.com/user',\n userNameAttribute: 'id',\n defaultScope: ['user:email'],\n createAuthorizationUri({ pkce, ...params }) {\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode({ pkce, ...params }) {\n const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as GithubErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as GithubToken;\n },\n async getUserInfo({ access_token }) {\n invariant(access_token, 'access_token is required');\n invariant(this.userInfoUri, 'userInfoUri is required');\n const headers = { Accept: 'application/json', Authorization: `Bearer ${access_token}` };\n const response = await fetch(this.userInfoUri, { headers });\n if (!response.ok) {\n throw new OAuth2Error(response.status, 'invalid_request', 'Failed to fetch user info');\n }\n const data = (await response.json()) as GithubUserInfo;\n const emailResponse = await fetch('https://api.github.com/user/emails', { headers });\n if (!emailResponse.ok) {\n throw new OAuth2Error(\n emailResponse.status,\n 'invalid_request',\n 'Failed to fetch user email'\n );\n }\n const emails = (await emailResponse.json()) as GithubEmail[];\n data.email = emails.find((email) => email.primary)?.email || data.email;\n const email_verified = emails.find((email) => email.email === data.email)?.verified || false;\n return {\n data,\n claims: {\n sub: data.id,\n name: data.name || data.login,\n email_verified,\n email: data.email,\n picture: data.avatar_url,\n profile: data.html_url,\n website: data.html_url,\n updated_at: data.updated_at ? Date.parse(data.updated_at) : undefined,\n },\n };\n },\n };\n}\n\nexport const github = createGithubProvider();\n\nexport interface GithubUserInfo {\n login: string;\n id: string;\n node_id: string;\n avatar_url: string;\n gravatar_id: string;\n url: string;\n html_url: string;\n followers_url: string;\n following_url: string;\n gists_url: string;\n starred_url: string;\n subscriptions_url: string;\n organizations_url: string;\n repos_url: string;\n events_url: string;\n received_events_url: string;\n type: string;\n site_admin: boolean;\n name: string;\n company: string;\n blog: string;\n location: string;\n email: string;\n hireable: boolean;\n bio: string;\n twitter_username: string;\n public_repos: string;\n public_gists: string;\n followers: string;\n following: string;\n created_at: string;\n updated_at: string;\n private_gists: string;\n total_private_repos: string;\n owned_private_repos: string;\n disk_usage: string;\n collaborators: string;\n two_factor_authentication: boolean;\n plan: {\n name: string;\n space: string;\n private_repos: string;\n collaborators: string;\n };\n}\n\ninterface GithubEmail {\n email: string;\n primary: boolean;\n verified: boolean;\n visibility: 'public' | 'private';\n}\n\nexport interface GithubToken extends OAuth2Token {\n access_token: string;\n token_type: string;\n scope: string;\n expires_in: number;\n refresh_token: string;\n}\n\ninterface GithubErrorResponse {\n error: string;\n error_description: string;\n error_uri: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAsB;AAEtB,mBAA4B;AAC5B,oBAAkE;AAE3D,SAAS,uBAAiC;AAC/C,SAAO;AAAA,IACL,kBAAkB;AAAA,IAClB,UAAU;AAAA,IACV,aAAa;AAAA,IACb,mBAAmB;AAAA,IACnB,cAAc,CAAC,YAAY;AAAA,IAC3B,uBAAuB,EAAE,MAAM,GAAG,OAAO,GA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QAAQ;AAAA,UACN,KAAK,KAAK;AAAA,UACV,MAAM,KAAK,QAAQ,KAAK;AAAA,UACxB;AAAA,UACA,OAAO,KAAK;AAAA,UACZ,SAAS,KAAK;AAAA,UACd,SAAS,KAAK;AAAA,UACd,SAAS,KAAK;AAAA,UACd,YAAY,KAAK,aAAa,KAAK,MAAM,KAAK,UAAU,IAAI;AAAA,QAC9D;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,SAAS,qBAAqB;","names":["invariant"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Provider } from '../types.cjs';
|
|
1
|
+
import { Provider, OAuth2Token } from '../types.cjs';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
3
|
+
declare function createGithubProvider(): Provider;
|
|
4
|
+
declare const github: Provider;
|
|
4
5
|
interface GithubUserInfo {
|
|
5
6
|
login: string;
|
|
6
7
|
id: string;
|
|
@@ -47,5 +48,12 @@ interface GithubUserInfo {
|
|
|
47
48
|
collaborators: string;
|
|
48
49
|
};
|
|
49
50
|
}
|
|
51
|
+
interface GithubToken extends OAuth2Token {
|
|
52
|
+
access_token: string;
|
|
53
|
+
token_type: string;
|
|
54
|
+
scope: string;
|
|
55
|
+
expires_in: number;
|
|
56
|
+
refresh_token: string;
|
|
57
|
+
}
|
|
50
58
|
|
|
51
|
-
export { type GithubUserInfo, github };
|
|
59
|
+
export { type GithubToken, type GithubUserInfo, createGithubProvider, github };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Provider } from '../types.js';
|
|
1
|
+
import { Provider, OAuth2Token } from '../types.js';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
3
|
+
declare function createGithubProvider(): Provider;
|
|
4
|
+
declare const github: Provider;
|
|
4
5
|
interface GithubUserInfo {
|
|
5
6
|
login: string;
|
|
6
7
|
id: string;
|
|
@@ -47,5 +48,12 @@ interface GithubUserInfo {
|
|
|
47
48
|
collaborators: string;
|
|
48
49
|
};
|
|
49
50
|
}
|
|
51
|
+
interface GithubToken extends OAuth2Token {
|
|
52
|
+
access_token: string;
|
|
53
|
+
token_type: string;
|
|
54
|
+
scope: string;
|
|
55
|
+
expires_in: number;
|
|
56
|
+
refresh_token: string;
|
|
57
|
+
}
|
|
50
58
|
|
|
51
|
-
export { type GithubUserInfo, github };
|
|
59
|
+
export { type GithubToken, type GithubUserInfo, createGithubProvider, github };
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
import invariant from "tiny-invariant";
|
|
3
3
|
import { OAuth2Error } from "../error.mjs";
|
|
4
4
|
import { createAuthorizationUri, exchangeAuthorizationCode } from "./common.mjs";
|
|
5
|
-
function
|
|
5
|
+
function createGithubProvider() {
|
|
6
6
|
return {
|
|
7
7
|
authorizationUri: "https://github.com/login/oauth/authorize",
|
|
8
8
|
tokenUri: "https://github.com/login/oauth/access_token",
|
|
9
9
|
userInfoUri: "https://api.github.com/user",
|
|
10
10
|
userNameAttribute: "id",
|
|
11
11
|
defaultScope: ["user:email"],
|
|
12
|
-
createAuthorizationUri({
|
|
12
|
+
createAuthorizationUri({ pkce, ...params }) {
|
|
13
13
|
return createAuthorizationUri({
|
|
14
14
|
...params,
|
|
15
15
|
scope: params.scope ?? this.defaultScope,
|
|
16
16
|
authorizationUri: this.authorizationUri
|
|
17
17
|
});
|
|
18
18
|
},
|
|
19
|
-
async exchangeAuthorizationCode({
|
|
19
|
+
async exchangeAuthorizationCode({ pkce, ...params }) {
|
|
20
20
|
const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });
|
|
21
21
|
if (!response.ok) {
|
|
22
22
|
const { error, error_description } = await response.json();
|
|
@@ -60,7 +60,9 @@ function github() {
|
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
+
var github = createGithubProvider();
|
|
63
64
|
export {
|
|
65
|
+
createGithubProvider,
|
|
64
66
|
github
|
|
65
67
|
};
|
|
66
68
|
//# sourceMappingURL=github.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/github.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { Provider } from '../types';\nimport { OAuth2Error } from '../error';\nimport { createAuthorizationUri, exchangeAuthorizationCode } from './common';\n\nexport function
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth2/provider/github.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { OAuth2Token, Provider } from '../types';\nimport { OAuth2Error } from '../error';\nimport { createAuthorizationUri, exchangeAuthorizationCode } from './common';\n\nexport function createGithubProvider(): Provider {\n return {\n authorizationUri: 'https://github.com/login/oauth/authorize',\n tokenUri: 'https://github.com/login/oauth/access_token',\n userInfoUri: 'https://api.github.com/user',\n userNameAttribute: 'id',\n defaultScope: ['user:email'],\n createAuthorizationUri({ pkce, ...params }) {\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode({ pkce, ...params }) {\n const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as GithubErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as GithubToken;\n },\n async getUserInfo({ access_token }) {\n invariant(access_token, 'access_token is required');\n invariant(this.userInfoUri, 'userInfoUri is required');\n const headers = { Accept: 'application/json', Authorization: `Bearer ${access_token}` };\n const response = await fetch(this.userInfoUri, { headers });\n if (!response.ok) {\n throw new OAuth2Error(response.status, 'invalid_request', 'Failed to fetch user info');\n }\n const data = (await response.json()) as GithubUserInfo;\n const emailResponse = await fetch('https://api.github.com/user/emails', { headers });\n if (!emailResponse.ok) {\n throw new OAuth2Error(\n emailResponse.status,\n 'invalid_request',\n 'Failed to fetch user email'\n );\n }\n const emails = (await emailResponse.json()) as GithubEmail[];\n data.email = emails.find((email) => email.primary)?.email || data.email;\n const email_verified = emails.find((email) => email.email === data.email)?.verified || false;\n return {\n data,\n claims: {\n sub: data.id,\n name: data.name || data.login,\n email_verified,\n email: data.email,\n picture: data.avatar_url,\n profile: data.html_url,\n website: data.html_url,\n updated_at: data.updated_at ? Date.parse(data.updated_at) : undefined,\n },\n };\n },\n };\n}\n\nexport const github = createGithubProvider();\n\nexport interface GithubUserInfo {\n login: string;\n id: string;\n node_id: string;\n avatar_url: string;\n gravatar_id: string;\n url: string;\n html_url: string;\n followers_url: string;\n following_url: string;\n gists_url: string;\n starred_url: string;\n subscriptions_url: string;\n organizations_url: string;\n repos_url: string;\n events_url: string;\n received_events_url: string;\n type: string;\n site_admin: boolean;\n name: string;\n company: string;\n blog: string;\n location: string;\n email: string;\n hireable: boolean;\n bio: string;\n twitter_username: string;\n public_repos: string;\n public_gists: string;\n followers: string;\n following: string;\n created_at: string;\n updated_at: string;\n private_gists: string;\n total_private_repos: string;\n owned_private_repos: string;\n disk_usage: string;\n collaborators: string;\n two_factor_authentication: boolean;\n plan: {\n name: string;\n space: string;\n private_repos: string;\n collaborators: string;\n };\n}\n\ninterface GithubEmail {\n email: string;\n primary: boolean;\n verified: boolean;\n visibility: 'public' | 'private';\n}\n\nexport interface GithubToken extends OAuth2Token {\n access_token: string;\n token_type: string;\n scope: string;\n expires_in: number;\n refresh_token: string;\n}\n\ninterface GithubErrorResponse {\n error: string;\n error_description: string;\n error_uri: string;\n}\n"],"mappings":";AAAA,OAAO,eAAe;AAEtB,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB,iCAAiC;AAE3D,SAAS,uBAAiC;AAC/C,SAAO;AAAA,IACL,kBAAkB;AAAA,IAClB,UAAU;AAAA,IACV,aAAa;AAAA,IACb,mBAAmB;AAAA,IACnB,cAAc,CAAC,YAAY;AAAA,IAC3B,uBAAuB,EAAE,MAAM,GAAG,OAAO,GAAG;AAC1C,aAAO,uBAAuB;AAAA,QAC5B,GAAG;AAAA,QACH,OAAO,OAAO,SAAS,KAAK;AAAA,QAC5B,kBAAkB,KAAK;AAAA,MACzB,CAAC;AAAA,I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AA,UACd,SAAS,KAAK;AAAA,UACd,YAAY,KAAK,aAAa,KAAK,MAAM,KAAK,UAAU,IAAI;AAAA,QAC9D;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,SAAS,qBAAqB;","names":[]}
|
|
@@ -30,13 +30,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/oauth2/provider/google.ts
|
|
31
31
|
var google_exports = {};
|
|
32
32
|
__export(google_exports, {
|
|
33
|
+
createGoogleProvider: () => createGoogleProvider,
|
|
33
34
|
google: () => google
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(google_exports);
|
|
36
37
|
var import_tiny_invariant = __toESM(require("tiny-invariant"), 1);
|
|
37
38
|
var import_error = require("../error.cjs");
|
|
38
39
|
var import_common = require("./common.cjs");
|
|
39
|
-
function
|
|
40
|
+
function createGoogleProvider() {
|
|
40
41
|
return {
|
|
41
42
|
authorizationUri: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
42
43
|
tokenUri: "https://oauth2.googleapis.com/token",
|
|
@@ -81,11 +82,26 @@ function google() {
|
|
|
81
82
|
locale: data.locale
|
|
82
83
|
}
|
|
83
84
|
};
|
|
85
|
+
},
|
|
86
|
+
async loginOAuth2Native({ pkce, credentials, ...params }) {
|
|
87
|
+
(0, import_tiny_invariant.default)(credentials.code, "code is required");
|
|
88
|
+
const { code } = credentials;
|
|
89
|
+
const { tokenUri } = this;
|
|
90
|
+
const response = await (0, import_common.exchangeAuthorizationCode)({ code, tokenUri, ...params });
|
|
91
|
+
if (!response.ok) {
|
|
92
|
+
const { error, error_description } = await response.json();
|
|
93
|
+
throw new import_error.OAuth2Error(response.status, error, error_description);
|
|
94
|
+
}
|
|
95
|
+
const token = await response.json();
|
|
96
|
+
const userInfo = await this.getUserInfo(token);
|
|
97
|
+
return { token, userInfo };
|
|
84
98
|
}
|
|
85
99
|
};
|
|
86
100
|
}
|
|
101
|
+
var google = createGoogleProvider();
|
|
87
102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
88
103
|
0 && (module.exports = {
|
|
104
|
+
createGoogleProvider,
|
|
89
105
|
google
|
|
90
106
|
});
|
|
91
107
|
//# sourceMappingURL=google.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/google.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { Provider } from '../types';\nimport { OAuth2Error } from '../error';\nimport { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from './common';\n\nexport function
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth2/provider/google.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { LoginOAuth2NativeParams, OAuth2Token, Provider } from '../types';\nimport { OAuth2Error } from '../error';\nimport { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from './common';\n\nexport function createGoogleProvider(): Provider {\n return {\n authorizationUri: 'https://accounts.google.com/o/oauth2/v2/auth',\n tokenUri: 'https://oauth2.googleapis.com/token',\n userInfoUri: 'https://www.googleapis.com/oauth2/v3/userinfo',\n userNameAttribute: 'sub',\n jwkSetUri: 'https://www.googleapis.com/oauth2/v3/certs',\n // https://developers.google.com/identity/protocols/oauth2/scopes#oauth2\n defaultScope: [\n 'https://www.googleapis.com/auth/userinfo.email',\n 'https://www.googleapis.com/auth/userinfo.profile',\n 'openid',\n ],\n createAuthorizationUri(params) {\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode(params) {\n const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as GoogleErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as GoogleToken;\n },\n async getUserInfo({ id_token }) {\n invariant(id_token, 'id_token is required');\n invariant(this.jwkSetUri, 'jwkSetUri is required');\n const data = await verifyIdToken<GoogleUserInfo>(id_token, this.jwkSetUri);\n return {\n data,\n claims: {\n sub: data.sub,\n name: data.name,\n picture: data.picture,\n email: data.email,\n email_verified: data.email_verified,\n given_name: data.given_name,\n family_name: data.family_name,\n locale: data.locale,\n },\n };\n },\n async loginOAuth2Native({ pkce, credentials, ...params }: LoginOAuth2NativeParams) {\n invariant(credentials.code, 'code is required');\n const { code } = credentials;\n const { tokenUri } = this;\n const response = await exchangeAuthorizationCode({ code, tokenUri, ...params });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as GoogleErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n const token = (await response.json()) as GoogleToken;\n const userInfo = await this.getUserInfo(token);\n return { token, userInfo };\n },\n };\n}\n\nexport const google = createGoogleProvider();\n\nexport interface GoogleUserInfo {\n aud: string;\n azp: string;\n email: string;\n email_verified: boolean;\n exp: number;\n family_name: string;\n given_name: string;\n hd?: string;\n iat: number;\n iss: string;\n jti?: string;\n locale?: string;\n name: string;\n nbf?: number;\n picture: string;\n sub: string;\n}\n\nexport interface GoogleToken extends OAuth2Token {\n access_token: string;\n token_type: string;\n expires_in: number;\n refresh_token: string;\n id_token: string;\n scope: string;\n}\n\n// android,ios has different client_id and redirect_uri\nexport type GoogleAppCredentials = {\n state: string;\n code: string;\n client_id: string;\n redirect_uri: string;\n};\n\nexport interface GoogleErrorResponse {\n error:\n | 'invalid_request'\n | 'invalid_client'\n | 'invalid_grant'\n | 'invalid_token'\n | 'invalid_scope'\n | 'unauthorized_client'\n | 'unsupported_grant_type'\n | 'access_denied'\n | 'server_error';\n error_description: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAsB;AAEtB,mBAA4B;AAC5B,oBAAiF;AAE1E,SAAS,uBAAiC;AAC/C,SAAO;AAAA,IACL,kBAAkB;AAAA,IAClB,UAAU;AAAA,IACV,aAAa;AAAA,IACb,mBAAmB;AAA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C,SAAS,IAAI;AAChB,cAAM,EAAE,OAAO,kBAAkB,IAAK,MAAM,SAAS,KAAK;AAC1D,cAAM,IAAI,yBAAY,SAAS,QAAQ,OAAO,iBAAiB;AAAA,MACjE;AACA,YAAM,QAAS,MAAM,SAAS,KAAK;AACnC,YAAM,WAAW,MAAM,KAAK,YAAY,KAAK;AAC7C,aAAO,EAAE,OAAO,SAAS;AAAA,IAC3B;AAAA,EACF;AACF;AAEO,IAAM,SAAS,qBAAqB;","names":["invariant"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Provider } from '../types.cjs';
|
|
1
|
+
import { Provider, OAuth2Token } from '../types.cjs';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
3
|
+
declare function createGoogleProvider(): Provider;
|
|
4
|
+
declare const google: Provider;
|
|
4
5
|
interface GoogleUserInfo {
|
|
5
6
|
aud: string;
|
|
6
7
|
azp: string;
|
|
@@ -19,7 +20,7 @@ interface GoogleUserInfo {
|
|
|
19
20
|
picture: string;
|
|
20
21
|
sub: string;
|
|
21
22
|
}
|
|
22
|
-
interface
|
|
23
|
+
interface GoogleToken extends OAuth2Token {
|
|
23
24
|
access_token: string;
|
|
24
25
|
token_type: string;
|
|
25
26
|
expires_in: number;
|
|
@@ -27,9 +28,15 @@ interface GoogleOAuth2Token {
|
|
|
27
28
|
id_token: string;
|
|
28
29
|
scope: string;
|
|
29
30
|
}
|
|
31
|
+
type GoogleAppCredentials = {
|
|
32
|
+
state: string;
|
|
33
|
+
code: string;
|
|
34
|
+
client_id: string;
|
|
35
|
+
redirect_uri: string;
|
|
36
|
+
};
|
|
30
37
|
interface GoogleErrorResponse {
|
|
31
38
|
error: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'invalid_token' | 'invalid_scope' | 'unauthorized_client' | 'unsupported_grant_type' | 'access_denied' | 'server_error';
|
|
32
39
|
error_description: string;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
export { type GoogleErrorResponse, type
|
|
42
|
+
export { type GoogleAppCredentials, type GoogleErrorResponse, type GoogleToken, type GoogleUserInfo, createGoogleProvider, google };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Provider } from '../types.js';
|
|
1
|
+
import { Provider, OAuth2Token } from '../types.js';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
3
|
+
declare function createGoogleProvider(): Provider;
|
|
4
|
+
declare const google: Provider;
|
|
4
5
|
interface GoogleUserInfo {
|
|
5
6
|
aud: string;
|
|
6
7
|
azp: string;
|
|
@@ -19,7 +20,7 @@ interface GoogleUserInfo {
|
|
|
19
20
|
picture: string;
|
|
20
21
|
sub: string;
|
|
21
22
|
}
|
|
22
|
-
interface
|
|
23
|
+
interface GoogleToken extends OAuth2Token {
|
|
23
24
|
access_token: string;
|
|
24
25
|
token_type: string;
|
|
25
26
|
expires_in: number;
|
|
@@ -27,9 +28,15 @@ interface GoogleOAuth2Token {
|
|
|
27
28
|
id_token: string;
|
|
28
29
|
scope: string;
|
|
29
30
|
}
|
|
31
|
+
type GoogleAppCredentials = {
|
|
32
|
+
state: string;
|
|
33
|
+
code: string;
|
|
34
|
+
client_id: string;
|
|
35
|
+
redirect_uri: string;
|
|
36
|
+
};
|
|
30
37
|
interface GoogleErrorResponse {
|
|
31
38
|
error: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'invalid_token' | 'invalid_scope' | 'unauthorized_client' | 'unsupported_grant_type' | 'access_denied' | 'server_error';
|
|
32
39
|
error_description: string;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
export { type GoogleErrorResponse, type
|
|
42
|
+
export { type GoogleAppCredentials, type GoogleErrorResponse, type GoogleToken, type GoogleUserInfo, createGoogleProvider, google };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import invariant from "tiny-invariant";
|
|
3
3
|
import { OAuth2Error } from "../error.mjs";
|
|
4
4
|
import { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from "./common.mjs";
|
|
5
|
-
function
|
|
5
|
+
function createGoogleProvider() {
|
|
6
6
|
return {
|
|
7
7
|
authorizationUri: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
8
8
|
tokenUri: "https://oauth2.googleapis.com/token",
|
|
@@ -47,10 +47,25 @@ function google() {
|
|
|
47
47
|
locale: data.locale
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
+
},
|
|
51
|
+
async loginOAuth2Native({ pkce, credentials, ...params }) {
|
|
52
|
+
invariant(credentials.code, "code is required");
|
|
53
|
+
const { code } = credentials;
|
|
54
|
+
const { tokenUri } = this;
|
|
55
|
+
const response = await exchangeAuthorizationCode({ code, tokenUri, ...params });
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
const { error, error_description } = await response.json();
|
|
58
|
+
throw new OAuth2Error(response.status, error, error_description);
|
|
59
|
+
}
|
|
60
|
+
const token = await response.json();
|
|
61
|
+
const userInfo = await this.getUserInfo(token);
|
|
62
|
+
return { token, userInfo };
|
|
50
63
|
}
|
|
51
64
|
};
|
|
52
65
|
}
|
|
66
|
+
var google = createGoogleProvider();
|
|
53
67
|
export {
|
|
68
|
+
createGoogleProvider,
|
|
54
69
|
google
|
|
55
70
|
};
|
|
56
71
|
//# sourceMappingURL=google.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/google.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { Provider } from '../types';\nimport { OAuth2Error } from '../error';\nimport { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from './common';\n\nexport function
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth2/provider/google.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { LoginOAuth2NativeParams, OAuth2Token, Provider } from '../types';\nimport { OAuth2Error } from '../error';\nimport { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from './common';\n\nexport function createGoogleProvider(): Provider {\n return {\n authorizationUri: 'https://accounts.google.com/o/oauth2/v2/auth',\n tokenUri: 'https://oauth2.googleapis.com/token',\n userInfoUri: 'https://www.googleapis.com/oauth2/v3/userinfo',\n userNameAttribute: 'sub',\n jwkSetUri: 'https://www.googleapis.com/oauth2/v3/certs',\n // https://developers.google.com/identity/protocols/oauth2/scopes#oauth2\n defaultScope: [\n 'https://www.googleapis.com/auth/userinfo.email',\n 'https://www.googleapis.com/auth/userinfo.profile',\n 'openid',\n ],\n createAuthorizationUri(params) {\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode(params) {\n const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as GoogleErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as GoogleToken;\n },\n async getUserInfo({ id_token }) {\n invariant(id_token, 'id_token is required');\n invariant(this.jwkSetUri, 'jwkSetUri is required');\n const data = await verifyIdToken<GoogleUserInfo>(id_token, this.jwkSetUri);\n return {\n data,\n claims: {\n sub: data.sub,\n name: data.name,\n picture: data.picture,\n email: data.email,\n email_verified: data.email_verified,\n given_name: data.given_name,\n family_name: data.family_name,\n locale: data.locale,\n },\n };\n },\n async loginOAuth2Native({ pkce, credentials, ...params }: LoginOAuth2NativeParams) {\n invariant(credentials.code, 'code is required');\n const { code } = credentials;\n const { tokenUri } = this;\n const response = await exchangeAuthorizationCode({ code, tokenUri, ...params });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as GoogleErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n const token = (await response.json()) as GoogleToken;\n const userInfo = await this.getUserInfo(token);\n return { token, userInfo };\n },\n };\n}\n\nexport const google = createGoogleProvider();\n\nexport interface GoogleUserInfo {\n aud: string;\n azp: string;\n email: string;\n email_verified: boolean;\n exp: number;\n family_name: string;\n given_name: string;\n hd?: string;\n iat: number;\n iss: string;\n jti?: string;\n locale?: string;\n name: string;\n nbf?: number;\n picture: string;\n sub: string;\n}\n\nexport interface GoogleToken extends OAuth2Token {\n access_token: string;\n token_type: string;\n expires_in: number;\n refresh_token: string;\n id_token: string;\n scope: string;\n}\n\n// android,ios has different client_id and redirect_uri\nexport type GoogleAppCredentials = {\n state: string;\n code: string;\n client_id: string;\n redirect_uri: string;\n};\n\nexport interface GoogleErrorResponse {\n error:\n | 'invalid_request'\n | 'invalid_client'\n | 'invalid_grant'\n | 'invalid_token'\n | 'invalid_scope'\n | 'unauthorized_client'\n | 'unsupported_grant_type'\n | 'access_denied'\n | 'server_error';\n error_description: string;\n}\n"],"mappings":";AAAA,OAAO,eAAe;AAEtB,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB,2BAA2B,qBAAqB;AAE1E,SAAS,uBAAiC;AAC/C,SAAO;AAAA,IACL,kBAAkB;AAAA,IAClB,UAAU;AAAA,IACV,aAAa;AAAA,IACb,mBAAmB;AAAA,IACnB,WAAW;AAAA;AAAA,IAEX,cAAc;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,uBAAuB,QAAQ;AAC7B,aAAO,uBAAuB;AAAA,QAC5B,GAAG;AAAA,QACH,OAAO,OAAO,SAAS,KAAK;AAAA,QAC5B,kBAAkB,KAAK;AAAA,MACzB,CAAC;AAAA,IACH;AAAA,IACA,MAAM,0BAA0B,QAAQ;AACtC,YAAM,WAAW,MAAM,0BAA0B,EAAE,GAAG,QAAQ,UAAU,KAAK,SAAS,CAAC;AACvF,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,EAAE,OAAO,kBAAkB,IAAK,MAAM,SAAS,KAAK;AAC1D,cAAM,IAAI,YAAY,SAAS,QAAQ,OAAO,iBAAiB;AAAA,MACjE;AACA,aAAQ,MAAM,SAAS,KAAK;AAAA,IAC9B;AAAA,IACA,MAAM,YAAY,EAAE,SAAS,GAAG;AAC9B,gBAAU,UAAU,sBAAsB;AAC1C,gBAAU,KAAK,WAAW,uBAAuB;AACjD,YAAM,OAAO,MAAM,cAA8B,UAAU,KAAK,SAAS;AACzE,aAAO;AAAA,QACL;AAAA,QACA,QAAQ;AAAA,UACN,KAAK,KAAK;AAAA,UACV,MAAM,KAAK;AAAA,UACX,SAAS,KAAK;AAAA,UACd,OAAO,KAAK;AAAA,UACZ,gBAAgB,KAAK;AAAA,UACrB,YAAY,KAAK;AAAA,UACjB,aAAa,KAAK;AAAA,UAClB,QAAQ,KAAK;AAAA,QACf;AAAA,MACF;AAAA,IACF;AAAA,IACA,MAAM,kBAAkB,EAAE,MAAM,aAAa,GAAG,OAAO,GAA4B;AACjF,gBAAU,YAAY,MAAM,kBAAkB;AAC9C,YAAM,EAAE,KAAK,IAAI;AACjB,YAAM,EAAE,SAAS,IAAI;AACrB,YAAM,WAAW,MAAM,0BAA0B,EAAE,MAAM,UAAU,GAAG,OAAO,CAAC;AAC9E,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,EAAE,OAAO,kBAAkB,IAAK,MAAM,SAAS,KAAK;AAC1D,cAAM,IAAI,YAAY,SAAS,QAAQ,OAAO,iBAAiB;AAAA,MACjE;AACA,YAAM,QAAS,MAAM,SAAS,KAAK;AACnC,YAAM,WAAW,MAAM,KAAK,YAAY,KAAK;AAC7C,aAAO,EAAE,OAAO,SAAS;AAAA,IAC3B;AAAA,EACF;AACF;AAEO,IAAM,SAAS,qBAAqB;","names":[]}
|
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/oauth2/provider/x.ts
|
|
31
31
|
var x_exports = {};
|
|
32
32
|
__export(x_exports, {
|
|
33
|
+
createXProvider: () => createXProvider,
|
|
33
34
|
x: () => x
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(x_exports);
|
|
@@ -45,7 +46,7 @@ var defaultUserFields = [
|
|
|
45
46
|
"location",
|
|
46
47
|
"verified"
|
|
47
48
|
];
|
|
48
|
-
function
|
|
49
|
+
function createXProvider(options) {
|
|
49
50
|
return {
|
|
50
51
|
authorizationUri: "https://x.com/i/oauth2/authorize",
|
|
51
52
|
tokenUri: "https://api.x.com/2/oauth2/token",
|
|
@@ -54,7 +55,7 @@ function x(options) {
|
|
|
54
55
|
userInfoUri: "https://api.x.com/2/users/me",
|
|
55
56
|
defaultScope: ["users.read", "tweet.read", "offline.access"],
|
|
56
57
|
createAuthorizationUri(params) {
|
|
57
|
-
if (!params.
|
|
58
|
+
if (!params.pkce) throw new Error("pkce is required for x");
|
|
58
59
|
return (0, import_common.createAuthorizationUri)({
|
|
59
60
|
...params,
|
|
60
61
|
scope: params.scope ?? this.defaultScope,
|
|
@@ -62,7 +63,7 @@ function x(options) {
|
|
|
62
63
|
});
|
|
63
64
|
},
|
|
64
65
|
async exchangeAuthorizationCode(params) {
|
|
65
|
-
if (!params.
|
|
66
|
+
if (!params.pkce) throw new Error("pkce is required for x");
|
|
66
67
|
const response = await (0, import_common.exchangeAuthorizationCode)({
|
|
67
68
|
...params,
|
|
68
69
|
tokenUri: this.tokenUri,
|
|
@@ -106,7 +107,16 @@ function x(options) {
|
|
|
106
107
|
};
|
|
107
108
|
},
|
|
108
109
|
async refreshAccessToken(params) {
|
|
109
|
-
|
|
110
|
+
const response = await (0, import_common.refreshAccessToken)({
|
|
111
|
+
...params,
|
|
112
|
+
tokenUri: this.tokenUri,
|
|
113
|
+
authentication: "basic"
|
|
114
|
+
});
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
const { error, error_description } = await response.json();
|
|
117
|
+
throw new import_error.OAuth2Error(response.status, error, error_description);
|
|
118
|
+
}
|
|
119
|
+
return await response.json();
|
|
110
120
|
},
|
|
111
121
|
async revokeToken(params) {
|
|
112
122
|
(0, import_tiny_invariant.default)(this.tokenRevokeUri, "tokenRevokeUri is required");
|
|
@@ -118,8 +128,10 @@ function x(options) {
|
|
|
118
128
|
}
|
|
119
129
|
};
|
|
120
130
|
}
|
|
131
|
+
var x = createXProvider();
|
|
121
132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
133
|
0 && (module.exports = {
|
|
134
|
+
createXProvider,
|
|
123
135
|
x
|
|
124
136
|
});
|
|
125
137
|
//# sourceMappingURL=x.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { Provider } from '../types';\nimport { OAuth2Error } from '../error';\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
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { OAuth2Token, Provider } from '../types';\nimport { OAuth2Error } from '../error';\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 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 const response = await refreshAccessToken({\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 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\n// prettier-ignore\ntype UrlEntity = { start: number; end: number; url: string; display_url: string; expanded_url: string; }\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAsB;AAEtB,mBAA4B;AAC5B,oBAKO;AAMP,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,gBAAgB,SAA8B;AAC5D,SAAO;AAAA,IACL,kBAAkB;AAAA,IAClB,UAAU;AAAA,IACV,gBAAgB;AAAA;AAAA,IAEhB,aAAa;AAAA,IACb,cAAc,CAAC,cAAc,cAAc,gBAAgB;AAAA,IAC3D,uBAAuB,QAAQ;AAC7B,UAAI,CAAC,OAAO,KAAM,OAAM,IAAI,MAAM,wBAAwB;AAC1D,iBAAO,sCAAuB;AAAA,QAC5B,GAAG;AAAA,QACH,OAAO,OAAO,SAAS,KAAK;AA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;AAAA,UACtB,OAAO,QAAQ,KAAK;AAAA,UACpB,gBAAgB,QAAQ,KAAK,YAAY;AAAA,UACzC,oBAAoB,QAAQ,KAAK;AAAA,UACjC,SAAS,iBAAiB,QAAQ,KAAK,QAAQ;AAAA,UAC/C,SAAS,QAAQ,KAAK;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,IACA,MAAM,mBAAmB,QAAQ;AAC/B,YAAM,WAAW,UAAM,kCAAmB;AAAA,QACxC,GAAG;AAAA,QACH,UAAU,KAAK;AAAA,QACf,gBAAgB;AAAA,MAClB,CAAC;AACD,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,EAAE,OAAO,kBAAkB,IAAK,MAAM,SAAS,KAAK;AAC1D,cAAM,IAAI,yBAAY,SAAS,QAAQ,OAAO,iBAAiB;AAAA,MACjE;AACA,aAAQ,MAAM,SAAS,KAAK;AAAA,IAC9B;AAAA,IACA,MAAM,YAAY,QAAQ;AACxB,gCAAAA,SAAU,KAAK,gBAAgB,4BAA4B;AAC3D,iBAAO,2BAAY;AAAA,QACjB,GAAG;AAAA,QACH,gBAAgB,KAAK;AAAA,QACrB,gBAAgB;AAAA,MAClB,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,IAAM,IAAI,gBAAgB;","names":["invariant"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Provider } from '../types.cjs';
|
|
1
|
+
import { Provider, OAuth2Token } from '../types.cjs';
|
|
2
2
|
|
|
3
3
|
interface XOptions {
|
|
4
4
|
userFields?: UserField[];
|
|
5
5
|
}
|
|
6
|
-
declare function
|
|
6
|
+
declare function createXProvider(options?: XOptions): Provider;
|
|
7
|
+
declare const x: Provider;
|
|
7
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';
|
|
8
9
|
interface XUser {
|
|
9
10
|
id: string;
|
|
@@ -56,5 +57,12 @@ type MentionEntity = {
|
|
|
56
57
|
end: string;
|
|
57
58
|
username: string;
|
|
58
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
|
+
}
|
|
59
67
|
|
|
60
|
-
export { type XOptions, type XUser, type XUserInfo, x };
|
|
68
|
+
export { type XOptions, type XToken, type XUser, type XUserInfo, createXProvider, x };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Provider } from '../types.js';
|
|
1
|
+
import { Provider, OAuth2Token } from '../types.js';
|
|
2
2
|
|
|
3
3
|
interface XOptions {
|
|
4
4
|
userFields?: UserField[];
|
|
5
5
|
}
|
|
6
|
-
declare function
|
|
6
|
+
declare function createXProvider(options?: XOptions): Provider;
|
|
7
|
+
declare const x: Provider;
|
|
7
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';
|
|
8
9
|
interface XUser {
|
|
9
10
|
id: string;
|
|
@@ -56,5 +57,12 @@ type MentionEntity = {
|
|
|
56
57
|
end: string;
|
|
57
58
|
username: string;
|
|
58
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
|
+
}
|
|
59
67
|
|
|
60
|
-
export { type XOptions, type XUser, type XUserInfo, x };
|
|
68
|
+
export { type XOptions, type XToken, type XUser, type XUserInfo, createXProvider, x };
|
|
@@ -16,7 +16,7 @@ var defaultUserFields = [
|
|
|
16
16
|
"location",
|
|
17
17
|
"verified"
|
|
18
18
|
];
|
|
19
|
-
function
|
|
19
|
+
function createXProvider(options) {
|
|
20
20
|
return {
|
|
21
21
|
authorizationUri: "https://x.com/i/oauth2/authorize",
|
|
22
22
|
tokenUri: "https://api.x.com/2/oauth2/token",
|
|
@@ -25,7 +25,7 @@ function x(options) {
|
|
|
25
25
|
userInfoUri: "https://api.x.com/2/users/me",
|
|
26
26
|
defaultScope: ["users.read", "tweet.read", "offline.access"],
|
|
27
27
|
createAuthorizationUri(params) {
|
|
28
|
-
if (!params.
|
|
28
|
+
if (!params.pkce) throw new Error("pkce is required for x");
|
|
29
29
|
return createAuthorizationUri({
|
|
30
30
|
...params,
|
|
31
31
|
scope: params.scope ?? this.defaultScope,
|
|
@@ -33,7 +33,7 @@ function x(options) {
|
|
|
33
33
|
});
|
|
34
34
|
},
|
|
35
35
|
async exchangeAuthorizationCode(params) {
|
|
36
|
-
if (!params.
|
|
36
|
+
if (!params.pkce) throw new Error("pkce is required for x");
|
|
37
37
|
const response = await exchangeAuthorizationCode({
|
|
38
38
|
...params,
|
|
39
39
|
tokenUri: this.tokenUri,
|
|
@@ -77,7 +77,16 @@ function x(options) {
|
|
|
77
77
|
};
|
|
78
78
|
},
|
|
79
79
|
async refreshAccessToken(params) {
|
|
80
|
-
|
|
80
|
+
const response = await refreshAccessToken({
|
|
81
|
+
...params,
|
|
82
|
+
tokenUri: this.tokenUri,
|
|
83
|
+
authentication: "basic"
|
|
84
|
+
});
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const { error, error_description } = await response.json();
|
|
87
|
+
throw new OAuth2Error(response.status, error, error_description);
|
|
88
|
+
}
|
|
89
|
+
return await response.json();
|
|
81
90
|
},
|
|
82
91
|
async revokeToken(params) {
|
|
83
92
|
invariant(this.tokenRevokeUri, "tokenRevokeUri is required");
|
|
@@ -89,7 +98,9 @@ function x(options) {
|
|
|
89
98
|
}
|
|
90
99
|
};
|
|
91
100
|
}
|
|
101
|
+
var x = createXProvider();
|
|
92
102
|
export {
|
|
103
|
+
createXProvider,
|
|
93
104
|
x
|
|
94
105
|
};
|
|
95
106
|
//# sourceMappingURL=x.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { Provider } from '../types';\nimport { OAuth2Error } from '../error';\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
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import invariant from 'tiny-invariant';\nimport { OAuth2Token, Provider } from '../types';\nimport { OAuth2Error } from '../error';\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 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 const response = await refreshAccessToken({\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 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\n// prettier-ignore\ntype UrlEntity = { start: number; end: number; url: string; display_url: string; expanded_url: string; }\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":";AAAA,OAAO,eAAe;AAEtB,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,gBAAgB,SAA8B;AAC5D,SAAO;AAAA,IACL,kBAAkB;AAAA,IAClB,UAAU;AAAA,IACV,gBAAgB;AAAA;AAAA,IAEhB,aAAa;AAAA,IACb,cAAc,CAAC,cAAc,cAAc,gBAAgB;AAAA,IAC3D,uBAAuB,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