@alore/auth-react-sdk 1.1.0-alpha.14 → 1.1.0-alpha.16

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/types.d.ts CHANGED
@@ -35,6 +35,15 @@ export interface AuthProviderConfig {
35
35
  termsOfServiceUrl?: string;
36
36
  logoUrl?: string;
37
37
  socialProviders?: SocialProvider[];
38
+ /**
39
+ * Where Microsoft returns the popup. Must be a page that does NOT boot the
40
+ * consuming app: MSAL reads the token off this window's URL fragment, and an
41
+ * app that routes on load (locale redirects, auth guards) clears the fragment
42
+ * first, failing the sign-in with `hash_empty_error`. A blank static file is
43
+ * the documented choice. Defaults to the origin, which only works for apps
44
+ * that do not navigate on load.
45
+ */
46
+ microsoftRedirectUri?: string;
38
47
  enableWalletCreation?: boolean;
39
48
  firebaseCompatible?: boolean;
40
49
  }
@@ -44,6 +53,12 @@ export interface AuthMachineContext {
44
53
  error?: string;
45
54
  active2fa?: TwoFactorAuth[];
46
55
  sessionId?: string;
56
+ socialChallenge?: {
57
+ sessionId: string;
58
+ idToken: string;
59
+ providerName: string;
60
+ device?: string;
61
+ };
47
62
  registerUser?: {
48
63
  email: string;
49
64
  nickname: string;
@@ -220,10 +220,22 @@ export declare class AloreAuth {
220
220
  providerName: string;
221
221
  device?: string;
222
222
  nonce?: string;
223
+ sessionId?: string;
224
+ emailCode?: string;
223
225
  };
224
226
  }) => Promise<{
227
+ emailChallenge: {
228
+ sessionId: any;
229
+ idToken: string;
230
+ providerName: string;
231
+ device: string | undefined;
232
+ };
233
+ sessionUser?: undefined;
234
+ isNewUser?: undefined;
235
+ } | {
225
236
  sessionUser: any;
226
237
  isNewUser: boolean;
238
+ emailChallenge?: undefined;
227
239
  }>;
228
240
  googleLogin: (context: AuthMachineContext, event: {
229
241
  type: 'GOOGLE_LOGIN';
@@ -415,16 +415,44 @@ export class AloreAuth {
415
415
  * password step.
416
416
  */
417
417
  socialLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
418
- const { idToken, providerName, device, nonce } = event.payload;
418
+ const { idToken, providerName, device, nonce, sessionId, emailCode } = event.payload;
419
419
  const { authProviderConfigs } = context;
420
- const { firebaseCompatible } = authProviderConfigs || {};
421
- const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/social-login${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
420
+ const { firebaseCompatible, locale } = authProviderConfigs || {};
421
+ const query = new URLSearchParams();
422
+ if (firebaseCompatible)
423
+ query.set('firebaseCompatibleToken', String(firebaseCompatible));
424
+ if (locale)
425
+ query.set('locale', locale);
426
+ const queryString = query.toString();
427
+ const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/social-login${queryString ? `?${queryString}` : ''}`, {
422
428
  method: 'POST',
423
429
  headers: {
424
430
  'Content-Type': 'application/json',
425
431
  },
426
- body: JSON.stringify(Object.assign(Object.assign({ idToken, provider: providerName }, (device ? { device } : {})), (nonce ? { nonce } : {}))),
432
+ body: JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign({ idToken, provider: providerName }, (device ? { device } : {})), (nonce ? { nonce } : {})), (sessionId ? { sessionId } : {})), (emailCode ? { emailCode } : {}))),
427
433
  });
434
+ // Not every 403 here is a refusal. Where the provider does not vouch for
435
+ // the address — Microsoft never does, since Entra carries no
436
+ // email_verified claim — the backend emails a code to the address the
437
+ // token claimed and hands back the session carrying it. The flow
438
+ // continues by calling this same endpoint again with that session and
439
+ // the code.
440
+ if (response.status === 403) {
441
+ const challenge = yield response
442
+ .clone()
443
+ .json()
444
+ .catch(() => null);
445
+ if ((challenge === null || challenge === void 0 ? void 0 : challenge.error) === 'SOCIAL_EMAIL_VERIFICATION_REQUIRED' && (challenge === null || challenge === void 0 ? void 0 : challenge.sessionId)) {
446
+ return {
447
+ emailChallenge: {
448
+ sessionId: challenge.sessionId,
449
+ idToken,
450
+ providerName,
451
+ device,
452
+ },
453
+ };
454
+ }
455
+ }
428
456
  if (!response.ok)
429
457
  yield this.throwParsedResponseError(response);
430
458
  const sessionUser = yield response.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alore/auth-react-sdk",
3
- "version": "1.1.0-alpha.14",
3
+ "version": "1.1.0-alpha.16",
4
4
  "repository": "https://github.com/0xCarbon/alore-js",
5
5
  "description": "SDK for Alore Auth",
6
6
  "main": "dist/index.js",