oauth-init 0.13.0 → 0.15.0
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/index.js +102 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1848,7 +1848,7 @@ ${l}
|
|
|
1848
1848
|
} }).prompt();
|
|
1849
1849
|
|
|
1850
1850
|
// src/index.ts
|
|
1851
|
-
import
|
|
1851
|
+
import path7 from "path";
|
|
1852
1852
|
import fs6 from "fs";
|
|
1853
1853
|
|
|
1854
1854
|
// node_modules/is-plain-obj/index.js
|
|
@@ -9371,8 +9371,6 @@ Opening: ${brandUrl}`);
|
|
|
9371
9371
|
}
|
|
9372
9372
|
|
|
9373
9373
|
// src/lib/github-provider.ts
|
|
9374
|
-
import { writeFile as writeFile2, unlink } from "fs/promises";
|
|
9375
|
-
import path7 from "path";
|
|
9376
9374
|
import http from "http";
|
|
9377
9375
|
function logStep2(message) {
|
|
9378
9376
|
if (!globalConfig.quiet)
|
|
@@ -9417,7 +9415,6 @@ class GitHubAuthProvider {
|
|
|
9417
9415
|
return Ne("Setup aborted.");
|
|
9418
9416
|
const PORT = 3004;
|
|
9419
9417
|
const REDIRECT_URI = `http://localhost:${PORT}/callback`;
|
|
9420
|
-
const tempPath = path7.join(process.cwd(), "github-setup.html");
|
|
9421
9418
|
const manifest = {
|
|
9422
9419
|
name: "oauth-init-app",
|
|
9423
9420
|
url: "http://localhost:3000",
|
|
@@ -9439,48 +9436,43 @@ class GitHubAuthProvider {
|
|
|
9439
9436
|
</body>
|
|
9440
9437
|
</html>
|
|
9441
9438
|
`;
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
resolve();
|
|
9469
|
-
} catch {
|
|
9470
|
-
s.error("Failed to convert manifest code.");
|
|
9471
|
-
server.close();
|
|
9472
|
-
resolve();
|
|
9473
|
-
}
|
|
9439
|
+
logStep2("GitHub App Configuration");
|
|
9440
|
+
logMessage2("Opening GitHub with your manifest...");
|
|
9441
|
+
return new Promise((resolve) => {
|
|
9442
|
+
const server = http.createServer(async (req, res) => {
|
|
9443
|
+
const url = new URL(req.url, `http://localhost:${PORT}`);
|
|
9444
|
+
const code = url.searchParams.get("code");
|
|
9445
|
+
if (code) {
|
|
9446
|
+
res.end("<h1>Success!</h1><p>You can close this tab and return to the CLI.</p>");
|
|
9447
|
+
const s = bt2();
|
|
9448
|
+
s.start("Exchanging code for secrets...");
|
|
9449
|
+
try {
|
|
9450
|
+
const { stdout } = await execa("curl", [
|
|
9451
|
+
"-X",
|
|
9452
|
+
"POST",
|
|
9453
|
+
`https://api.github.com/app-manifests/${code}/conversions`
|
|
9454
|
+
]);
|
|
9455
|
+
const credentials = JSON.parse(stdout);
|
|
9456
|
+
const { client_id, client_secret } = credentials;
|
|
9457
|
+
s.stop("Credentials received!");
|
|
9458
|
+
await saveCredentials(client_id, client_secret, "github", saveOption);
|
|
9459
|
+
server.close();
|
|
9460
|
+
resolve();
|
|
9461
|
+
} catch {
|
|
9462
|
+
s.error("Failed to convert manifest code.");
|
|
9463
|
+
server.close();
|
|
9464
|
+
resolve();
|
|
9474
9465
|
}
|
|
9475
|
-
}
|
|
9466
|
+
} else {
|
|
9467
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
9468
|
+
res.end(htmlContent);
|
|
9469
|
+
}
|
|
9470
|
+
}).listen(PORT, async () => {
|
|
9471
|
+
if (!globalConfig.noOpen) {
|
|
9472
|
+
await open_default(REDIRECT_URI);
|
|
9473
|
+
}
|
|
9476
9474
|
});
|
|
9477
|
-
}
|
|
9478
|
-
R2.error(`Setup failed: ${err.message}`);
|
|
9479
|
-
} finally {
|
|
9480
|
-
try {
|
|
9481
|
-
await unlink(tempPath);
|
|
9482
|
-
} catch {}
|
|
9483
|
-
}
|
|
9475
|
+
});
|
|
9484
9476
|
}
|
|
9485
9477
|
async setupOAuthApp(callbackUrl) {
|
|
9486
9478
|
logStep2("Step 1: Create OAuth App on GitHub");
|
|
@@ -9516,6 +9508,55 @@ class GitHubAuthProvider {
|
|
|
9516
9508
|
}
|
|
9517
9509
|
}
|
|
9518
9510
|
|
|
9511
|
+
// src/lib/discord-provider.ts
|
|
9512
|
+
function logStep3(message) {
|
|
9513
|
+
if (!globalConfig.quiet)
|
|
9514
|
+
R2.step(message);
|
|
9515
|
+
}
|
|
9516
|
+
function logMessage3(message) {
|
|
9517
|
+
if (!globalConfig.quiet)
|
|
9518
|
+
R2.message(message);
|
|
9519
|
+
}
|
|
9520
|
+
|
|
9521
|
+
class DiscordAuthProvider {
|
|
9522
|
+
async run(callbackUrl) {
|
|
9523
|
+
try {
|
|
9524
|
+
logStep3("Step 1: Create Discord Application");
|
|
9525
|
+
const portalUrl = "https://discord.com/developers/applications?new_app=true";
|
|
9526
|
+
logMessage3(`Opening Discord Developer Portal: ${portalUrl}`);
|
|
9527
|
+
if (!globalConfig.noOpen) {
|
|
9528
|
+
await open_default(portalUrl);
|
|
9529
|
+
}
|
|
9530
|
+
Ve(`1. Click 'New Application' and give it a name.
|
|
9531
|
+
` + `2. Go to 'OAuth2' -> 'General' in the sidebar.
|
|
9532
|
+
` + "3. Click 'Add Redirect' and paste: " + callbackUrl + `
|
|
9533
|
+
4. Click 'Reset Secret' if you don't have a Client Secret`, "Action Required");
|
|
9534
|
+
logStep3("Step 2: Collect Credentials");
|
|
9535
|
+
const clientId = await Ze({
|
|
9536
|
+
message: "Enter your Discord Client ID:",
|
|
9537
|
+
placeholder: "123456789012345678",
|
|
9538
|
+
validate: (value) => !value || !/^\d{17,19}$/.test(value) ? "Invalid Discord ID" : undefined
|
|
9539
|
+
});
|
|
9540
|
+
if (Ct(clientId))
|
|
9541
|
+
return Ne("Setup aborted.");
|
|
9542
|
+
const clientSecret = await He({
|
|
9543
|
+
message: "Enter your Discord Client Secret:",
|
|
9544
|
+
validate: (value) => !value || value.length < 10 ? "Secret too short" : undefined
|
|
9545
|
+
});
|
|
9546
|
+
if (Ct(clientSecret))
|
|
9547
|
+
return Ne("Setup aborted.");
|
|
9548
|
+
logStep3("Step 3: Save credentials");
|
|
9549
|
+
const saveOption = await askSaveOption();
|
|
9550
|
+
if (Ct(saveOption))
|
|
9551
|
+
return Ne("Setup aborted.");
|
|
9552
|
+
await saveCredentials(clientId, clientSecret, "discord", saveOption);
|
|
9553
|
+
} catch (err) {
|
|
9554
|
+
R2.error(`Setup Failed: ${err.message}`);
|
|
9555
|
+
process.exit(1);
|
|
9556
|
+
}
|
|
9557
|
+
}
|
|
9558
|
+
}
|
|
9559
|
+
|
|
9519
9560
|
// src/index.ts
|
|
9520
9561
|
var AUTH_LIBRARIES = [
|
|
9521
9562
|
{ name: "next-auth", callbackPattern: "/api/auth/callback/[provider]" },
|
|
@@ -9526,7 +9567,7 @@ var AUTH_LIBRARIES = [
|
|
|
9526
9567
|
{ name: "iron-session", callbackPattern: "/api/auth/callback" }
|
|
9527
9568
|
];
|
|
9528
9569
|
function detectAuthLibrary() {
|
|
9529
|
-
const packageJsonPath =
|
|
9570
|
+
const packageJsonPath = path7.join(process.cwd(), "package.json");
|
|
9530
9571
|
if (!fs6.existsSync(packageJsonPath)) {
|
|
9531
9572
|
return null;
|
|
9532
9573
|
}
|
|
@@ -9590,6 +9631,19 @@ async function setupOAuthServices(oauthServices) {
|
|
|
9590
9631
|
}
|
|
9591
9632
|
const githubProvider = new GitHubAuthProvider;
|
|
9592
9633
|
await githubProvider.run(githubOauthCallback);
|
|
9634
|
+
} else if (service === "discord") {
|
|
9635
|
+
R2.step("Discord OAuth Setup");
|
|
9636
|
+
const discordOauthCallback = await Ze({
|
|
9637
|
+
message: "Enter the Discord OAuth callback URL:",
|
|
9638
|
+
placeholder: defaultCallback,
|
|
9639
|
+
defaultValue: defaultCallback
|
|
9640
|
+
});
|
|
9641
|
+
if (Ct(discordOauthCallback)) {
|
|
9642
|
+
Ne("Setup aborted.");
|
|
9643
|
+
return;
|
|
9644
|
+
}
|
|
9645
|
+
const discordProvider = new DiscordAuthProvider;
|
|
9646
|
+
await discordProvider.run(discordOauthCallback);
|
|
9593
9647
|
}
|
|
9594
9648
|
}
|
|
9595
9649
|
Le("OAuth setup completed! Thank you for using oauth-init!");
|
|
@@ -9619,7 +9673,7 @@ Examples:
|
|
|
9619
9673
|
}
|
|
9620
9674
|
globalConfig.quiet = flags.quiet;
|
|
9621
9675
|
globalConfig.noOpen = flags.noOpen;
|
|
9622
|
-
const projectDirectoryName =
|
|
9676
|
+
const projectDirectoryName = path7.basename(process.cwd());
|
|
9623
9677
|
We(`
|
|
9624
9678
|
▗▄▖ ▗▄▖ ▗▖ ▗▖▗▄▄▄▖▗▖ ▗▖ ▗▄▄▄▖▗▖ ▗▖▗▄▄▄▖▗▄▄▄▖
|
|
9625
9679
|
▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌ █ ▐▌ ▐▌ █ ▐▛▚▖▐▌ █ █
|
|
@@ -9638,7 +9692,8 @@ Examples:
|
|
|
9638
9692
|
message: "Select OAuth services to setup:",
|
|
9639
9693
|
options: [
|
|
9640
9694
|
{ value: "google", label: "Google" },
|
|
9641
|
-
{ value: "github", label: "Github" }
|
|
9695
|
+
{ value: "github", label: "Github" },
|
|
9696
|
+
{ value: "discord", label: "Discord" }
|
|
9642
9697
|
]
|
|
9643
9698
|
});
|
|
9644
9699
|
if (Ct(oauthToSetup)) {
|