oauth-init 0.14.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 +64 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9508,6 +9508,55 @@ class GitHubAuthProvider {
|
|
|
9508
9508
|
}
|
|
9509
9509
|
}
|
|
9510
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
|
+
|
|
9511
9560
|
// src/index.ts
|
|
9512
9561
|
var AUTH_LIBRARIES = [
|
|
9513
9562
|
{ name: "next-auth", callbackPattern: "/api/auth/callback/[provider]" },
|
|
@@ -9582,6 +9631,19 @@ async function setupOAuthServices(oauthServices) {
|
|
|
9582
9631
|
}
|
|
9583
9632
|
const githubProvider = new GitHubAuthProvider;
|
|
9584
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);
|
|
9585
9647
|
}
|
|
9586
9648
|
}
|
|
9587
9649
|
Le("OAuth setup completed! Thank you for using oauth-init!");
|
|
@@ -9630,7 +9692,8 @@ Examples:
|
|
|
9630
9692
|
message: "Select OAuth services to setup:",
|
|
9631
9693
|
options: [
|
|
9632
9694
|
{ value: "google", label: "Google" },
|
|
9633
|
-
{ value: "github", label: "Github" }
|
|
9695
|
+
{ value: "github", label: "Github" },
|
|
9696
|
+
{ value: "discord", label: "Discord" }
|
|
9634
9697
|
]
|
|
9635
9698
|
});
|
|
9636
9699
|
if (Ct(oauthToSetup)) {
|