@shware/security 0.4.9 → 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 +84 -22
- 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 +85 -23
- 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 +40 -6
- package/dist/oauth2/client.cjs.map +1 -1
- package/dist/oauth2/client.d.cts +29 -6
- package/dist/oauth2/client.d.ts +29 -6
- package/dist/oauth2/client.mjs +40 -6
- 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/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,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;AA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MAAM,OAAO,GAAG,SAAS,KAAK;AAClE,YAAM,iBAAiB,OAAO,KAAK,CAAC,UAAU,MAAM,UAAU,KAAK,KAAK,GAAG,YAAY;AACvF,aAAO;AAAA,QACL;AAAA,QACA,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":[]}
|
|
@@ -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'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AAQ,KAAK;AAAA,QACf;AAAA,MACF;AAAA,IACF;AAAA,IACA,MAAM,kBAAkB,EAAE,MAAM,aAAa,GAAG,OAAO,GAA4B;AACjF,gCAAAA,SAAU,YAAY,MAAM,kBAAkB;AAC9C,YAAM,EAAE,KAAK,IAAI;AACjB,YAAM,EAAE,SAAS,IAAI;AACrB,YAAM,WAAW,UAAM,yCAA0B,EAAE,MAAM,UAAU,GAAG,OAAO,CAAC;AAC9E,UAAI,CAAC,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,I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2/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,SA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AA,UACR,SAAS;AAAA,UACT;AAAA,UACA,iCAAiC,OAAO,GAAG,CAAC,GAAG,UAAU,OAAO,GAAG,CAAC,GAAG;AAAA,QACzE;AAAA,MACF;AACA,YAAM,UAAW,MAAM,SAAS,KAAK;AACrC,aAAO;AAAA,QACL,MAAM;AAAA,QACN,QAAQ;AAAA,UACN,KAAK,QAAQ,KAAK;AAAA,UAClB,MAAM,QAAQ,KAAK;AAAA,UACnB,SAAS,QAAQ,KAAK;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,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ANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,5 +19,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
19
|
|
|
16
20
|
// src/oauth2/types.ts
|
|
17
21
|
var types_exports = {};
|
|
22
|
+
__export(types_exports, {
|
|
23
|
+
OidcScopes: () => OidcScopes
|
|
24
|
+
});
|
|
18
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
|
+
});
|
|
19
39
|
//# sourceMappingURL=types.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/oauth2/types.ts"],"sourcesContent":["
|
|
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: NativeCredentials;\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\nexport interface OidcToken extends OAuth2Token {\n id_token: string;\n}\n\nexport type NativeCredentials = {\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 enum OidcScopes {\n openid = 'openid',\n profile = 'profile',\n email = 'email',\n phone = 'phone',\n address = 'address',\n offline_access = 'offline_access',\n}\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 tokenRevokeUri?: 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 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: { [name: string]: Registration | undefined };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuGO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,oBAAiB;AANP,SAAAA;AAAA,GAAA;","names":["OidcScopes"]}
|