@hazeljs/oauth 0.2.0-beta.49

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.
Files changed (39) hide show
  1. package/LICENSE +192 -0
  2. package/README.md +200 -0
  3. package/dist/guards/oauth-state.guard.d.ts +15 -0
  4. package/dist/guards/oauth-state.guard.d.ts.map +1 -0
  5. package/dist/guards/oauth-state.guard.js +43 -0
  6. package/dist/index.d.ts +12 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +17 -0
  9. package/dist/oauth.controller.d.ts +29 -0
  10. package/dist/oauth.controller.d.ts.map +1 -0
  11. package/dist/oauth.controller.js +134 -0
  12. package/dist/oauth.module.d.ts +5 -0
  13. package/dist/oauth.module.d.ts.map +1 -0
  14. package/dist/oauth.module.js +27 -0
  15. package/dist/oauth.service.d.ts +36 -0
  16. package/dist/oauth.service.d.ts.map +1 -0
  17. package/dist/oauth.service.js +239 -0
  18. package/dist/providers/facebook.provider.d.ts +11 -0
  19. package/dist/providers/facebook.provider.d.ts.map +1 -0
  20. package/dist/providers/facebook.provider.js +63 -0
  21. package/dist/providers/github.provider.d.ts +11 -0
  22. package/dist/providers/github.provider.d.ts.map +1 -0
  23. package/dist/providers/github.provider.js +79 -0
  24. package/dist/providers/google.provider.d.ts +11 -0
  25. package/dist/providers/google.provider.d.ts.map +1 -0
  26. package/dist/providers/google.provider.js +61 -0
  27. package/dist/providers/index.d.ts +7 -0
  28. package/dist/providers/index.d.ts.map +1 -0
  29. package/dist/providers/index.js +22 -0
  30. package/dist/providers/microsoft.provider.d.ts +11 -0
  31. package/dist/providers/microsoft.provider.d.ts.map +1 -0
  32. package/dist/providers/microsoft.provider.js +62 -0
  33. package/dist/providers/provider.types.d.ts +62 -0
  34. package/dist/providers/provider.types.d.ts.map +1 -0
  35. package/dist/providers/provider.types.js +5 -0
  36. package/dist/providers/twitter.provider.d.ts +11 -0
  37. package/dist/providers/twitter.provider.d.ts.map +1 -0
  38. package/dist/providers/twitter.provider.js +67 -0
  39. package/package.json +56 -0
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var OAuthModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.OAuthModule = void 0;
11
+ const core_1 = require("@hazeljs/core");
12
+ const oauth_controller_1 = require("./oauth.controller");
13
+ const oauth_service_1 = require("./oauth.service");
14
+ let OAuthModule = OAuthModule_1 = class OAuthModule {
15
+ static forRoot(options) {
16
+ oauth_service_1.OAuthService.configure(options);
17
+ return OAuthModule_1;
18
+ }
19
+ };
20
+ exports.OAuthModule = OAuthModule;
21
+ exports.OAuthModule = OAuthModule = OAuthModule_1 = __decorate([
22
+ (0, core_1.HazelModule)({
23
+ controllers: [oauth_controller_1.OAuthController],
24
+ providers: [oauth_service_1.OAuthService],
25
+ exports: [oauth_service_1.OAuthService],
26
+ })
27
+ ], OAuthModule);
@@ -0,0 +1,36 @@
1
+ import type { OAuthModuleOptions, OAuthCallbackResult, OAuthAuthorizationResult, SupportedProvider } from './providers/provider.types';
2
+ export declare class OAuthService {
3
+ private options;
4
+ private googleClient;
5
+ private microsoftClient;
6
+ private githubClient;
7
+ private facebookClient;
8
+ private twitterClient;
9
+ constructor();
10
+ private static options;
11
+ static configure(options: OAuthModuleOptions): void;
12
+ private static getOptions;
13
+ private initClients;
14
+ private getClient;
15
+ private getDefaultScopes;
16
+ /**
17
+ * Get the authorization URL to redirect the user to the OAuth provider.
18
+ * For PKCE providers (Google, Microsoft), store codeVerifier and pass it to handleCallback.
19
+ */
20
+ getAuthorizationUrl(provider: SupportedProvider, state?: string, scopes?: string[]): OAuthAuthorizationResult;
21
+ /**
22
+ * Exchange the authorization code for tokens and fetch user profile.
23
+ * For PKCE providers (Google, Microsoft), codeVerifier is required.
24
+ */
25
+ handleCallback(provider: SupportedProvider, code: string, state: string, codeVerifier?: string): Promise<OAuthCallbackResult>;
26
+ /**
27
+ * Validate that the state matches (CSRF protection).
28
+ * Use this when handling the callback to ensure the request originated from your app.
29
+ */
30
+ validateState(receivedState: string, storedState: string): boolean;
31
+ /**
32
+ * Generate a cryptographically secure state value for OAuth.
33
+ */
34
+ generateState(): string;
35
+ }
36
+ //# sourceMappingURL=oauth.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.service.d.ts","sourceRoot":"","sources":["../src/oauth.service.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EAElB,MAAM,4BAA4B,CAAC;AAIpC,qBACa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,YAAY,CAAwD;IAC5E,OAAO,CAAC,eAAe,CAA2D;IAClF,OAAO,CAAC,YAAY,CAAwD;IAC5E,OAAO,CAAC,cAAc,CAA0D;IAChF,OAAO,CAAC,aAAa,CAAyD;;IAO9E,OAAO,CAAC,MAAM,CAAC,OAAO,CAAmC;IAEzD,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAInD,OAAO,CAAC,MAAM,CAAC,UAAU;IASzB,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,SAAS;IA8BjB,OAAO,CAAC,gBAAgB;IAmBxB;;;OAGG;IACH,mBAAmB,CACjB,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,CAAC,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,wBAAwB;IA2B3B;;;OAGG;IACG,cAAc,CAClB,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAuF/B;;;OAGG;IACH,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO;IAIlE;;OAEG;IACH,aAAa,IAAI,MAAM;CAGxB"}
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ var OAuthService_1;
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.OAuthService = void 0;
47
+ const core_1 = require("@hazeljs/core");
48
+ const arctic = __importStar(require("arctic"));
49
+ const providers_1 = require("./providers");
50
+ const PKCE_PROVIDERS = ['google', 'microsoft', 'twitter'];
51
+ let OAuthService = OAuthService_1 = class OAuthService {
52
+ constructor() {
53
+ this.googleClient = null;
54
+ this.microsoftClient = null;
55
+ this.githubClient = null;
56
+ this.facebookClient = null;
57
+ this.twitterClient = null;
58
+ this.options = OAuthService_1.getOptions();
59
+ this.initClients();
60
+ }
61
+ static configure(options) {
62
+ OAuthService_1.options = options;
63
+ }
64
+ static getOptions() {
65
+ if (!OAuthService_1.options) {
66
+ throw new Error('OAuthModule not configured. Call OAuthModule.forRoot({ providers: {...} }) in your app module.');
67
+ }
68
+ return OAuthService_1.options;
69
+ }
70
+ initClients() {
71
+ if (this.options.providers.google) {
72
+ this.googleClient = (0, providers_1.createGoogleProvider)(this.options.providers.google);
73
+ }
74
+ if (this.options.providers.microsoft) {
75
+ this.microsoftClient = (0, providers_1.createMicrosoftProvider)(this.options.providers.microsoft);
76
+ }
77
+ if (this.options.providers.github) {
78
+ this.githubClient = (0, providers_1.createGitHubProvider)(this.options.providers.github);
79
+ }
80
+ if (this.options.providers.facebook) {
81
+ this.facebookClient = (0, providers_1.createFacebookProvider)(this.options.providers.facebook);
82
+ }
83
+ if (this.options.providers.twitter) {
84
+ this.twitterClient = (0, providers_1.createTwitterProvider)(this.options.providers.twitter);
85
+ }
86
+ }
87
+ getClient(provider) {
88
+ switch (provider) {
89
+ case 'google':
90
+ if (!this.googleClient)
91
+ throw new Error('Google OAuth is not configured');
92
+ return this.googleClient;
93
+ case 'microsoft':
94
+ if (!this.microsoftClient)
95
+ throw new Error('Microsoft OAuth is not configured');
96
+ return this.microsoftClient;
97
+ case 'github':
98
+ if (!this.githubClient)
99
+ throw new Error('GitHub OAuth is not configured');
100
+ return this.githubClient;
101
+ case 'facebook':
102
+ if (!this.facebookClient)
103
+ throw new Error('Facebook OAuth is not configured');
104
+ return this.facebookClient;
105
+ case 'twitter':
106
+ if (!this.twitterClient)
107
+ throw new Error('Twitter OAuth is not configured');
108
+ return this.twitterClient;
109
+ default:
110
+ throw new Error(`Unsupported provider: ${provider}`);
111
+ }
112
+ }
113
+ getDefaultScopes(provider) {
114
+ const defaults = this.options.defaultScopes?.[provider];
115
+ if (defaults)
116
+ return defaults;
117
+ switch (provider) {
118
+ case 'google':
119
+ return (0, providers_1.getGoogleDefaultScopes)();
120
+ case 'microsoft':
121
+ return (0, providers_1.getMicrosoftDefaultScopes)();
122
+ case 'github':
123
+ return (0, providers_1.getGitHubDefaultScopes)();
124
+ case 'facebook':
125
+ return (0, providers_1.getFacebookDefaultScopes)();
126
+ case 'twitter':
127
+ return (0, providers_1.getTwitterDefaultScopes)();
128
+ default:
129
+ return [];
130
+ }
131
+ }
132
+ /**
133
+ * Get the authorization URL to redirect the user to the OAuth provider.
134
+ * For PKCE providers (Google, Microsoft), store codeVerifier and pass it to handleCallback.
135
+ */
136
+ getAuthorizationUrl(provider, state, scopes) {
137
+ const client = this.getClient(provider);
138
+ const resolvedState = state || arctic.generateState();
139
+ const resolvedScopes = scopes ?? this.getDefaultScopes(provider);
140
+ if (PKCE_PROVIDERS.includes(provider)) {
141
+ const codeVerifier = arctic.generateCodeVerifier();
142
+ const url = client.createAuthorizationURL(resolvedState, codeVerifier, resolvedScopes);
143
+ return {
144
+ url: url.toString(),
145
+ state: resolvedState,
146
+ codeVerifier,
147
+ };
148
+ }
149
+ // GitHub, Facebook - no PKCE
150
+ const url = client.createAuthorizationURL(resolvedState, resolvedScopes);
151
+ return {
152
+ url: url.toString(),
153
+ state: resolvedState,
154
+ };
155
+ }
156
+ /**
157
+ * Exchange the authorization code for tokens and fetch user profile.
158
+ * For PKCE providers (Google, Microsoft), codeVerifier is required.
159
+ */
160
+ async handleCallback(provider, code, state, codeVerifier) {
161
+ const client = this.getClient(provider);
162
+ const needsPkce = PKCE_PROVIDERS.includes(provider);
163
+ if (needsPkce && !codeVerifier) {
164
+ throw new Error(`Provider ${provider} requires codeVerifier (PKCE). Pass the codeVerifier from getAuthorizationUrl.`);
165
+ }
166
+ let accessToken;
167
+ let refreshToken;
168
+ let expiresAt;
169
+ try {
170
+ if (needsPkce && codeVerifier) {
171
+ const tokens = await client.validateAuthorizationCode(code, codeVerifier);
172
+ accessToken = tokens.accessToken();
173
+ refreshToken = tokens.hasRefreshToken() ? tokens.refreshToken() : undefined;
174
+ expiresAt = tokens.accessTokenExpiresAt();
175
+ }
176
+ else {
177
+ const tokens = await client.validateAuthorizationCode(code);
178
+ accessToken = tokens.accessToken();
179
+ refreshToken = tokens.hasRefreshToken() ? tokens.refreshToken() : undefined;
180
+ expiresAt = tokens.accessTokenExpiresAt();
181
+ }
182
+ }
183
+ catch (e) {
184
+ if (e instanceof arctic.OAuth2RequestError) {
185
+ throw new Error(`OAuth token exchange failed: ${e.code} - ${e.description || e.message}`);
186
+ }
187
+ if (e instanceof arctic.ArcticFetchError) {
188
+ const cause = e.cause;
189
+ throw new Error(`OAuth request failed: ${cause?.message || e.message}`);
190
+ }
191
+ throw e;
192
+ }
193
+ let user;
194
+ switch (provider) {
195
+ case 'google':
196
+ user = await (0, providers_1.fetchGoogleUser)(accessToken);
197
+ break;
198
+ case 'microsoft':
199
+ user = await (0, providers_1.fetchMicrosoftUser)(accessToken);
200
+ break;
201
+ case 'github':
202
+ user = await (0, providers_1.fetchGitHubUser)(accessToken);
203
+ break;
204
+ case 'facebook':
205
+ user = await (0, providers_1.fetchFacebookUser)(accessToken);
206
+ break;
207
+ case 'twitter':
208
+ user = await (0, providers_1.fetchTwitterUser)(accessToken);
209
+ break;
210
+ default:
211
+ throw new Error(`Unsupported provider: ${provider}`);
212
+ }
213
+ return {
214
+ accessToken,
215
+ refreshToken,
216
+ expiresAt,
217
+ user,
218
+ };
219
+ }
220
+ /**
221
+ * Validate that the state matches (CSRF protection).
222
+ * Use this when handling the callback to ensure the request originated from your app.
223
+ */
224
+ validateState(receivedState, storedState) {
225
+ return receivedState === storedState && receivedState.length > 0;
226
+ }
227
+ /**
228
+ * Generate a cryptographically secure state value for OAuth.
229
+ */
230
+ generateState() {
231
+ return arctic.generateState();
232
+ }
233
+ };
234
+ exports.OAuthService = OAuthService;
235
+ OAuthService.options = null;
236
+ exports.OAuthService = OAuthService = OAuthService_1 = __decorate([
237
+ (0, core_1.Injectable)(),
238
+ __metadata("design:paramtypes", [])
239
+ ], OAuthService);
@@ -0,0 +1,11 @@
1
+ import * as arctic from 'arctic';
2
+ import type { FacebookProviderConfig } from './provider.types';
3
+ export declare function createFacebookProvider(config: FacebookProviderConfig): arctic.Facebook;
4
+ export declare function getFacebookDefaultScopes(): string[];
5
+ export declare function fetchFacebookUser(accessToken: string): Promise<{
6
+ id: string;
7
+ email: string;
8
+ name: string | null;
9
+ picture?: string | null;
10
+ }>;
11
+ //# sourceMappingURL=facebook.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facebook.provider.d.ts","sourceRoot":"","sources":["../../src/providers/facebook.provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAI/D,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAAC,QAAQ,CAEtF;AAED,wBAAgB,wBAAwB,IAAI,MAAM,EAAE,CAEnD;AAED,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC,CAqBD"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createFacebookProvider = createFacebookProvider;
37
+ exports.getFacebookDefaultScopes = getFacebookDefaultScopes;
38
+ exports.fetchFacebookUser = fetchFacebookUser;
39
+ const arctic = __importStar(require("arctic"));
40
+ const DEFAULT_SCOPES = ['email', 'public_profile'];
41
+ function createFacebookProvider(config) {
42
+ return new arctic.Facebook(config.clientId, config.clientSecret, config.redirectUri);
43
+ }
44
+ function getFacebookDefaultScopes() {
45
+ return [...DEFAULT_SCOPES];
46
+ }
47
+ async function fetchFacebookUser(accessToken) {
48
+ const params = new URLSearchParams();
49
+ params.set('access_token', accessToken);
50
+ params.set('fields', ['id', 'name', 'picture', 'email'].join(','));
51
+ const res = await fetch(`https://graph.facebook.com/me?${params.toString()}`);
52
+ if (!res.ok) {
53
+ throw new Error(`Failed to fetch Facebook user: ${res.status}`);
54
+ }
55
+ const data = (await res.json());
56
+ const pictureUrl = data.picture?.data?.url ?? null;
57
+ return {
58
+ id: data.id,
59
+ email: data.email || '',
60
+ name: data.name || null,
61
+ picture: pictureUrl,
62
+ };
63
+ }
@@ -0,0 +1,11 @@
1
+ import * as arctic from 'arctic';
2
+ import type { GitHubProviderConfig } from './provider.types';
3
+ export declare function createGitHubProvider(config: GitHubProviderConfig): arctic.GitHub;
4
+ export declare function getGitHubDefaultScopes(): string[];
5
+ export declare function fetchGitHubUser(accessToken: string): Promise<{
6
+ id: string;
7
+ email: string;
8
+ name: string | null;
9
+ picture?: string | null;
10
+ }>;
11
+ //# sourceMappingURL=github.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.provider.d.ts","sourceRoot":"","sources":["../../src/providers/github.provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAI7D,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAEhF;AAED,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD;AAED,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC,CAuCD"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createGitHubProvider = createGitHubProvider;
37
+ exports.getGitHubDefaultScopes = getGitHubDefaultScopes;
38
+ exports.fetchGitHubUser = fetchGitHubUser;
39
+ const arctic = __importStar(require("arctic"));
40
+ const DEFAULT_SCOPES = ['user:email'];
41
+ function createGitHubProvider(config) {
42
+ return new arctic.GitHub(config.clientId, config.clientSecret, config.redirectUri);
43
+ }
44
+ function getGitHubDefaultScopes() {
45
+ return [...DEFAULT_SCOPES];
46
+ }
47
+ async function fetchGitHubUser(accessToken) {
48
+ const res = await fetch('https://api.github.com/user', {
49
+ headers: {
50
+ Authorization: `Bearer ${accessToken}`,
51
+ Accept: 'application/vnd.github+json',
52
+ 'X-GitHub-Api-Version': '2022-11-28',
53
+ },
54
+ });
55
+ if (!res.ok) {
56
+ throw new Error(`Failed to fetch GitHub user: ${res.status}`);
57
+ }
58
+ const data = (await res.json());
59
+ let email = data.email || '';
60
+ if (!email) {
61
+ const emailsRes = await fetch('https://api.github.com/user/emails', {
62
+ headers: {
63
+ Authorization: `Bearer ${accessToken}`,
64
+ Accept: 'application/vnd.github+json',
65
+ },
66
+ });
67
+ if (emailsRes.ok) {
68
+ const emails = (await emailsRes.json());
69
+ const primary = emails.find((e) => e.primary) || emails[0];
70
+ email = primary?.email || '';
71
+ }
72
+ }
73
+ return {
74
+ id: String(data.id),
75
+ email,
76
+ name: data.name || null,
77
+ picture: data.avatar_url ?? null,
78
+ };
79
+ }
@@ -0,0 +1,11 @@
1
+ import * as arctic from 'arctic';
2
+ import type { GoogleProviderConfig } from './provider.types';
3
+ export declare function createGoogleProvider(config: GoogleProviderConfig): arctic.Google;
4
+ export declare function getGoogleDefaultScopes(): string[];
5
+ export declare function fetchGoogleUser(accessToken: string): Promise<{
6
+ id: string;
7
+ email: string;
8
+ name: string | null;
9
+ picture?: string | null;
10
+ }>;
11
+ //# sourceMappingURL=google.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.provider.d.ts","sourceRoot":"","sources":["../../src/providers/google.provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAI7D,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAEhF;AAED,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD;AAED,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC,CAmBD"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createGoogleProvider = createGoogleProvider;
37
+ exports.getGoogleDefaultScopes = getGoogleDefaultScopes;
38
+ exports.fetchGoogleUser = fetchGoogleUser;
39
+ const arctic = __importStar(require("arctic"));
40
+ const DEFAULT_SCOPES = ['openid', 'profile', 'email'];
41
+ function createGoogleProvider(config) {
42
+ return new arctic.Google(config.clientId, config.clientSecret, config.redirectUri);
43
+ }
44
+ function getGoogleDefaultScopes() {
45
+ return [...DEFAULT_SCOPES];
46
+ }
47
+ async function fetchGoogleUser(accessToken) {
48
+ const res = await fetch('https://openidconnect.googleapis.com/v1/userinfo', {
49
+ headers: { Authorization: `Bearer ${accessToken}` },
50
+ });
51
+ if (!res.ok) {
52
+ throw new Error(`Failed to fetch Google user: ${res.status}`);
53
+ }
54
+ const data = (await res.json());
55
+ return {
56
+ id: data.sub,
57
+ email: data.email || '',
58
+ name: data.name || null,
59
+ picture: data.picture ?? null,
60
+ };
61
+ }
@@ -0,0 +1,7 @@
1
+ export * from './provider.types';
2
+ export * from './google.provider';
3
+ export * from './microsoft.provider';
4
+ export * from './github.provider';
5
+ export * from './facebook.provider';
6
+ export * from './twitter.provider';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./provider.types"), exports);
18
+ __exportStar(require("./google.provider"), exports);
19
+ __exportStar(require("./microsoft.provider"), exports);
20
+ __exportStar(require("./github.provider"), exports);
21
+ __exportStar(require("./facebook.provider"), exports);
22
+ __exportStar(require("./twitter.provider"), exports);
@@ -0,0 +1,11 @@
1
+ import * as arctic from 'arctic';
2
+ import type { MicrosoftProviderConfig } from './provider.types';
3
+ export declare function createMicrosoftProvider(config: MicrosoftProviderConfig): arctic.MicrosoftEntraId;
4
+ export declare function getMicrosoftDefaultScopes(): string[];
5
+ export declare function fetchMicrosoftUser(accessToken: string): Promise<{
6
+ id: string;
7
+ email: string;
8
+ name: string | null;
9
+ picture?: string | null;
10
+ }>;
11
+ //# sourceMappingURL=microsoft.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microsoft.provider.d.ts","sourceRoot":"","sources":["../../src/providers/microsoft.provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAIhE,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,uBAAuB,GAAG,MAAM,CAAC,gBAAgB,CAQhG;AAED,wBAAgB,yBAAyB,IAAI,MAAM,EAAE,CAEpD;AAED,wBAAsB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC,CAmBD"}