naystack 1.8.6 → 1.8.7
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 +6 -27
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.esm.js +6 -26
- package/dist/auth/instagram/index.cjs.js +6 -27
- package/dist/auth/instagram/index.d.mts +3 -4
- package/dist/auth/instagram/index.d.ts +3 -4
- package/dist/auth/instagram/index.esm.js +6 -26
- package/dist/auth/instagram/route.cjs.js +6 -25
- package/dist/auth/instagram/route.esm.js +6 -25
- package/dist/auth/instagram/utils.cjs.js +1 -22
- package/dist/auth/instagram/utils.d.mts +4 -30
- package/dist/auth/instagram/utils.d.ts +4 -30
- package/dist/auth/instagram/utils.esm.js +1 -23
- package/package.json +1 -1
package/dist/auth/index.cjs.js
CHANGED
|
@@ -33,7 +33,6 @@ __export(auth_exports, {
|
|
|
33
33
|
AuthFetch: () => AuthFetch,
|
|
34
34
|
AuthWrapper: () => AuthWrapper,
|
|
35
35
|
checkAuthStatus: () => checkAuthStatus,
|
|
36
|
-
getAuthorizationHandoff: () => getAuthorizationHandoff,
|
|
37
36
|
getContext: () => getContext,
|
|
38
37
|
getInstagramAuthorizationURL: () => getInstagramAuthorizationURL,
|
|
39
38
|
getRefreshToken: () => getRefreshToken,
|
|
@@ -576,28 +575,9 @@ function setupGoogleAuth(props) {
|
|
|
576
575
|
}
|
|
577
576
|
|
|
578
577
|
// src/auth/instagram/route.ts
|
|
579
|
-
var
|
|
578
|
+
var import_server8 = require("next/server");
|
|
580
579
|
|
|
581
580
|
// src/auth/instagram/utils.ts
|
|
582
|
-
var import_server7 = require("next/server");
|
|
583
|
-
function getAuthorizationHandoff(authorizationURL) {
|
|
584
|
-
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
585
|
-
/</g,
|
|
586
|
-
"\\u003c"
|
|
587
|
-
);
|
|
588
|
-
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
589
|
-
return new import_server7.NextResponse(
|
|
590
|
-
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Connecting\u2026</title><script>location.replace(${scriptSafeURL})</script><noscript><meta http-equiv="refresh" content="0;url=${attributeSafeURL}"></noscript></head><body></body></html>`,
|
|
591
|
-
{
|
|
592
|
-
headers: {
|
|
593
|
-
"content-type": "text/html; charset=utf-8",
|
|
594
|
-
"cache-control": "no-store",
|
|
595
|
-
// The token is in the URL; keep it off the provider's referer log.
|
|
596
|
-
"referrer-policy": "no-referrer"
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
581
|
async function getRefreshedInstagramAccessToken(token) {
|
|
602
582
|
const request = await fetch(
|
|
603
583
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -633,7 +613,7 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
633
613
|
}
|
|
634
614
|
}
|
|
635
615
|
}
|
|
636
|
-
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize
|
|
616
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize/?client_id=${getEnv(
|
|
637
617
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
638
618
|
)}&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 */)}`;
|
|
639
619
|
|
|
@@ -660,7 +640,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
660
640
|
};
|
|
661
641
|
|
|
662
642
|
// src/socials/meta-webhook.ts
|
|
663
|
-
var
|
|
643
|
+
var import_server7 = require("next/server");
|
|
664
644
|
|
|
665
645
|
// src/auth/instagram/route.ts
|
|
666
646
|
var getInstagramRoute = ({
|
|
@@ -668,7 +648,7 @@ var getInstagramRoute = ({
|
|
|
668
648
|
errorRedirectURL,
|
|
669
649
|
onUser
|
|
670
650
|
}) => {
|
|
671
|
-
const handleError2 = (message) =>
|
|
651
|
+
const handleError2 = (message) => import_server8.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
672
652
|
return async (req) => {
|
|
673
653
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
674
654
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -676,7 +656,7 @@ var getInstagramRoute = ({
|
|
|
676
656
|
if (error) return handleError2(error);
|
|
677
657
|
if (!accessCode) {
|
|
678
658
|
if (!stateToken) return handleError2("Invalid request");
|
|
679
|
-
return
|
|
659
|
+
return import_server8.NextResponse.redirect(getInstagramAuthorizationURL(stateToken), 302);
|
|
680
660
|
}
|
|
681
661
|
if (!stateToken) return handleError2("Invalid request");
|
|
682
662
|
const instagramData = await getLongLivedToken(
|
|
@@ -696,7 +676,7 @@ var getInstagramRoute = ({
|
|
|
696
676
|
instagramData.accessToken
|
|
697
677
|
);
|
|
698
678
|
if (errorMessage) return handleError2(errorMessage);
|
|
699
|
-
return
|
|
679
|
+
return import_server8.NextResponse.redirect(redirectURL);
|
|
700
680
|
};
|
|
701
681
|
};
|
|
702
682
|
|
|
@@ -718,7 +698,6 @@ async function getRefreshToken() {
|
|
|
718
698
|
AuthFetch,
|
|
719
699
|
AuthWrapper,
|
|
720
700
|
checkAuthStatus,
|
|
721
|
-
getAuthorizationHandoff,
|
|
722
701
|
getContext,
|
|
723
702
|
getInstagramAuthorizationURL,
|
|
724
703
|
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 {
|
|
8
|
+
export { 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 {
|
|
8
|
+
export { 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,28 +533,9 @@ function setupGoogleAuth(props) {
|
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
// src/auth/instagram/route.ts
|
|
536
|
-
import { NextResponse as
|
|
536
|
+
import { NextResponse as NextResponse7 } from "next/server";
|
|
537
537
|
|
|
538
538
|
// src/auth/instagram/utils.ts
|
|
539
|
-
import { NextResponse as NextResponse6 } from "next/server";
|
|
540
|
-
function getAuthorizationHandoff(authorizationURL) {
|
|
541
|
-
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
542
|
-
/</g,
|
|
543
|
-
"\\u003c"
|
|
544
|
-
);
|
|
545
|
-
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
546
|
-
return new NextResponse6(
|
|
547
|
-
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Connecting\u2026</title><script>location.replace(${scriptSafeURL})</script><noscript><meta http-equiv="refresh" content="0;url=${attributeSafeURL}"></noscript></head><body></body></html>`,
|
|
548
|
-
{
|
|
549
|
-
headers: {
|
|
550
|
-
"content-type": "text/html; charset=utf-8",
|
|
551
|
-
"cache-control": "no-store",
|
|
552
|
-
// The token is in the URL; keep it off the provider's referer log.
|
|
553
|
-
"referrer-policy": "no-referrer"
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
539
|
async function getRefreshedInstagramAccessToken(token) {
|
|
559
540
|
const request = await fetch(
|
|
560
541
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -590,7 +571,7 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
590
571
|
}
|
|
591
572
|
}
|
|
592
573
|
}
|
|
593
|
-
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize
|
|
574
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize/?client_id=${getEnv(
|
|
594
575
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
595
576
|
)}&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 */)}`;
|
|
596
577
|
|
|
@@ -617,7 +598,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
617
598
|
};
|
|
618
599
|
|
|
619
600
|
// src/socials/meta-webhook.ts
|
|
620
|
-
import { NextResponse as
|
|
601
|
+
import { NextResponse as NextResponse6 } from "next/server";
|
|
621
602
|
|
|
622
603
|
// src/auth/instagram/route.ts
|
|
623
604
|
var getInstagramRoute = ({
|
|
@@ -625,7 +606,7 @@ var getInstagramRoute = ({
|
|
|
625
606
|
errorRedirectURL,
|
|
626
607
|
onUser
|
|
627
608
|
}) => {
|
|
628
|
-
const handleError2 = (message) =>
|
|
609
|
+
const handleError2 = (message) => NextResponse7.redirect(`${errorRedirectURL}?error=${message}`);
|
|
629
610
|
return async (req) => {
|
|
630
611
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
631
612
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -633,7 +614,7 @@ var getInstagramRoute = ({
|
|
|
633
614
|
if (error) return handleError2(error);
|
|
634
615
|
if (!accessCode) {
|
|
635
616
|
if (!stateToken) return handleError2("Invalid request");
|
|
636
|
-
return
|
|
617
|
+
return NextResponse7.redirect(getInstagramAuthorizationURL(stateToken), 302);
|
|
637
618
|
}
|
|
638
619
|
if (!stateToken) return handleError2("Invalid request");
|
|
639
620
|
const instagramData = await getLongLivedToken(
|
|
@@ -653,7 +634,7 @@ var getInstagramRoute = ({
|
|
|
653
634
|
instagramData.accessToken
|
|
654
635
|
);
|
|
655
636
|
if (errorMessage) return handleError2(errorMessage);
|
|
656
|
-
return
|
|
637
|
+
return NextResponse7.redirect(redirectURL);
|
|
657
638
|
};
|
|
658
639
|
};
|
|
659
640
|
|
|
@@ -674,7 +655,6 @@ export {
|
|
|
674
655
|
AuthFetch,
|
|
675
656
|
AuthWrapper,
|
|
676
657
|
checkAuthStatus,
|
|
677
|
-
getAuthorizationHandoff,
|
|
678
658
|
getContext,
|
|
679
659
|
getInstagramAuthorizationURL,
|
|
680
660
|
getRefreshToken,
|
|
@@ -20,7 +20,6 @@ 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,
|
|
24
23
|
getInstagramAuthorizationURL: () => getInstagramAuthorizationURL,
|
|
25
24
|
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken,
|
|
26
25
|
setupInstagramAuth: () => setupInstagramAuth
|
|
@@ -28,7 +27,7 @@ __export(instagram_exports, {
|
|
|
28
27
|
module.exports = __toCommonJS(instagram_exports);
|
|
29
28
|
|
|
30
29
|
// src/auth/instagram/route.ts
|
|
31
|
-
var
|
|
30
|
+
var import_server3 = require("next/server");
|
|
32
31
|
|
|
33
32
|
// src/auth/email/token.ts
|
|
34
33
|
var import_bcryptjs = require("bcryptjs");
|
|
@@ -102,25 +101,6 @@ function getUserIdFromAccessToken(accessToken) {
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
// src/auth/instagram/utils.ts
|
|
105
|
-
var import_server2 = require("next/server");
|
|
106
|
-
function getAuthorizationHandoff(authorizationURL) {
|
|
107
|
-
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
108
|
-
/</g,
|
|
109
|
-
"\\u003c"
|
|
110
|
-
);
|
|
111
|
-
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
112
|
-
return new import_server2.NextResponse(
|
|
113
|
-
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Connecting\u2026</title><script>location.replace(${scriptSafeURL})</script><noscript><meta http-equiv="refresh" content="0;url=${attributeSafeURL}"></noscript></head><body></body></html>`,
|
|
114
|
-
{
|
|
115
|
-
headers: {
|
|
116
|
-
"content-type": "text/html; charset=utf-8",
|
|
117
|
-
"cache-control": "no-store",
|
|
118
|
-
// The token is in the URL; keep it off the provider's referer log.
|
|
119
|
-
"referrer-policy": "no-referrer"
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
104
|
async function getRefreshedInstagramAccessToken(token) {
|
|
125
105
|
const request = await fetch(
|
|
126
106
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -156,7 +136,7 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
156
136
|
}
|
|
157
137
|
}
|
|
158
138
|
}
|
|
159
|
-
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize
|
|
139
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize/?client_id=${getEnv(
|
|
160
140
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
161
141
|
)}&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 */)}`;
|
|
162
142
|
|
|
@@ -183,7 +163,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
183
163
|
};
|
|
184
164
|
|
|
185
165
|
// src/socials/meta-webhook.ts
|
|
186
|
-
var
|
|
166
|
+
var import_server2 = require("next/server");
|
|
187
167
|
|
|
188
168
|
// src/auth/instagram/route.ts
|
|
189
169
|
var getInstagramRoute = ({
|
|
@@ -191,7 +171,7 @@ var getInstagramRoute = ({
|
|
|
191
171
|
errorRedirectURL,
|
|
192
172
|
onUser
|
|
193
173
|
}) => {
|
|
194
|
-
const handleError = (message) =>
|
|
174
|
+
const handleError = (message) => import_server3.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
195
175
|
return async (req) => {
|
|
196
176
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
197
177
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -199,7 +179,7 @@ var getInstagramRoute = ({
|
|
|
199
179
|
if (error) return handleError(error);
|
|
200
180
|
if (!accessCode) {
|
|
201
181
|
if (!stateToken) return handleError("Invalid request");
|
|
202
|
-
return
|
|
182
|
+
return import_server3.NextResponse.redirect(getInstagramAuthorizationURL(stateToken), 302);
|
|
203
183
|
}
|
|
204
184
|
if (!stateToken) return handleError("Invalid request");
|
|
205
185
|
const instagramData = await getLongLivedToken(
|
|
@@ -219,7 +199,7 @@ var getInstagramRoute = ({
|
|
|
219
199
|
instagramData.accessToken
|
|
220
200
|
);
|
|
221
201
|
if (errorMessage) return handleError(errorMessage);
|
|
222
|
-
return
|
|
202
|
+
return import_server3.NextResponse.redirect(redirectURL);
|
|
223
203
|
};
|
|
224
204
|
};
|
|
225
205
|
|
|
@@ -231,7 +211,6 @@ function setupInstagramAuth(props) {
|
|
|
231
211
|
}
|
|
232
212
|
// Annotate the CommonJS export names for ESM import in node:
|
|
233
213
|
0 && (module.exports = {
|
|
234
|
-
getAuthorizationHandoff,
|
|
235
214
|
getInstagramAuthorizationURL,
|
|
236
215
|
getRefreshedInstagramAccessToken,
|
|
237
216
|
setupInstagramAuth
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
-
export {
|
|
2
|
+
export { getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './utils.mjs';
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -22,9 +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
|
-
*
|
|
27
|
-
* the Instagram app; see {@link getAuthorizationHandoff}).
|
|
25
|
+
* entry point (`?state` with no code → 302 to Instagram's authorize URL; see
|
|
26
|
+
* {@link getInstagramAuthorizationURL} for why that URL is spelled the way it is).
|
|
28
27
|
*
|
|
29
28
|
* Requires env vars: `INSTAGRAM_CLIENT_ID` (server-only), `INSTAGRAM_CLIENT_SECRET`, `NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT`.
|
|
30
29
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
-
export {
|
|
2
|
+
export { getInstagramAuthorizationURL, getRefreshedInstagramAccessToken } from './utils.js';
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -22,9 +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
|
-
*
|
|
27
|
-
* the Instagram app; see {@link getAuthorizationHandoff}).
|
|
25
|
+
* entry point (`?state` with no code → 302 to Instagram's authorize URL; see
|
|
26
|
+
* {@link getInstagramAuthorizationURL} for why that URL is spelled the way it is).
|
|
28
27
|
*
|
|
29
28
|
* Requires env vars: `INSTAGRAM_CLIENT_ID` (server-only), `INSTAGRAM_CLIENT_SECRET`, `NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT`.
|
|
30
29
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/auth/instagram/route.ts
|
|
2
|
-
import { NextResponse as
|
|
2
|
+
import { NextResponse as NextResponse3 } from "next/server";
|
|
3
3
|
|
|
4
4
|
// src/auth/email/token.ts
|
|
5
5
|
import { compare } from "bcryptjs";
|
|
@@ -73,25 +73,6 @@ function getUserIdFromAccessToken(accessToken) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// src/auth/instagram/utils.ts
|
|
76
|
-
import { NextResponse as NextResponse2 } from "next/server";
|
|
77
|
-
function getAuthorizationHandoff(authorizationURL) {
|
|
78
|
-
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
79
|
-
/</g,
|
|
80
|
-
"\\u003c"
|
|
81
|
-
);
|
|
82
|
-
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
83
|
-
return new NextResponse2(
|
|
84
|
-
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Connecting\u2026</title><script>location.replace(${scriptSafeURL})</script><noscript><meta http-equiv="refresh" content="0;url=${attributeSafeURL}"></noscript></head><body></body></html>`,
|
|
85
|
-
{
|
|
86
|
-
headers: {
|
|
87
|
-
"content-type": "text/html; charset=utf-8",
|
|
88
|
-
"cache-control": "no-store",
|
|
89
|
-
// The token is in the URL; keep it off the provider's referer log.
|
|
90
|
-
"referrer-policy": "no-referrer"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
76
|
async function getRefreshedInstagramAccessToken(token) {
|
|
96
77
|
const request = await fetch(
|
|
97
78
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -127,7 +108,7 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
127
108
|
}
|
|
128
109
|
}
|
|
129
110
|
}
|
|
130
|
-
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize
|
|
111
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize/?client_id=${getEnv(
|
|
131
112
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
132
113
|
)}&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 */)}`;
|
|
133
114
|
|
|
@@ -154,7 +135,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
154
135
|
};
|
|
155
136
|
|
|
156
137
|
// src/socials/meta-webhook.ts
|
|
157
|
-
import { NextResponse as
|
|
138
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
158
139
|
|
|
159
140
|
// src/auth/instagram/route.ts
|
|
160
141
|
var getInstagramRoute = ({
|
|
@@ -162,7 +143,7 @@ var getInstagramRoute = ({
|
|
|
162
143
|
errorRedirectURL,
|
|
163
144
|
onUser
|
|
164
145
|
}) => {
|
|
165
|
-
const handleError = (message) =>
|
|
146
|
+
const handleError = (message) => NextResponse3.redirect(`${errorRedirectURL}?error=${message}`);
|
|
166
147
|
return async (req) => {
|
|
167
148
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
168
149
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -170,7 +151,7 @@ var getInstagramRoute = ({
|
|
|
170
151
|
if (error) return handleError(error);
|
|
171
152
|
if (!accessCode) {
|
|
172
153
|
if (!stateToken) return handleError("Invalid request");
|
|
173
|
-
return
|
|
154
|
+
return NextResponse3.redirect(getInstagramAuthorizationURL(stateToken), 302);
|
|
174
155
|
}
|
|
175
156
|
if (!stateToken) return handleError("Invalid request");
|
|
176
157
|
const instagramData = await getLongLivedToken(
|
|
@@ -190,7 +171,7 @@ var getInstagramRoute = ({
|
|
|
190
171
|
instagramData.accessToken
|
|
191
172
|
);
|
|
192
173
|
if (errorMessage) return handleError(errorMessage);
|
|
193
|
-
return
|
|
174
|
+
return NextResponse3.redirect(redirectURL);
|
|
194
175
|
};
|
|
195
176
|
};
|
|
196
177
|
|
|
@@ -201,7 +182,6 @@ function setupInstagramAuth(props) {
|
|
|
201
182
|
};
|
|
202
183
|
}
|
|
203
184
|
export {
|
|
204
|
-
getAuthorizationHandoff,
|
|
205
185
|
getInstagramAuthorizationURL,
|
|
206
186
|
getRefreshedInstagramAccessToken,
|
|
207
187
|
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_server3 = require("next/server");
|
|
27
27
|
|
|
28
28
|
// src/auth/email/token.ts
|
|
29
29
|
var import_bcryptjs = require("bcryptjs");
|
|
@@ -97,25 +97,6 @@ function getUserIdFromAccessToken(accessToken) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// src/auth/instagram/utils.ts
|
|
100
|
-
var import_server2 = require("next/server");
|
|
101
|
-
function getAuthorizationHandoff(authorizationURL) {
|
|
102
|
-
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
103
|
-
/</g,
|
|
104
|
-
"\\u003c"
|
|
105
|
-
);
|
|
106
|
-
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
107
|
-
return new import_server2.NextResponse(
|
|
108
|
-
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Connecting\u2026</title><script>location.replace(${scriptSafeURL})</script><noscript><meta http-equiv="refresh" content="0;url=${attributeSafeURL}"></noscript></head><body></body></html>`,
|
|
109
|
-
{
|
|
110
|
-
headers: {
|
|
111
|
-
"content-type": "text/html; charset=utf-8",
|
|
112
|
-
"cache-control": "no-store",
|
|
113
|
-
// The token is in the URL; keep it off the provider's referer log.
|
|
114
|
-
"referrer-policy": "no-referrer"
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
100
|
async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
120
101
|
const formData = new FormData();
|
|
121
102
|
formData.set("client_id", clientId);
|
|
@@ -144,7 +125,7 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
144
125
|
}
|
|
145
126
|
}
|
|
146
127
|
}
|
|
147
|
-
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize
|
|
128
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize/?client_id=${getEnv(
|
|
148
129
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
149
130
|
)}&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 */)}`;
|
|
150
131
|
|
|
@@ -171,7 +152,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
171
152
|
};
|
|
172
153
|
|
|
173
154
|
// src/socials/meta-webhook.ts
|
|
174
|
-
var
|
|
155
|
+
var import_server2 = require("next/server");
|
|
175
156
|
|
|
176
157
|
// src/auth/instagram/route.ts
|
|
177
158
|
var getInstagramRoute = ({
|
|
@@ -179,7 +160,7 @@ var getInstagramRoute = ({
|
|
|
179
160
|
errorRedirectURL,
|
|
180
161
|
onUser
|
|
181
162
|
}) => {
|
|
182
|
-
const handleError = (message) =>
|
|
163
|
+
const handleError = (message) => import_server3.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
|
|
183
164
|
return async (req) => {
|
|
184
165
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
185
166
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -187,7 +168,7 @@ var getInstagramRoute = ({
|
|
|
187
168
|
if (error) return handleError(error);
|
|
188
169
|
if (!accessCode) {
|
|
189
170
|
if (!stateToken) return handleError("Invalid request");
|
|
190
|
-
return
|
|
171
|
+
return import_server3.NextResponse.redirect(getInstagramAuthorizationURL(stateToken), 302);
|
|
191
172
|
}
|
|
192
173
|
if (!stateToken) return handleError("Invalid request");
|
|
193
174
|
const instagramData = await getLongLivedToken(
|
|
@@ -207,7 +188,7 @@ var getInstagramRoute = ({
|
|
|
207
188
|
instagramData.accessToken
|
|
208
189
|
);
|
|
209
190
|
if (errorMessage) return handleError(errorMessage);
|
|
210
|
-
return
|
|
191
|
+
return import_server3.NextResponse.redirect(redirectURL);
|
|
211
192
|
};
|
|
212
193
|
};
|
|
213
194
|
// 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 NextResponse3 } from "next/server";
|
|
3
3
|
|
|
4
4
|
// src/auth/email/token.ts
|
|
5
5
|
import { compare } from "bcryptjs";
|
|
@@ -73,25 +73,6 @@ function getUserIdFromAccessToken(accessToken) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// src/auth/instagram/utils.ts
|
|
76
|
-
import { NextResponse as NextResponse2 } from "next/server";
|
|
77
|
-
function getAuthorizationHandoff(authorizationURL) {
|
|
78
|
-
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
79
|
-
/</g,
|
|
80
|
-
"\\u003c"
|
|
81
|
-
);
|
|
82
|
-
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
83
|
-
return new NextResponse2(
|
|
84
|
-
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Connecting\u2026</title><script>location.replace(${scriptSafeURL})</script><noscript><meta http-equiv="refresh" content="0;url=${attributeSafeURL}"></noscript></head><body></body></html>`,
|
|
85
|
-
{
|
|
86
|
-
headers: {
|
|
87
|
-
"content-type": "text/html; charset=utf-8",
|
|
88
|
-
"cache-control": "no-store",
|
|
89
|
-
// The token is in the URL; keep it off the provider's referer log.
|
|
90
|
-
"referrer-policy": "no-referrer"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
76
|
async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
96
77
|
const formData = new FormData();
|
|
97
78
|
formData.set("client_id", clientId);
|
|
@@ -120,7 +101,7 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
120
101
|
}
|
|
121
102
|
}
|
|
122
103
|
}
|
|
123
|
-
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize
|
|
104
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize/?client_id=${getEnv(
|
|
124
105
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
125
106
|
)}&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 */)}`;
|
|
126
107
|
|
|
@@ -147,7 +128,7 @@ var getInstagramUser = (token, id, fields) => {
|
|
|
147
128
|
};
|
|
148
129
|
|
|
149
130
|
// src/socials/meta-webhook.ts
|
|
150
|
-
import { NextResponse as
|
|
131
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
151
132
|
|
|
152
133
|
// src/auth/instagram/route.ts
|
|
153
134
|
var getInstagramRoute = ({
|
|
@@ -155,7 +136,7 @@ var getInstagramRoute = ({
|
|
|
155
136
|
errorRedirectURL,
|
|
156
137
|
onUser
|
|
157
138
|
}) => {
|
|
158
|
-
const handleError = (message) =>
|
|
139
|
+
const handleError = (message) => NextResponse3.redirect(`${errorRedirectURL}?error=${message}`);
|
|
159
140
|
return async (req) => {
|
|
160
141
|
const accessCode = req.nextUrl.searchParams.get("code");
|
|
161
142
|
const error = req.nextUrl.searchParams.get("error");
|
|
@@ -163,7 +144,7 @@ var getInstagramRoute = ({
|
|
|
163
144
|
if (error) return handleError(error);
|
|
164
145
|
if (!accessCode) {
|
|
165
146
|
if (!stateToken) return handleError("Invalid request");
|
|
166
|
-
return
|
|
147
|
+
return NextResponse3.redirect(getInstagramAuthorizationURL(stateToken), 302);
|
|
167
148
|
}
|
|
168
149
|
if (!stateToken) return handleError("Invalid request");
|
|
169
150
|
const instagramData = await getLongLivedToken(
|
|
@@ -183,7 +164,7 @@ var getInstagramRoute = ({
|
|
|
183
164
|
instagramData.accessToken
|
|
184
165
|
);
|
|
185
166
|
if (errorMessage) return handleError(errorMessage);
|
|
186
|
-
return
|
|
167
|
+
return NextResponse3.redirect(redirectURL);
|
|
187
168
|
};
|
|
188
169
|
};
|
|
189
170
|
export {
|
|
@@ -20,13 +20,11 @@ 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,
|
|
24
23
|
getInstagramAuthorizationURL: () => getInstagramAuthorizationURL,
|
|
25
24
|
getLongLivedToken: () => getLongLivedToken,
|
|
26
25
|
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken
|
|
27
26
|
});
|
|
28
27
|
module.exports = __toCommonJS(utils_exports);
|
|
29
|
-
var import_server = require("next/server");
|
|
30
28
|
|
|
31
29
|
// src/env.ts
|
|
32
30
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -79,24 +77,6 @@ function getEnv(key, skipCheck) {
|
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
// src/auth/instagram/utils.ts
|
|
82
|
-
function getAuthorizationHandoff(authorizationURL) {
|
|
83
|
-
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
84
|
-
/</g,
|
|
85
|
-
"\\u003c"
|
|
86
|
-
);
|
|
87
|
-
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
88
|
-
return new import_server.NextResponse(
|
|
89
|
-
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Connecting\u2026</title><script>location.replace(${scriptSafeURL})</script><noscript><meta http-equiv="refresh" content="0;url=${attributeSafeURL}"></noscript></head><body></body></html>`,
|
|
90
|
-
{
|
|
91
|
-
headers: {
|
|
92
|
-
"content-type": "text/html; charset=utf-8",
|
|
93
|
-
"cache-control": "no-store",
|
|
94
|
-
// The token is in the URL; keep it off the provider's referer log.
|
|
95
|
-
"referrer-policy": "no-referrer"
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
80
|
async function getRefreshedInstagramAccessToken(token) {
|
|
101
81
|
const request = await fetch(
|
|
102
82
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -132,12 +112,11 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
132
112
|
}
|
|
133
113
|
}
|
|
134
114
|
}
|
|
135
|
-
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize
|
|
115
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize/?client_id=${getEnv(
|
|
136
116
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
137
117
|
)}&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 */)}`;
|
|
138
118
|
// Annotate the CommonJS export names for ESM import in node:
|
|
139
119
|
0 && (module.exports = {
|
|
140
|
-
getAuthorizationHandoff,
|
|
141
120
|
getInstagramAuthorizationURL,
|
|
142
121
|
getLongLivedToken,
|
|
143
122
|
getRefreshedInstagramAccessToken
|
|
@@ -1,27 +1,3 @@
|
|
|
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.
|
|
6
|
-
*
|
|
7
|
-
* Mobile browsers match universal links (iOS) and app links (Android) against the
|
|
8
|
-
* final URL of a *user-initiated* navigation — following redirects — so both a
|
|
9
|
-
* tapped `<a href="https://www.instagram.com/…">` and a server 302 to the same
|
|
10
|
-
* place can be intercepted by the provider's native app, which has no idea what to
|
|
11
|
-
* do with an OAuth flow. A navigation issued from a freshly loaded document has no
|
|
12
|
-
* gesture token behind it and is never intercepted, so this page loads and
|
|
13
|
-
* immediately replaces itself with `authorizationURL`.
|
|
14
|
-
*
|
|
15
|
-
* `location.replace` keeps the interstitial out of session history, so Back from
|
|
16
|
-
* the provider returns to the page that started the flow. The `noscript` meta
|
|
17
|
-
* refresh is a fallback, not the primary path.
|
|
18
|
-
*
|
|
19
|
-
* @param authorizationURL - Provider authorization URL to hand the browser off to
|
|
20
|
-
* @returns HTML response that redirects client-side
|
|
21
|
-
*
|
|
22
|
-
* @category Auth
|
|
23
|
-
*/
|
|
24
|
-
declare function getAuthorizationHandoff(authorizationURL: string): NextResponse<unknown>;
|
|
25
1
|
/**
|
|
26
2
|
* Exchanges a long-lived Instagram token for a refreshed token.
|
|
27
3
|
* @param token - Current long-lived access token
|
|
@@ -57,16 +33,14 @@ declare function getLongLivedToken(code: string, redirectURL: string, clientId:
|
|
|
57
33
|
*
|
|
58
34
|
* @example
|
|
59
35
|
* ```ts
|
|
60
|
-
* // In a server route handler
|
|
61
|
-
*
|
|
62
|
-
* // universal/app link and opens the Instagram app mid-flow.
|
|
63
|
-
* import { getAuthorizationHandoff, getInstagramAuthorizationURL } from "naystack/auth";
|
|
36
|
+
* // In a server route handler:
|
|
37
|
+
* import { getInstagramAuthorizationURL } from "naystack/auth";
|
|
64
38
|
*
|
|
65
|
-
* return
|
|
39
|
+
* return NextResponse.redirect(getInstagramAuthorizationURL(state), 302);
|
|
66
40
|
* ```
|
|
67
41
|
*
|
|
68
42
|
* @category Auth
|
|
69
43
|
*/
|
|
70
44
|
declare const getInstagramAuthorizationURL: (token: string) => string;
|
|
71
45
|
|
|
72
|
-
export {
|
|
46
|
+
export { getInstagramAuthorizationURL, getLongLivedToken, getRefreshedInstagramAccessToken };
|
|
@@ -1,27 +1,3 @@
|
|
|
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.
|
|
6
|
-
*
|
|
7
|
-
* Mobile browsers match universal links (iOS) and app links (Android) against the
|
|
8
|
-
* final URL of a *user-initiated* navigation — following redirects — so both a
|
|
9
|
-
* tapped `<a href="https://www.instagram.com/…">` and a server 302 to the same
|
|
10
|
-
* place can be intercepted by the provider's native app, which has no idea what to
|
|
11
|
-
* do with an OAuth flow. A navigation issued from a freshly loaded document has no
|
|
12
|
-
* gesture token behind it and is never intercepted, so this page loads and
|
|
13
|
-
* immediately replaces itself with `authorizationURL`.
|
|
14
|
-
*
|
|
15
|
-
* `location.replace` keeps the interstitial out of session history, so Back from
|
|
16
|
-
* the provider returns to the page that started the flow. The `noscript` meta
|
|
17
|
-
* refresh is a fallback, not the primary path.
|
|
18
|
-
*
|
|
19
|
-
* @param authorizationURL - Provider authorization URL to hand the browser off to
|
|
20
|
-
* @returns HTML response that redirects client-side
|
|
21
|
-
*
|
|
22
|
-
* @category Auth
|
|
23
|
-
*/
|
|
24
|
-
declare function getAuthorizationHandoff(authorizationURL: string): NextResponse<unknown>;
|
|
25
1
|
/**
|
|
26
2
|
* Exchanges a long-lived Instagram token for a refreshed token.
|
|
27
3
|
* @param token - Current long-lived access token
|
|
@@ -57,16 +33,14 @@ declare function getLongLivedToken(code: string, redirectURL: string, clientId:
|
|
|
57
33
|
*
|
|
58
34
|
* @example
|
|
59
35
|
* ```ts
|
|
60
|
-
* // In a server route handler
|
|
61
|
-
*
|
|
62
|
-
* // universal/app link and opens the Instagram app mid-flow.
|
|
63
|
-
* import { getAuthorizationHandoff, getInstagramAuthorizationURL } from "naystack/auth";
|
|
36
|
+
* // In a server route handler:
|
|
37
|
+
* import { getInstagramAuthorizationURL } from "naystack/auth";
|
|
64
38
|
*
|
|
65
|
-
* return
|
|
39
|
+
* return NextResponse.redirect(getInstagramAuthorizationURL(state), 302);
|
|
66
40
|
* ```
|
|
67
41
|
*
|
|
68
42
|
* @category Auth
|
|
69
43
|
*/
|
|
70
44
|
declare const getInstagramAuthorizationURL: (token: string) => string;
|
|
71
45
|
|
|
72
|
-
export {
|
|
46
|
+
export { getInstagramAuthorizationURL, getLongLivedToken, getRefreshedInstagramAccessToken };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// src/auth/instagram/utils.ts
|
|
2
|
-
import { NextResponse } from "next/server";
|
|
3
|
-
|
|
4
1
|
// src/env.ts
|
|
5
2
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
6
3
|
var getEnvValue = (key) => {
|
|
@@ -52,24 +49,6 @@ function getEnv(key, skipCheck) {
|
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
// src/auth/instagram/utils.ts
|
|
55
|
-
function getAuthorizationHandoff(authorizationURL) {
|
|
56
|
-
const scriptSafeURL = JSON.stringify(authorizationURL).replace(
|
|
57
|
-
/</g,
|
|
58
|
-
"\\u003c"
|
|
59
|
-
);
|
|
60
|
-
const attributeSafeURL = authorizationURL.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
61
|
-
return new NextResponse(
|
|
62
|
-
`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Connecting\u2026</title><script>location.replace(${scriptSafeURL})</script><noscript><meta http-equiv="refresh" content="0;url=${attributeSafeURL}"></noscript></head><body></body></html>`,
|
|
63
|
-
{
|
|
64
|
-
headers: {
|
|
65
|
-
"content-type": "text/html; charset=utf-8",
|
|
66
|
-
"cache-control": "no-store",
|
|
67
|
-
// The token is in the URL; keep it off the provider's referer log.
|
|
68
|
-
"referrer-policy": "no-referrer"
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
52
|
async function getRefreshedInstagramAccessToken(token) {
|
|
74
53
|
const request = await fetch(
|
|
75
54
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
@@ -105,11 +84,10 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
105
84
|
}
|
|
106
85
|
}
|
|
107
86
|
}
|
|
108
|
-
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize
|
|
87
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize/?client_id=${getEnv(
|
|
109
88
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
110
89
|
)}&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 */)}`;
|
|
111
90
|
export {
|
|
112
|
-
getAuthorizationHandoff,
|
|
113
91
|
getInstagramAuthorizationURL,
|
|
114
92
|
getLongLivedToken,
|
|
115
93
|
getRefreshedInstagramAccessToken
|