@holo-js/auth-social-github 0.1.9 → 0.2.1
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/index.mjs +13 -24
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,40 +1,25 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { socialAuthInternals } from "@holo-js/auth-social";
|
|
2
3
|
function applyScopes(url, config) {
|
|
3
4
|
const scopes = config.scopes?.length ? config.scopes : ["read:user", "user:email"];
|
|
4
5
|
url.searchParams.set("scope", scopes.join(" "));
|
|
5
6
|
}
|
|
6
|
-
async function readJson(response) {
|
|
7
|
-
const text = await response.text();
|
|
8
|
-
return text ? JSON.parse(text) : {};
|
|
9
|
-
}
|
|
10
7
|
async function exchangeToken(context) {
|
|
11
|
-
const body = new URLSearchParams({
|
|
12
|
-
code: context.code,
|
|
13
|
-
client_id: context.config.clientId ?? "",
|
|
14
|
-
client_secret: context.config.clientSecret ?? "",
|
|
15
|
-
redirect_uri: context.config.redirectUri ?? ""
|
|
16
|
-
});
|
|
17
8
|
const response = await fetch("https://github.com/login/oauth/access_token", {
|
|
18
9
|
method: "POST",
|
|
19
10
|
headers: {
|
|
20
11
|
accept: "application/json",
|
|
21
12
|
"content-type": "application/x-www-form-urlencoded"
|
|
22
13
|
},
|
|
23
|
-
body
|
|
14
|
+
body: socialAuthInternals.createAuthorizationCodeTokenBody(context, {
|
|
15
|
+
includeCodeVerifier: false,
|
|
16
|
+
includeGrantType: false
|
|
17
|
+
})
|
|
24
18
|
});
|
|
25
19
|
if (!response.ok) {
|
|
26
20
|
throw new Error("[@holo-js/auth-social-github] GitHub token exchange failed.");
|
|
27
21
|
}
|
|
28
|
-
return await
|
|
29
|
-
}
|
|
30
|
-
function normalizeTokens(payload) {
|
|
31
|
-
return {
|
|
32
|
-
accessToken: String(payload.access_token ?? ""),
|
|
33
|
-
refreshToken: typeof payload.refresh_token === "string" ? payload.refresh_token : void 0,
|
|
34
|
-
refreshTokenExpiresIn: payload.refresh_token_expires_in,
|
|
35
|
-
tokenType: payload.token_type,
|
|
36
|
-
scope: payload.scope
|
|
37
|
-
};
|
|
22
|
+
return await socialAuthInternals.readJsonResponse(response);
|
|
38
23
|
}
|
|
39
24
|
function normalizeProfile(profilePayload, emailsPayload) {
|
|
40
25
|
const id = profilePayload.id;
|
|
@@ -76,11 +61,15 @@ var githubSocialProvider = Object.freeze({
|
|
|
76
61
|
if (!emailsResponse.ok) {
|
|
77
62
|
throw new Error("[@holo-js/auth-social-github] GitHub email request failed.");
|
|
78
63
|
}
|
|
79
|
-
const profilePayload = await
|
|
80
|
-
const emailsPayload = await
|
|
64
|
+
const profilePayload = await socialAuthInternals.readJsonResponse(profileResponse);
|
|
65
|
+
const emailsPayload = await socialAuthInternals.readJsonResponse(emailsResponse);
|
|
81
66
|
return {
|
|
82
67
|
profile: normalizeProfile(profilePayload, emailsPayload),
|
|
83
|
-
tokens:
|
|
68
|
+
tokens: socialAuthInternals.normalizeOAuthTokens(tokenPayload, {
|
|
69
|
+
extra: {
|
|
70
|
+
refreshTokenExpiresIn: tokenPayload.refresh_token_expires_in
|
|
71
|
+
}
|
|
72
|
+
})
|
|
84
73
|
};
|
|
85
74
|
}
|
|
86
75
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/auth-social-github",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Holo-JS Framework - GitHub social auth provider",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "vitest --run"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@holo-js/auth-social": "^0.1
|
|
26
|
+
"@holo-js/auth-social": "^0.2.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.10.2",
|