@holo-js/auth-social-linkedin 0.1.3

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.
@@ -0,0 +1,5 @@
1
+ import { SocialProviderRuntime } from '@holo-js/auth-social';
2
+
3
+ declare const linkedinSocialProvider: SocialProviderRuntime;
4
+
5
+ export { linkedinSocialProvider as default, linkedinSocialProvider };
package/dist/index.mjs ADDED
@@ -0,0 +1,81 @@
1
+ // src/index.ts
2
+ async function readJson(response) {
3
+ const text = await response.text();
4
+ return text ? JSON.parse(text) : {};
5
+ }
6
+ async function exchangeToken(context) {
7
+ const body = new URLSearchParams({
8
+ code: context.code,
9
+ client_id: context.config.clientId ?? "",
10
+ client_secret: context.config.clientSecret ?? "",
11
+ redirect_uri: context.config.redirectUri ?? "",
12
+ grant_type: "authorization_code"
13
+ });
14
+ const response = await fetch("https://www.linkedin.com/oauth/v2/accessToken", {
15
+ method: "POST",
16
+ headers: {
17
+ accept: "application/json",
18
+ "content-type": "application/x-www-form-urlencoded"
19
+ },
20
+ body
21
+ });
22
+ if (!response.ok) {
23
+ throw new Error("[@holo-js/auth-social-linkedin] LinkedIn token exchange failed.");
24
+ }
25
+ return await readJson(response);
26
+ }
27
+ function normalizeTokens(payload) {
28
+ const expiresIn = typeof payload.expires_in === "number" ? payload.expires_in : typeof payload.expires_in === "string" ? Number.parseInt(payload.expires_in, 10) : void 0;
29
+ return {
30
+ accessToken: String(payload.access_token ?? ""),
31
+ expiresAt: Number.isFinite(expiresIn) ? new Date(Date.now() + expiresIn * 1e3) : void 0
32
+ };
33
+ }
34
+ function normalizeProfile(payload) {
35
+ const id = typeof payload.sub === "string" ? payload.sub : "";
36
+ if (!id) {
37
+ throw new Error('[@holo-js/auth-social-linkedin] LinkedIn user info did not include "sub".');
38
+ }
39
+ return {
40
+ id,
41
+ email: typeof payload.email === "string" ? payload.email : void 0,
42
+ emailVerified: payload.email_verified === true,
43
+ name: typeof payload.name === "string" ? payload.name : void 0,
44
+ avatar: typeof payload.picture === "string" ? payload.picture : void 0
45
+ };
46
+ }
47
+ var linkedinSocialProvider = Object.freeze({
48
+ buildAuthorizationUrl(context) {
49
+ const scopes = (context.config.scopes ?? []).length > 0 ? context.config.scopes ?? [] : ["openid", "profile", "email"];
50
+ const url = new URL("https://www.linkedin.com/oauth/v2/authorization");
51
+ url.searchParams.set("client_id", context.config.clientId ?? "");
52
+ url.searchParams.set("redirect_uri", context.config.redirectUri ?? "");
53
+ url.searchParams.set("response_type", "code");
54
+ url.searchParams.set("scope", scopes.join(" "));
55
+ url.searchParams.set("state", context.state);
56
+ return url.toString();
57
+ },
58
+ async exchangeCode(context) {
59
+ const tokenPayload = await exchangeToken(context);
60
+ const accessToken = String(tokenPayload.access_token ?? "");
61
+ const response = await fetch("https://api.linkedin.com/v2/userinfo", {
62
+ headers: {
63
+ authorization: `Bearer ${accessToken}`,
64
+ accept: "application/json"
65
+ }
66
+ });
67
+ if (!response.ok) {
68
+ throw new Error("[@holo-js/auth-social-linkedin] LinkedIn user info request failed.");
69
+ }
70
+ const payload = await readJson(response);
71
+ return {
72
+ profile: normalizeProfile(payload),
73
+ tokens: normalizeTokens(tokenPayload)
74
+ };
75
+ }
76
+ });
77
+ var src_default = linkedinSocialProvider;
78
+ export {
79
+ src_default as default,
80
+ linkedinSocialProvider
81
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@holo-js/auth-social-linkedin",
3
+ "version": "0.1.3",
4
+ "description": "Holo-JS Framework - LinkedIn social auth provider",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.mjs",
11
+ "default": "./dist/index.mjs"
12
+ }
13
+ },
14
+ "main": "./dist/index.mjs",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "stub": "tsup",
22
+ "typecheck": "tsc -p tsconfig.json --noEmit",
23
+ "test": "vitest --run"
24
+ },
25
+ "dependencies": {
26
+ "@holo-js/auth-social": "workspace:*",
27
+ "@holo-js/config": "workspace:*"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.10.2",
31
+ "tsup": "^8.3.5",
32
+ "typescript": "^5.7.2",
33
+ "vitest": "^2.1.8"
34
+ }
35
+ }