naystack 1.8.7 → 1.8.8
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/auth/index.cjs.js +31 -5
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.esm.js +30 -5
- package/dist/auth/instagram/index.cjs.js +31 -5
- package/dist/auth/instagram/index.d.mts +3 -3
- package/dist/auth/instagram/index.d.ts +3 -3
- package/dist/auth/instagram/index.esm.js +30 -5
- package/dist/auth/instagram/route.cjs.js +29 -5
- package/dist/auth/instagram/route.esm.js +29 -5
- package/dist/auth/instagram/utils.cjs.js +23 -0
- package/dist/auth/instagram/utils.d.mts +19 -1
- package/dist/auth/instagram/utils.d.ts +19 -1
- package/dist/auth/instagram/utils.esm.js +24 -0
- package/package.json +1 -1
package/dist/auth/index.cjs.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(auth_exports, {
|
|
|
33
33
|
AuthFetch: () => AuthFetch,
|
|
34
34
|
AuthWrapper: () => AuthWrapper,
|
|
35
35
|
checkAuthStatus: () => checkAuthStatus,
|
|
36
|
+
getAuthorizationHandoff: () => getAuthorizationHandoff,
|
|
36
37
|
getContext: () => getContext,
|
|
37
38
|
getInstagramAuthorizationURL: () => getInstagramAuthorizationURL,
|
|
38
39
|
getRefreshToken: () => getRefreshToken,
|
|
@@ -575,9 +576,30 @@ function setupGoogleAuth(props) {
|
|
|
575
576
|
}
|
|
576
577
|
|
|
577
578
|
// src/auth/instagram/route.ts
|
|
578
|
-
var
|
|
579
|
+
var import_server9 = require("next/server");
|
|
579
580
|
|
|
580
581
|
// src/auth/instagram/utils.ts
|
|
582
|
+
var import_server7 = require("next/server");
|
|
583
|
+
var HANDOFF_DELAY_MS = 1500;
|
|
584
|
+
function getAuthorizationHandoff(authorizationURL, providerName) {
|
|
585
|
+
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
586
|
+
/</g,
|
|
587
|
+
"\\u003c"
|
|
588
|
+
);
|
|
589
|
+
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
590
|
+
const safeProviderName = providerName.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
591
|
+
return new import_server7.NextResponse(
|
|
592
|
+
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Redirecting to ${safeProviderName}\u2026</title><style>body{margin:0;min-height:100dvh;display:flex;align-items:center;justify-content:center;font:500 15px/1.5 system-ui,-apple-system,sans-serif;color:#111}</style><script>setTimeout(function(){location.replace(${scriptSafeURL})},${HANDOFF_DELAY_MS})</script><noscript><meta http-equiv="refresh" content="2;url=${attributeSafeURL}"></noscript></head><body><p>Redirecting to ${safeProviderName}\u2026</p></body></html>`,
|
|
593
|
+
{
|
|
594
|
+
headers: {
|
|
595
|
+
"content-type": "text/html; charset=utf-8",
|
|
596
|
+
"cache-control": "no-store",
|
|
597
|
+
// The token is in the URL; keep it off the provider's referer log.
|
|
598
|
+
"referrer-policy": "no-referrer"
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
);
|
|
602
|
+
}
|
|
581
603
|
async function getRefreshedInstagramAccessToken(token) {
|
|
582
604
|
const request = await fetch(
|
|
583
605
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -640,7 +662,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
640
662
|
};
|
|
641
663
|
|
|
642
664
|
// src/socials/meta-webhook.ts
|
|
643
|
-
var
|
|
665
|
+
var import_server8 = require("next/server");
|
|
644
666
|
|
|
645
667
|
// src/auth/instagram/route.ts
|
|
646
668
|
var getInstagramRoute = ({
|
|
@@ -648,7 +670,7 @@ var getInstagramRoute = ({
|
|
|
648
670
|
errorRedirectURL,
|
|
649
671
|
onUser
|
|
650
672
|
}) => {
|
|
651
|
-
const handleError2 = (message) =>
|
|
673
|
+
const handleError2 = (message) => import_server9.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
652
674
|
return async (req) => {
|
|
653
675
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
654
676
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -656,7 +678,10 @@ var getInstagramRoute = ({
|
|
|
656
678
|
if (error) return handleError2(error);
|
|
657
679
|
if (!accessCode) {
|
|
658
680
|
if (!stateToken) return handleError2("Invalid request");
|
|
659
|
-
return
|
|
681
|
+
return getAuthorizationHandoff(
|
|
682
|
+
getInstagramAuthorizationURL(stateToken),
|
|
683
|
+
"Instagram"
|
|
684
|
+
);
|
|
660
685
|
}
|
|
661
686
|
if (!stateToken) return handleError2("Invalid request");
|
|
662
687
|
const instagramData = await getLongLivedToken(
|
|
@@ -676,7 +701,7 @@ var getInstagramRoute = ({
|
|
|
676
701
|
instagramData.accessToken
|
|
677
702
|
);
|
|
678
703
|
if (errorMessage) return handleError2(errorMessage);
|
|
679
|
-
return
|
|
704
|
+
return import_server9.NextResponse.redirect(redirectURL);
|
|
680
705
|
};
|
|
681
706
|
};
|
|
682
707
|
|
|
@@ -698,6 +723,7 @@ async function getRefreshToken() {
|
|
|
698
723
|
AuthFetch,
|
|
699
724
|
AuthWrapper,
|
|
700
725
|
checkAuthStatus,
|
|
726
|
+
getAuthorizationHandoff,
|
|
701
727
|
getContext,
|
|
702
728
|
getInstagramAuthorizationURL,
|
|
703
729
|
getRefreshToken,
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ export { getRefreshToken } from './utils/token.mjs';
|
|
|
5
5
|
export { AuthFetch, AuthWrapper } from './email/next.mjs';
|
|
6
6
|
export { checkAuthStatus, getTokenizedResponse } from './email/token.mjs';
|
|
7
7
|
export { getContext } from './email/utils.mjs';
|
|
8
|
-
export { getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './instagram/utils.mjs';
|
|
8
|
+
export { getAuthorizationHandoff, getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './instagram/utils.mjs';
|
|
9
9
|
import 'next/server';
|
|
10
10
|
import './email/types.mjs';
|
|
11
11
|
import './types.mjs';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { getRefreshToken } from './utils/token.js';
|
|
|
5
5
|
export { AuthFetch, AuthWrapper } from './email/next.js';
|
|
6
6
|
export { checkAuthStatus, getTokenizedResponse } from './email/token.js';
|
|
7
7
|
export { getContext } from './email/utils.js';
|
|
8
|
-
export { getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './instagram/utils.js';
|
|
8
|
+
export { getAuthorizationHandoff, getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './instagram/utils.js';
|
|
9
9
|
import 'next/server';
|
|
10
10
|
import './email/types.js';
|
|
11
11
|
import './types.js';
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -533,9 +533,30 @@ function setupGoogleAuth(props) {
|
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
// src/auth/instagram/route.ts
|
|
536
|
-
import { NextResponse as
|
|
536
|
+
import { NextResponse as NextResponse8 } from "next/server";
|
|
537
537
|
|
|
538
538
|
// src/auth/instagram/utils.ts
|
|
539
|
+
import { NextResponse as NextResponse6 } from "next/server";
|
|
540
|
+
var HANDOFF_DELAY_MS = 1500;
|
|
541
|
+
function getAuthorizationHandoff(authorizationURL, providerName) {
|
|
542
|
+
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
543
|
+
/</g,
|
|
544
|
+
"\\u003c"
|
|
545
|
+
);
|
|
546
|
+
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
547
|
+
const safeProviderName = providerName.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
548
|
+
return new NextResponse6(
|
|
549
|
+
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Redirecting to ${safeProviderName}\u2026</title><style>body{margin:0;min-height:100dvh;display:flex;align-items:center;justify-content:center;font:500 15px/1.5 system-ui,-apple-system,sans-serif;color:#111}</style><script>setTimeout(function(){location.replace(${scriptSafeURL})},${HANDOFF_DELAY_MS})</script><noscript><meta http-equiv="refresh" content="2;url=${attributeSafeURL}"></noscript></head><body><p>Redirecting to ${safeProviderName}\u2026</p></body></html>`,
|
|
550
|
+
{
|
|
551
|
+
headers: {
|
|
552
|
+
"content-type": "text/html; charset=utf-8",
|
|
553
|
+
"cache-control": "no-store",
|
|
554
|
+
// The token is in the URL; keep it off the provider's referer log.
|
|
555
|
+
"referrer-policy": "no-referrer"
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
);
|
|
559
|
+
}
|
|
539
560
|
async function getRefreshedInstagramAccessToken(token) {
|
|
540
561
|
const request = await fetch(
|
|
541
562
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -598,7 +619,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
598
619
|
};
|
|
599
620
|
|
|
600
621
|
// src/socials/meta-webhook.ts
|
|
601
|
-
import { NextResponse as
|
|
622
|
+
import { NextResponse as NextResponse7 } from "next/server";
|
|
602
623
|
|
|
603
624
|
// src/auth/instagram/route.ts
|
|
604
625
|
var getInstagramRoute = ({
|
|
@@ -606,7 +627,7 @@ var getInstagramRoute = ({
|
|
|
606
627
|
errorRedirectURL,
|
|
607
628
|
onUser
|
|
608
629
|
}) => {
|
|
609
|
-
const handleError2 = (message) =>
|
|
630
|
+
const handleError2 = (message) => NextResponse8.redirect(`${errorRedirectURL}?error=${message}`);
|
|
610
631
|
return async (req) => {
|
|
611
632
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
612
633
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -614,7 +635,10 @@ var getInstagramRoute = ({
|
|
|
614
635
|
if (error) return handleError2(error);
|
|
615
636
|
if (!accessCode) {
|
|
616
637
|
if (!stateToken) return handleError2("Invalid request");
|
|
617
|
-
return
|
|
638
|
+
return getAuthorizationHandoff(
|
|
639
|
+
getInstagramAuthorizationURL(stateToken),
|
|
640
|
+
"Instagram"
|
|
641
|
+
);
|
|
618
642
|
}
|
|
619
643
|
if (!stateToken) return handleError2("Invalid request");
|
|
620
644
|
const instagramData = await getLongLivedToken(
|
|
@@ -634,7 +658,7 @@ var getInstagramRoute = ({
|
|
|
634
658
|
instagramData.accessToken
|
|
635
659
|
);
|
|
636
660
|
if (errorMessage) return handleError2(errorMessage);
|
|
637
|
-
return
|
|
661
|
+
return NextResponse8.redirect(redirectURL);
|
|
638
662
|
};
|
|
639
663
|
};
|
|
640
664
|
|
|
@@ -655,6 +679,7 @@ export {
|
|
|
655
679
|
AuthFetch,
|
|
656
680
|
AuthWrapper,
|
|
657
681
|
checkAuthStatus,
|
|
682
|
+
getAuthorizationHandoff,
|
|
658
683
|
getContext,
|
|
659
684
|
getInstagramAuthorizationURL,
|
|
660
685
|
getRefreshToken,
|
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/instagram/index.ts
|
|
21
21
|
var instagram_exports = {};
|
|
22
22
|
__export(instagram_exports, {
|
|
23
|
+
getAuthorizationHandoff: () => getAuthorizationHandoff,
|
|
23
24
|
getInstagramAuthorizationURL: () => getInstagramAuthorizationURL,
|
|
24
25
|
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken,
|
|
25
26
|
setupInstagramAuth: () => setupInstagramAuth
|
|
@@ -27,7 +28,7 @@ __export(instagram_exports, {
|
|
|
27
28
|
module.exports = __toCommonJS(instagram_exports);
|
|
28
29
|
|
|
29
30
|
// src/auth/instagram/route.ts
|
|
30
|
-
var
|
|
31
|
+
var import_server4 = require("next/server");
|
|
31
32
|
|
|
32
33
|
// src/auth/email/token.ts
|
|
33
34
|
var import_bcryptjs = require("bcryptjs");
|
|
@@ -101,6 +102,27 @@ function getUserIdFromAccessToken(accessToken) {
|
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
// src/auth/instagram/utils.ts
|
|
105
|
+
var import_server2 = require("next/server");
|
|
106
|
+
var HANDOFF_DELAY_MS = 1500;
|
|
107
|
+
function getAuthorizationHandoff(authorizationURL, providerName) {
|
|
108
|
+
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
109
|
+
/</g,
|
|
110
|
+
"\\u003c"
|
|
111
|
+
);
|
|
112
|
+
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
113
|
+
const safeProviderName = providerName.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
114
|
+
return new import_server2.NextResponse(
|
|
115
|
+
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Redirecting to ${safeProviderName}\u2026</title><style>body{margin:0;min-height:100dvh;display:flex;align-items:center;justify-content:center;font:500 15px/1.5 system-ui,-apple-system,sans-serif;color:#111}</style><script>setTimeout(function(){location.replace(${scriptSafeURL})},${HANDOFF_DELAY_MS})</script><noscript><meta http-equiv="refresh" content="2;url=${attributeSafeURL}"></noscript></head><body><p>Redirecting to ${safeProviderName}\u2026</p></body></html>`,
|
|
116
|
+
{
|
|
117
|
+
headers: {
|
|
118
|
+
"content-type": "text/html; charset=utf-8",
|
|
119
|
+
"cache-control": "no-store",
|
|
120
|
+
// The token is in the URL; keep it off the provider's referer log.
|
|
121
|
+
"referrer-policy": "no-referrer"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
104
126
|
async function getRefreshedInstagramAccessToken(token) {
|
|
105
127
|
const request = await fetch(
|
|
106
128
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -163,7 +185,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
163
185
|
};
|
|
164
186
|
|
|
165
187
|
// src/socials/meta-webhook.ts
|
|
166
|
-
var
|
|
188
|
+
var import_server3 = require("next/server");
|
|
167
189
|
|
|
168
190
|
// src/auth/instagram/route.ts
|
|
169
191
|
var getInstagramRoute = ({
|
|
@@ -171,7 +193,7 @@ var getInstagramRoute = ({
|
|
|
171
193
|
errorRedirectURL,
|
|
172
194
|
onUser
|
|
173
195
|
}) => {
|
|
174
|
-
const handleError = (message) =>
|
|
196
|
+
const handleError = (message) => import_server4.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
175
197
|
return async (req) => {
|
|
176
198
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
177
199
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -179,7 +201,10 @@ var getInstagramRoute = ({
|
|
|
179
201
|
if (error) return handleError(error);
|
|
180
202
|
if (!accessCode) {
|
|
181
203
|
if (!stateToken) return handleError("Invalid request");
|
|
182
|
-
return
|
|
204
|
+
return getAuthorizationHandoff(
|
|
205
|
+
getInstagramAuthorizationURL(stateToken),
|
|
206
|
+
"Instagram"
|
|
207
|
+
);
|
|
183
208
|
}
|
|
184
209
|
if (!stateToken) return handleError("Invalid request");
|
|
185
210
|
const instagramData = await getLongLivedToken(
|
|
@@ -199,7 +224,7 @@ var getInstagramRoute = ({
|
|
|
199
224
|
instagramData.accessToken
|
|
200
225
|
);
|
|
201
226
|
if (errorMessage) return handleError(errorMessage);
|
|
202
|
-
return
|
|
227
|
+
return import_server4.NextResponse.redirect(redirectURL);
|
|
203
228
|
};
|
|
204
229
|
};
|
|
205
230
|
|
|
@@ -211,6 +236,7 @@ function setupInstagramAuth(props) {
|
|
|
211
236
|
}
|
|
212
237
|
// Annotate the CommonJS export names for ESM import in node:
|
|
213
238
|
0 && (module.exports = {
|
|
239
|
+
getAuthorizationHandoff,
|
|
214
240
|
getInstagramAuthorizationURL,
|
|
215
241
|
getRefreshedInstagramAccessToken,
|
|
216
242
|
setupInstagramAuth
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
-
export { getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './utils.mjs';
|
|
2
|
+
export { getAuthorizationHandoff, getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './utils.mjs';
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -22,8 +22,8 @@ interface SetupInstagramAuthOptions {
|
|
|
22
22
|
* Mount the GET handler on your Instagram auth route (e.g. `app/api/(auth)/instagram/route.ts`).
|
|
23
23
|
*
|
|
24
24
|
* The single GET handler serves both the OAuth callback (`?code`) and the connect
|
|
25
|
-
* entry point (`?state` with no code →
|
|
26
|
-
*
|
|
25
|
+
* entry point (`?state` with no code → an interstitial page that waits, then jumps
|
|
26
|
+
* to Instagram's authorize URL; see {@link getAuthorizationHandoff}).
|
|
27
27
|
*
|
|
28
28
|
* Requires env vars: `INSTAGRAM_CLIENT_ID` (server-only), `INSTAGRAM_CLIENT_SECRET`, `NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT`.
|
|
29
29
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
-
export { getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './utils.js';
|
|
2
|
+
export { getAuthorizationHandoff, getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './utils.js';
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -22,8 +22,8 @@ interface SetupInstagramAuthOptions {
|
|
|
22
22
|
* Mount the GET handler on your Instagram auth route (e.g. `app/api/(auth)/instagram/route.ts`).
|
|
23
23
|
*
|
|
24
24
|
* The single GET handler serves both the OAuth callback (`?code`) and the connect
|
|
25
|
-
* entry point (`?state` with no code →
|
|
26
|
-
*
|
|
25
|
+
* entry point (`?state` with no code → an interstitial page that waits, then jumps
|
|
26
|
+
* to Instagram's authorize URL; see {@link getAuthorizationHandoff}).
|
|
27
27
|
*
|
|
28
28
|
* Requires env vars: `INSTAGRAM_CLIENT_ID` (server-only), `INSTAGRAM_CLIENT_SECRET`, `NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT`.
|
|
29
29
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/auth/instagram/route.ts
|
|
2
|
-
import { NextResponse as
|
|
2
|
+
import { NextResponse as NextResponse4 } from "next/server";
|
|
3
3
|
|
|
4
4
|
// src/auth/email/token.ts
|
|
5
5
|
import { compare } from "bcryptjs";
|
|
@@ -73,6 +73,27 @@ function getUserIdFromAccessToken(accessToken) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// src/auth/instagram/utils.ts
|
|
76
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
77
|
+
var HANDOFF_DELAY_MS = 1500;
|
|
78
|
+
function getAuthorizationHandoff(authorizationURL, providerName) {
|
|
79
|
+
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
80
|
+
/</g,
|
|
81
|
+
"\\u003c"
|
|
82
|
+
);
|
|
83
|
+
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
84
|
+
const safeProviderName = providerName.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
85
|
+
return new NextResponse2(
|
|
86
|
+
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Redirecting to ${safeProviderName}\u2026</title><style>body{margin:0;min-height:100dvh;display:flex;align-items:center;justify-content:center;font:500 15px/1.5 system-ui,-apple-system,sans-serif;color:#111}</style><script>setTimeout(function(){location.replace(${scriptSafeURL})},${HANDOFF_DELAY_MS})</script><noscript><meta http-equiv="refresh" content="2;url=${attributeSafeURL}"></noscript></head><body><p>Redirecting to ${safeProviderName}\u2026</p></body></html>`,
|
|
87
|
+
{
|
|
88
|
+
headers: {
|
|
89
|
+
"content-type": "text/html; charset=utf-8",
|
|
90
|
+
"cache-control": "no-store",
|
|
91
|
+
// The token is in the URL; keep it off the provider's referer log.
|
|
92
|
+
"referrer-policy": "no-referrer"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
76
97
|
async function getRefreshedInstagramAccessToken(token) {
|
|
77
98
|
const request = await fetch(
|
|
78
99
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -135,7 +156,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
135
156
|
};
|
|
136
157
|
|
|
137
158
|
// src/socials/meta-webhook.ts
|
|
138
|
-
import { NextResponse as
|
|
159
|
+
import { NextResponse as NextResponse3 } from "next/server";
|
|
139
160
|
|
|
140
161
|
// src/auth/instagram/route.ts
|
|
141
162
|
var getInstagramRoute = ({
|
|
@@ -143,7 +164,7 @@ var getInstagramRoute = ({
|
|
|
143
164
|
errorRedirectURL,
|
|
144
165
|
onUser
|
|
145
166
|
}) => {
|
|
146
|
-
const handleError = (message) =>
|
|
167
|
+
const handleError = (message) => NextResponse4.redirect(`${errorRedirectURL}?error=${message}`);
|
|
147
168
|
return async (req) => {
|
|
148
169
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
149
170
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -151,7 +172,10 @@ var getInstagramRoute = ({
|
|
|
151
172
|
if (error) return handleError(error);
|
|
152
173
|
if (!accessCode) {
|
|
153
174
|
if (!stateToken) return handleError("Invalid request");
|
|
154
|
-
return
|
|
175
|
+
return getAuthorizationHandoff(
|
|
176
|
+
getInstagramAuthorizationURL(stateToken),
|
|
177
|
+
"Instagram"
|
|
178
|
+
);
|
|
155
179
|
}
|
|
156
180
|
if (!stateToken) return handleError("Invalid request");
|
|
157
181
|
const instagramData = await getLongLivedToken(
|
|
@@ -171,7 +195,7 @@ var getInstagramRoute = ({
|
|
|
171
195
|
instagramData.accessToken
|
|
172
196
|
);
|
|
173
197
|
if (errorMessage) return handleError(errorMessage);
|
|
174
|
-
return
|
|
198
|
+
return NextResponse4.redirect(redirectURL);
|
|
175
199
|
};
|
|
176
200
|
};
|
|
177
201
|
|
|
@@ -182,6 +206,7 @@ function setupInstagramAuth(props) {
|
|
|
182
206
|
};
|
|
183
207
|
}
|
|
184
208
|
export {
|
|
209
|
+
getAuthorizationHandoff,
|
|
185
210
|
getInstagramAuthorizationURL,
|
|
186
211
|
getRefreshedInstagramAccessToken,
|
|
187
212
|
setupInstagramAuth
|
|
@@ -23,7 +23,7 @@ __export(route_exports, {
|
|
|
23
23
|
getInstagramRoute: () => getInstagramRoute
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(route_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_server4 = require("next/server");
|
|
27
27
|
|
|
28
28
|
// src/auth/email/token.ts
|
|
29
29
|
var import_bcryptjs = require("bcryptjs");
|
|
@@ -97,6 +97,27 @@ function getUserIdFromAccessToken(accessToken) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// src/auth/instagram/utils.ts
|
|
100
|
+
var import_server2 = require("next/server");
|
|
101
|
+
var HANDOFF_DELAY_MS = 1500;
|
|
102
|
+
function getAuthorizationHandoff(authorizationURL, providerName) {
|
|
103
|
+
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
104
|
+
/</g,
|
|
105
|
+
"\\u003c"
|
|
106
|
+
);
|
|
107
|
+
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
108
|
+
const safeProviderName = providerName.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
109
|
+
return new import_server2.NextResponse(
|
|
110
|
+
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Redirecting to ${safeProviderName}\u2026</title><style>body{margin:0;min-height:100dvh;display:flex;align-items:center;justify-content:center;font:500 15px/1.5 system-ui,-apple-system,sans-serif;color:#111}</style><script>setTimeout(function(){location.replace(${scriptSafeURL})},${HANDOFF_DELAY_MS})</script><noscript><meta http-equiv="refresh" content="2;url=${attributeSafeURL}"></noscript></head><body><p>Redirecting to ${safeProviderName}\u2026</p></body></html>`,
|
|
111
|
+
{
|
|
112
|
+
headers: {
|
|
113
|
+
"content-type": "text/html; charset=utf-8",
|
|
114
|
+
"cache-control": "no-store",
|
|
115
|
+
// The token is in the URL; keep it off the provider's referer log.
|
|
116
|
+
"referrer-policy": "no-referrer"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
}
|
|
100
121
|
async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
101
122
|
const formData = new FormData();
|
|
102
123
|
formData.set("client_id", clientId);
|
|
@@ -152,7 +173,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
152
173
|
};
|
|
153
174
|
|
|
154
175
|
// src/socials/meta-webhook.ts
|
|
155
|
-
var
|
|
176
|
+
var import_server3 = require("next/server");
|
|
156
177
|
|
|
157
178
|
// src/auth/instagram/route.ts
|
|
158
179
|
var getInstagramRoute = ({
|
|
@@ -160,7 +181,7 @@ var getInstagramRoute = ({
|
|
|
160
181
|
errorRedirectURL,
|
|
161
182
|
onUser
|
|
162
183
|
}) => {
|
|
163
|
-
const handleError = (message) =>
|
|
184
|
+
const handleError = (message) => import_server4.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
164
185
|
return async (req) => {
|
|
165
186
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
166
187
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -168,7 +189,10 @@ var getInstagramRoute = ({
|
|
|
168
189
|
if (error) return handleError(error);
|
|
169
190
|
if (!accessCode) {
|
|
170
191
|
if (!stateToken) return handleError("Invalid request");
|
|
171
|
-
return
|
|
192
|
+
return getAuthorizationHandoff(
|
|
193
|
+
getInstagramAuthorizationURL(stateToken),
|
|
194
|
+
"Instagram"
|
|
195
|
+
);
|
|
172
196
|
}
|
|
173
197
|
if (!stateToken) return handleError("Invalid request");
|
|
174
198
|
const instagramData = await getLongLivedToken(
|
|
@@ -188,7 +212,7 @@ var getInstagramRoute = ({
|
|
|
188
212
|
instagramData.accessToken
|
|
189
213
|
);
|
|
190
214
|
if (errorMessage) return handleError(errorMessage);
|
|
191
|
-
return
|
|
215
|
+
return import_server4.NextResponse.redirect(redirectURL);
|
|
192
216
|
};
|
|
193
217
|
};
|
|
194
218
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/auth/instagram/route.ts
|
|
2
|
-
import { NextResponse as
|
|
2
|
+
import { NextResponse as NextResponse4 } from "next/server";
|
|
3
3
|
|
|
4
4
|
// src/auth/email/token.ts
|
|
5
5
|
import { compare } from "bcryptjs";
|
|
@@ -73,6 +73,27 @@ function getUserIdFromAccessToken(accessToken) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// src/auth/instagram/utils.ts
|
|
76
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
77
|
+
var HANDOFF_DELAY_MS = 1500;
|
|
78
|
+
function getAuthorizationHandoff(authorizationURL, providerName) {
|
|
79
|
+
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
80
|
+
/</g,
|
|
81
|
+
"\\u003c"
|
|
82
|
+
);
|
|
83
|
+
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
84
|
+
const safeProviderName = providerName.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
85
|
+
return new NextResponse2(
|
|
86
|
+
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Redirecting to ${safeProviderName}\u2026</title><style>body{margin:0;min-height:100dvh;display:flex;align-items:center;justify-content:center;font:500 15px/1.5 system-ui,-apple-system,sans-serif;color:#111}</style><script>setTimeout(function(){location.replace(${scriptSafeURL})},${HANDOFF_DELAY_MS})</script><noscript><meta http-equiv="refresh" content="2;url=${attributeSafeURL}"></noscript></head><body><p>Redirecting to ${safeProviderName}\u2026</p></body></html>`,
|
|
87
|
+
{
|
|
88
|
+
headers: {
|
|
89
|
+
"content-type": "text/html; charset=utf-8",
|
|
90
|
+
"cache-control": "no-store",
|
|
91
|
+
// The token is in the URL; keep it off the provider's referer log.
|
|
92
|
+
"referrer-policy": "no-referrer"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
76
97
|
async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
77
98
|
const formData = new FormData();
|
|
78
99
|
formData.set("client_id", clientId);
|
|
@@ -128,7 +149,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
128
149
|
};
|
|
129
150
|
|
|
130
151
|
// src/socials/meta-webhook.ts
|
|
131
|
-
import { NextResponse as
|
|
152
|
+
import { NextResponse as NextResponse3 } from "next/server";
|
|
132
153
|
|
|
133
154
|
// src/auth/instagram/route.ts
|
|
134
155
|
var getInstagramRoute = ({
|
|
@@ -136,7 +157,7 @@ var getInstagramRoute = ({
|
|
|
136
157
|
errorRedirectURL,
|
|
137
158
|
onUser
|
|
138
159
|
}) => {
|
|
139
|
-
const handleError = (message) =>
|
|
160
|
+
const handleError = (message) => NextResponse4.redirect(`${errorRedirectURL}?error=${message}`);
|
|
140
161
|
return async (req) => {
|
|
141
162
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
142
163
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -144,7 +165,10 @@ var getInstagramRoute = ({
|
|
|
144
165
|
if (error) return handleError(error);
|
|
145
166
|
if (!accessCode) {
|
|
146
167
|
if (!stateToken) return handleError("Invalid request");
|
|
147
|
-
return
|
|
168
|
+
return getAuthorizationHandoff(
|
|
169
|
+
getInstagramAuthorizationURL(stateToken),
|
|
170
|
+
"Instagram"
|
|
171
|
+
);
|
|
148
172
|
}
|
|
149
173
|
if (!stateToken) return handleError("Invalid request");
|
|
150
174
|
const instagramData = await getLongLivedToken(
|
|
@@ -164,7 +188,7 @@ var getInstagramRoute = ({
|
|
|
164
188
|
instagramData.accessToken
|
|
165
189
|
);
|
|
166
190
|
if (errorMessage) return handleError(errorMessage);
|
|
167
|
-
return
|
|
191
|
+
return NextResponse4.redirect(redirectURL);
|
|
168
192
|
};
|
|
169
193
|
};
|
|
170
194
|
export {
|
|
@@ -20,11 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/instagram/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
+
getAuthorizationHandoff: () => getAuthorizationHandoff,
|
|
23
24
|
getInstagramAuthorizationURL: () => getInstagramAuthorizationURL,
|
|
24
25
|
getLongLivedToken: () => getLongLivedToken,
|
|
25
26
|
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(utils_exports);
|
|
29
|
+
var import_server = require("next/server");
|
|
28
30
|
|
|
29
31
|
// src/env.ts
|
|
30
32
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -77,6 +79,26 @@ function getEnv(key, skipCheck) {
|
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
// src/auth/instagram/utils.ts
|
|
82
|
+
var HANDOFF_DELAY_MS = 1500;
|
|
83
|
+
function getAuthorizationHandoff(authorizationURL, providerName) {
|
|
84
|
+
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
85
|
+
/</g,
|
|
86
|
+
"\\u003c"
|
|
87
|
+
);
|
|
88
|
+
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
89
|
+
const safeProviderName = providerName.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
90
|
+
return new import_server.NextResponse(
|
|
91
|
+
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Redirecting to ${safeProviderName}\u2026</title><style>body{margin:0;min-height:100dvh;display:flex;align-items:center;justify-content:center;font:500 15px/1.5 system-ui,-apple-system,sans-serif;color:#111}</style><script>setTimeout(function(){location.replace(${scriptSafeURL})},${HANDOFF_DELAY_MS})</script><noscript><meta http-equiv="refresh" content="2;url=${attributeSafeURL}"></noscript></head><body><p>Redirecting to ${safeProviderName}\u2026</p></body></html>`,
|
|
92
|
+
{
|
|
93
|
+
headers: {
|
|
94
|
+
"content-type": "text/html; charset=utf-8",
|
|
95
|
+
"cache-control": "no-store",
|
|
96
|
+
// The token is in the URL; keep it off the provider's referer log.
|
|
97
|
+
"referrer-policy": "no-referrer"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
80
102
|
async function getRefreshedInstagramAccessToken(token) {
|
|
81
103
|
const request = await fetch(
|
|
82
104
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -117,6 +139,7 @@ var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/a
|
|
|
117
139
|
)}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${getEnv("NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT" /* NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT */)}`;
|
|
118
140
|
// Annotate the CommonJS export names for ESM import in node:
|
|
119
141
|
0 && (module.exports = {
|
|
142
|
+
getAuthorizationHandoff,
|
|
120
143
|
getInstagramAuthorizationURL,
|
|
121
144
|
getLongLivedToken,
|
|
122
145
|
getRefreshedInstagramAccessToken
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builds the interstitial document that carries the browser from our origin to a
|
|
5
|
+
* provider's authorization page: it renders, waits {@link HANDOFF_DELAY_MS}, then
|
|
6
|
+
* replaces itself with `authorizationURL`.
|
|
7
|
+
*
|
|
8
|
+
* `location.replace` keeps the interstitial out of session history, so Back from
|
|
9
|
+
* the provider returns to the page that started the flow. The `noscript` meta
|
|
10
|
+
* refresh is a fallback, not the primary path.
|
|
11
|
+
*
|
|
12
|
+
* @param authorizationURL - Provider authorization URL to hand the browser off to
|
|
13
|
+
* @param providerName - Shown to the user while waiting, e.g. `"Instagram"`
|
|
14
|
+
* @returns HTML response that redirects client-side after a delay
|
|
15
|
+
*
|
|
16
|
+
* @category Auth
|
|
17
|
+
*/
|
|
18
|
+
declare function getAuthorizationHandoff(authorizationURL: string, providerName: string): NextResponse<unknown>;
|
|
1
19
|
/**
|
|
2
20
|
* Exchanges a long-lived Instagram token for a refreshed token.
|
|
3
21
|
* @param token - Current long-lived access token
|
|
@@ -43,4 +61,4 @@ declare function getLongLivedToken(code: string, redirectURL: string, clientId:
|
|
|
43
61
|
*/
|
|
44
62
|
declare const getInstagramAuthorizationURL: (token: string) => string;
|
|
45
63
|
|
|
46
|
-
export { getInstagramAuthorizationURL, getLongLivedToken, getRefreshedInstagramAccessToken };
|
|
64
|
+
export { getAuthorizationHandoff, getInstagramAuthorizationURL, getLongLivedToken, getRefreshedInstagramAccessToken };
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builds the interstitial document that carries the browser from our origin to a
|
|
5
|
+
* provider's authorization page: it renders, waits {@link HANDOFF_DELAY_MS}, then
|
|
6
|
+
* replaces itself with `authorizationURL`.
|
|
7
|
+
*
|
|
8
|
+
* `location.replace` keeps the interstitial out of session history, so Back from
|
|
9
|
+
* the provider returns to the page that started the flow. The `noscript` meta
|
|
10
|
+
* refresh is a fallback, not the primary path.
|
|
11
|
+
*
|
|
12
|
+
* @param authorizationURL - Provider authorization URL to hand the browser off to
|
|
13
|
+
* @param providerName - Shown to the user while waiting, e.g. `"Instagram"`
|
|
14
|
+
* @returns HTML response that redirects client-side after a delay
|
|
15
|
+
*
|
|
16
|
+
* @category Auth
|
|
17
|
+
*/
|
|
18
|
+
declare function getAuthorizationHandoff(authorizationURL: string, providerName: string): NextResponse<unknown>;
|
|
1
19
|
/**
|
|
2
20
|
* Exchanges a long-lived Instagram token for a refreshed token.
|
|
3
21
|
* @param token - Current long-lived access token
|
|
@@ -43,4 +61,4 @@ declare function getLongLivedToken(code: string, redirectURL: string, clientId:
|
|
|
43
61
|
*/
|
|
44
62
|
declare const getInstagramAuthorizationURL: (token: string) => string;
|
|
45
63
|
|
|
46
|
-
export { getInstagramAuthorizationURL, getLongLivedToken, getRefreshedInstagramAccessToken };
|
|
64
|
+
export { getAuthorizationHandoff, getInstagramAuthorizationURL, getLongLivedToken, getRefreshedInstagramAccessToken };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/auth/instagram/utils.ts
|
|
2
|
+
import { NextResponse } from "next/server";
|
|
3
|
+
|
|
1
4
|
// src/env.ts
|
|
2
5
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
3
6
|
var getEnvValue = (key) => {
|
|
@@ -49,6 +52,26 @@ function getEnv(key, skipCheck) {
|
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
// src/auth/instagram/utils.ts
|
|
55
|
+
var HANDOFF_DELAY_MS = 1500;
|
|
56
|
+
function getAuthorizationHandoff(authorizationURL, providerName) {
|
|
57
|
+
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
58
|
+
/</g,
|
|
59
|
+
"\\u003c"
|
|
60
|
+
);
|
|
61
|
+
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
62
|
+
const safeProviderName = providerName.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
63
|
+
return new NextResponse(
|
|
64
|
+
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Redirecting to ${safeProviderName}\u2026</title><style>body{margin:0;min-height:100dvh;display:flex;align-items:center;justify-content:center;font:500 15px/1.5 system-ui,-apple-system,sans-serif;color:#111}</style><script>setTimeout(function(){location.replace(${scriptSafeURL})},${HANDOFF_DELAY_MS})</script><noscript><meta http-equiv="refresh" content="2;url=${attributeSafeURL}"></noscript></head><body><p>Redirecting to ${safeProviderName}\u2026</p></body></html>`,
|
|
65
|
+
{
|
|
66
|
+
headers: {
|
|
67
|
+
"content-type": "text/html; charset=utf-8",
|
|
68
|
+
"cache-control": "no-store",
|
|
69
|
+
// The token is in the URL; keep it off the provider's referer log.
|
|
70
|
+
"referrer-policy": "no-referrer"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
52
75
|
async function getRefreshedInstagramAccessToken(token) {
|
|
53
76
|
const request = await fetch(
|
|
54
77
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -88,6 +111,7 @@ var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/a
|
|
|
88
111
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
89
112
|
)}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${getEnv("NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT" /* NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT */)}`;
|
|
90
113
|
export {
|
|
114
|
+
getAuthorizationHandoff,
|
|
91
115
|
getInstagramAuthorizationURL,
|
|
92
116
|
getLongLivedToken,
|
|
93
117
|
getRefreshedInstagramAccessToken
|