@hfunlabs/hypurr-connect 0.1.25 → 0.1.26
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/README.md +7 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +22 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/HypurrConnectProvider.tsx +28 -26
- package/src/types.ts +2 -2
package/package.json
CHANGED
|
@@ -63,7 +63,8 @@ const TELEGRAM_STORAGE_KEY = "hypurr-connect-tg-jwt";
|
|
|
63
63
|
const LEGACY_TELEGRAM_STORAGE_KEY = "hypurr-connect-tg-user";
|
|
64
64
|
const TELEGRAM_AUTH_STATE_KEY = "hypurr-connect-auth-state";
|
|
65
65
|
const TELEGRAM_AUTH_CODE_VERIFIER_PREFIX = "hypurr-connect-auth-code-verifier:";
|
|
66
|
-
const
|
|
66
|
+
const TELEGRAM_AUTH_REDIRECT_URI_PREFIX =
|
|
67
|
+
"hypurr-connect-auth-redirect-uri:";
|
|
67
68
|
const TELEGRAM_AUTH_MESSAGE = "hypurr-connect:telegram-auth";
|
|
68
69
|
const DEFAULT_AUTH_HUB_URL = "https://auth.hypurr.fun/login";
|
|
69
70
|
const DEFAULT_MEDIA_URL = "https://media.hypurr.fun";
|
|
@@ -240,7 +241,7 @@ function withExpectedFrom(
|
|
|
240
241
|
return transaction.from ? transaction : { ...transaction, from: address };
|
|
241
242
|
}
|
|
242
243
|
|
|
243
|
-
function
|
|
244
|
+
function currentRedirectUri(): string {
|
|
244
245
|
const url = new URL(window.location.href);
|
|
245
246
|
for (const param of [
|
|
246
247
|
"code",
|
|
@@ -326,52 +327,52 @@ function codeVerifierStorageKey(state: string): string {
|
|
|
326
327
|
return `${TELEGRAM_AUTH_CODE_VERIFIER_PREFIX}${state}`;
|
|
327
328
|
}
|
|
328
329
|
|
|
329
|
-
function
|
|
330
|
-
return `${
|
|
330
|
+
function redirectUriStorageKey(state: string): string {
|
|
331
|
+
return `${TELEGRAM_AUTH_REDIRECT_URI_PREFIX}${state}`;
|
|
331
332
|
}
|
|
332
333
|
|
|
333
334
|
function storeTelegramAuthSession(
|
|
334
335
|
state: string,
|
|
335
336
|
codeVerifier: string,
|
|
336
|
-
|
|
337
|
+
redirectUri: string,
|
|
337
338
|
): void {
|
|
338
339
|
const previousState = sessionStorage.getItem(TELEGRAM_AUTH_STATE_KEY);
|
|
339
340
|
if (previousState) {
|
|
340
341
|
sessionStorage.removeItem(codeVerifierStorageKey(previousState));
|
|
341
|
-
sessionStorage.removeItem(
|
|
342
|
+
sessionStorage.removeItem(redirectUriStorageKey(previousState));
|
|
342
343
|
}
|
|
343
344
|
sessionStorage.setItem(TELEGRAM_AUTH_STATE_KEY, state);
|
|
344
345
|
sessionStorage.setItem(codeVerifierStorageKey(state), codeVerifier);
|
|
345
|
-
sessionStorage.setItem(
|
|
346
|
+
sessionStorage.setItem(redirectUriStorageKey(state), redirectUri);
|
|
346
347
|
}
|
|
347
348
|
|
|
348
349
|
function clearTelegramAuthSession(state: string): void {
|
|
349
350
|
sessionStorage.removeItem(TELEGRAM_AUTH_STATE_KEY);
|
|
350
351
|
sessionStorage.removeItem(codeVerifierStorageKey(state));
|
|
351
|
-
sessionStorage.removeItem(
|
|
352
|
+
sessionStorage.removeItem(redirectUriStorageKey(state));
|
|
352
353
|
}
|
|
353
354
|
|
|
354
355
|
function takeTelegramAuthSession(state: string): {
|
|
355
356
|
codeVerifier: string | null;
|
|
356
|
-
|
|
357
|
+
redirectUri: string | null;
|
|
357
358
|
} | null {
|
|
358
359
|
const expectedState = sessionStorage.getItem(TELEGRAM_AUTH_STATE_KEY);
|
|
359
360
|
sessionStorage.removeItem(TELEGRAM_AUTH_STATE_KEY);
|
|
360
361
|
if (!expectedState || state !== expectedState) {
|
|
361
362
|
if (expectedState) {
|
|
362
363
|
sessionStorage.removeItem(codeVerifierStorageKey(expectedState));
|
|
363
|
-
sessionStorage.removeItem(
|
|
364
|
+
sessionStorage.removeItem(redirectUriStorageKey(expectedState));
|
|
364
365
|
}
|
|
365
366
|
return null;
|
|
366
367
|
}
|
|
367
368
|
|
|
368
369
|
const codeVerifierKey = codeVerifierStorageKey(state);
|
|
369
|
-
const
|
|
370
|
+
const redirectUriKey = redirectUriStorageKey(state);
|
|
370
371
|
const codeVerifier = sessionStorage.getItem(codeVerifierKey);
|
|
371
|
-
const
|
|
372
|
+
const redirectUri = sessionStorage.getItem(redirectUriKey);
|
|
372
373
|
sessionStorage.removeItem(codeVerifierKey);
|
|
373
|
-
sessionStorage.removeItem(
|
|
374
|
-
return { codeVerifier,
|
|
374
|
+
sessionStorage.removeItem(redirectUriKey);
|
|
375
|
+
return { codeVerifier, redirectUri };
|
|
375
376
|
}
|
|
376
377
|
|
|
377
378
|
function fallbackAuthTokenUrl(authHubUrl?: string): string {
|
|
@@ -454,20 +455,20 @@ async function exchangeTelegramAuthCode({
|
|
|
454
455
|
clientId,
|
|
455
456
|
code,
|
|
456
457
|
codeVerifier,
|
|
457
|
-
|
|
458
|
+
redirectUri,
|
|
458
459
|
}: {
|
|
459
460
|
authHubUrl?: string;
|
|
460
461
|
clientId: string;
|
|
461
462
|
code: string;
|
|
462
463
|
codeVerifier: string;
|
|
463
|
-
|
|
464
|
+
redirectUri: string;
|
|
464
465
|
}): Promise<string> {
|
|
465
466
|
const body = new URLSearchParams({
|
|
466
467
|
client_id: clientId,
|
|
467
468
|
code,
|
|
468
469
|
code_verifier: codeVerifier,
|
|
469
470
|
grant_type: "authorization_code",
|
|
470
|
-
|
|
471
|
+
redirect_uri: redirectUri,
|
|
471
472
|
});
|
|
472
473
|
|
|
473
474
|
const response = await fetch(await resolveAuthTokenUrl(authHubUrl), {
|
|
@@ -639,7 +640,7 @@ export function HypurrConnectProvider({
|
|
|
639
640
|
clientId: normalizeClientId(config.clientId),
|
|
640
641
|
code: callback.code,
|
|
641
642
|
codeVerifier: authSession.codeVerifier,
|
|
642
|
-
|
|
643
|
+
redirectUri: authSession.redirectUri || currentRedirectUri(),
|
|
643
644
|
})
|
|
644
645
|
.then(acceptTelegramToken)
|
|
645
646
|
.catch((err) =>
|
|
@@ -1642,12 +1643,12 @@ export function HypurrConnectProvider({
|
|
|
1642
1643
|
const state = randomState();
|
|
1643
1644
|
const codeVerifier = randomCodeVerifier();
|
|
1644
1645
|
|
|
1645
|
-
const
|
|
1646
|
-
const
|
|
1647
|
-
typeof
|
|
1648
|
-
?
|
|
1649
|
-
:
|
|
1650
|
-
storeTelegramAuthSession(state, codeVerifier,
|
|
1646
|
+
const configuredRedirectUri = config.telegram?.redirectUri;
|
|
1647
|
+
const redirectUri =
|
|
1648
|
+
typeof configuredRedirectUri === "function"
|
|
1649
|
+
? configuredRedirectUri()
|
|
1650
|
+
: configuredRedirectUri || currentRedirectUri();
|
|
1651
|
+
storeTelegramAuthSession(state, codeVerifier, redirectUri);
|
|
1651
1652
|
|
|
1652
1653
|
const width = 520;
|
|
1653
1654
|
const height = 720;
|
|
@@ -1675,7 +1676,8 @@ export function HypurrConnectProvider({
|
|
|
1675
1676
|
"client_id",
|
|
1676
1677
|
normalizeClientId(config.clientId),
|
|
1677
1678
|
);
|
|
1678
|
-
authUrl.searchParams.set("
|
|
1679
|
+
authUrl.searchParams.set("redirect_uri", redirectUri);
|
|
1680
|
+
authUrl.searchParams.set("return_to", redirectUri);
|
|
1679
1681
|
authUrl.searchParams.set("state", state);
|
|
1680
1682
|
authUrl.searchParams.set(
|
|
1681
1683
|
"scope",
|
|
@@ -1703,7 +1705,7 @@ export function HypurrConnectProvider({
|
|
|
1703
1705
|
}, [
|
|
1704
1706
|
config.clientId,
|
|
1705
1707
|
config.telegram?.authHubUrl,
|
|
1706
|
-
config.telegram?.
|
|
1708
|
+
config.telegram?.redirectUri,
|
|
1707
1709
|
config.telegram?.scope,
|
|
1708
1710
|
]);
|
|
1709
1711
|
|
package/src/types.ts
CHANGED
|
@@ -33,8 +33,8 @@ export interface HypurrConnectConfig {
|
|
|
33
33
|
telegram?: {
|
|
34
34
|
/** Auth hub login URL. Defaults to https://auth.hypurr.fun/login. */
|
|
35
35
|
authHubUrl?: string;
|
|
36
|
-
/** Optional
|
|
37
|
-
|
|
36
|
+
/** Optional OAuth redirect URI. Defaults to the current page without auth query params. */
|
|
37
|
+
redirectUri?: string | (() => string);
|
|
38
38
|
/** Requested hub scopes. Defaults to the scopes required by this SDK. */
|
|
39
39
|
scope?: string | string[];
|
|
40
40
|
/** @deprecated Telegram login is handled by the auth hub; this option is ignored. */
|