oauth-init 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +213 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10374,6 +10374,197 @@ ${_appName}`, "Save this URL");
10374
10374
  }
10375
10375
  }
10376
10376
 
10377
+ // src/lib/providers/microsoft.ts
10378
+ init_dist2();
10379
+ function logStep6(message) {
10380
+ if (!globalConfig.quiet)
10381
+ R2.step(message);
10382
+ }
10383
+ function logInfo3(message) {
10384
+ if (!globalConfig.quiet)
10385
+ R2.info(message);
10386
+ }
10387
+ function logMessage6(message) {
10388
+ if (!globalConfig.quiet)
10389
+ R2.message(message);
10390
+ }
10391
+ var CREATE_NEW_MICROSOFT_APP_OPTION = "register_new_microsoft_app";
10392
+ async function loadMicrosoftApplications(startMessage = "Fetching azure applications") {
10393
+ const loading = bt2();
10394
+ loading.start(startMessage);
10395
+ const { stdout } = await execa("az", [
10396
+ "ad",
10397
+ "app",
10398
+ "list",
10399
+ "--query",
10400
+ "[].{name:displayName, appId:appId}",
10401
+ "-o",
10402
+ "json"
10403
+ ]);
10404
+ loading.stop("Fetched Applications");
10405
+ return JSON.parse(stdout);
10406
+ }
10407
+ async function checkAzureAuth() {
10408
+ const s = bt2();
10409
+ s.start("Checking azure CLI...");
10410
+ try {
10411
+ await execa("az", ["version"]);
10412
+ } catch {
10413
+ s.stop("azure CLI not found.");
10414
+ R2.error(`azure CLI is required for Microsoft OAuth setup.
10415
+ ` + `Install it: https://learn.microsoft.com/en-us/cli/azure/get-started-with-azure-cli?view=azure-cli-latest
10416
+ ` + "Then run: az login");
10417
+ return false;
10418
+ }
10419
+ s.stop("azure CLI found.");
10420
+ const authSpinner = bt2();
10421
+ authSpinner.start("Checking azure authentication and subscriptions...");
10422
+ try {
10423
+ const { stdout } = await execa("az", [
10424
+ "account",
10425
+ "list",
10426
+ "--query= [].{name:name,state:state,isDefault:isDefault}",
10427
+ "-o",
10428
+ "table"
10429
+ ]);
10430
+ if (!stdout.trim()) {
10431
+ authSpinner.stop("Not authenticated.");
10432
+ R2.error("Please run: az login");
10433
+ return false;
10434
+ }
10435
+ authSpinner.stop(`Authenticated as: ${stdout.trim()}`);
10436
+ return true;
10437
+ } catch {
10438
+ authSpinner.stop("Authentication check failed.");
10439
+ return false;
10440
+ }
10441
+ }
10442
+
10443
+ class MicrosoftAuthProvider {
10444
+ async run(_appName) {
10445
+ try {
10446
+ const isAuthenticated = await checkAzureAuth();
10447
+ if (!isAuthenticated) {
10448
+ R2.error("Please install azure CLI and authenticate before continuing.");
10449
+ process.exit(1);
10450
+ }
10451
+ let appsList = await loadMicrosoftApplications();
10452
+ if (!appsList || appsList.length === 0) {
10453
+ R2.error("No Azure applications found. Create one at https://entra.microsoft.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade");
10454
+ process.exit(1);
10455
+ }
10456
+ logStep6("Step 1: Select from existing applications or register a new application in Microsoft Entra Admin Center");
10457
+ const brandUrl = `https://entra.microsoft.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade`;
10458
+ let selectedAppId;
10459
+ while (!selectedAppId) {
10460
+ const options = [
10461
+ {
10462
+ label: "Register a new Microsoft Entra application",
10463
+ value: CREATE_NEW_MICROSOFT_APP_OPTION
10464
+ },
10465
+ ...appsList.map((app) => ({
10466
+ label: app.appId ? `${app.name} (Default)` : app.name,
10467
+ value: app.appId
10468
+ }))
10469
+ ];
10470
+ const selection = await Je({
10471
+ message: "Select your application",
10472
+ options
10473
+ });
10474
+ if (Ct(selection))
10475
+ return Ne("Setup aborted.");
10476
+ if (selection === CREATE_NEW_MICROSOFT_APP_OPTION) {
10477
+ logMessage6(`Microsoft Entra requires manual setup for personal projects.
10478
+ Opening: ${brandUrl}`);
10479
+ Ve(`Required Redirect URI:
10480
+ ${_appName}`, "Save this URL");
10481
+ if (!globalConfig.noOpen) {
10482
+ const shouldOpen = globalConfig.skipPrompts ? true : await Re({
10483
+ message: "Open Microsoft Entra Admin Center?",
10484
+ initialValue: true
10485
+ });
10486
+ if (Ct(shouldOpen))
10487
+ return Ne("Setup aborted.");
10488
+ if (shouldOpen)
10489
+ await open_default(brandUrl);
10490
+ }
10491
+ if (!globalConfig.skipPrompts) {
10492
+ Ve(`1. Click on New Registration
10493
+ 2. Fill App Name & Redirect URI
10494
+ 3. Click Register`, "Action Required");
10495
+ const brandDone = await Ze({
10496
+ message: "Press Enter once you've saved the Consent Screen (or type 'skip' if done previously)"
10497
+ });
10498
+ if (Ct(brandDone))
10499
+ return Ne("Setup aborted.");
10500
+ }
10501
+ appsList = await loadMicrosoftApplications("Refreshing azure applications");
10502
+ if (!appsList || appsList.length === 0) {
10503
+ R2.error("No Azure applications found. Create one at https://entra.microsoft.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade");
10504
+ process.exit(1);
10505
+ }
10506
+ continue;
10507
+ }
10508
+ if (typeof selection !== "string") {
10509
+ continue;
10510
+ }
10511
+ selectedAppId = selection;
10512
+ }
10513
+ if (!selectedAppId) {
10514
+ R2.error("No application selected.");
10515
+ process.exit(1);
10516
+ }
10517
+ const appId = selectedAppId;
10518
+ logInfo3(`Registered Apps: ${appId}`);
10519
+ logStep6("Step 2: Copy OAuth Application(client) ID");
10520
+ const clientUrl = `https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/~/Overview/appId/${appId}/`;
10521
+ logMessage6(`Opening: ${clientUrl}`);
10522
+ Ve(`Required Redirect URI:
10523
+ ${_appName}`, "Save this URL");
10524
+ if (!globalConfig.noOpen) {
10525
+ const shouldOpen = globalConfig.skipPrompts ? true : await Re({
10526
+ message: "Check overview of your registered application?",
10527
+ initialValue: true
10528
+ });
10529
+ if (Ct(shouldOpen))
10530
+ return Ne("Setup aborted.");
10531
+ if (shouldOpen)
10532
+ await open_default(clientUrl);
10533
+ }
10534
+ if (!globalConfig.skipPrompts) {
10535
+ Ve(`1. Copy Application (Client) ID from overview
10536
+ 2. Create a new client secret, Under Manage
10537
+ 3. Select 'Certificates & Secrets' -> 'New client secret' -> Copy the value (save the secret when created as it won't be shown again)`, "Action Required");
10538
+ }
10539
+ let clientId;
10540
+ let clientSecret;
10541
+ if (globalConfig.skipPrompts) {
10542
+ R2.error("Client ID and Secret required in non-interactive mode. Run without --skip-prompts");
10543
+ process.exit(1);
10544
+ }
10545
+ clientId = await Ze({
10546
+ message: "Paste your Client ID:",
10547
+ placeholder: "2893e9ee-8956-4825-9923-84b21943bb24"
10548
+ });
10549
+ if (Ct(clientId))
10550
+ return Ne("Setup aborted.");
10551
+ clientSecret = await He({
10552
+ message: "Paste your Client Secret:"
10553
+ });
10554
+ if (Ct(clientSecret))
10555
+ return Ne("Setup aborted.");
10556
+ logStep6("Step 3: Save credentials");
10557
+ const saveOption = await askSaveOption();
10558
+ if (Ct(saveOption))
10559
+ return Ne("Setup aborted.");
10560
+ await saveCredentials(clientId, clientSecret, "microsoft", saveOption);
10561
+ } catch (err) {
10562
+ R2.error(`Setup Failed: ${err.message}`);
10563
+ process.exit(1);
10564
+ }
10565
+ }
10566
+ }
10567
+
10377
10568
  // src/index.ts
10378
10569
  var AUTH_LIBRARIES = [
10379
10570
  { name: "next-auth", callbackPattern: "/api/auth/callback/[provider]" },
@@ -10441,7 +10632,13 @@ Vercel OAuth Setup:
10441
10632
  3. Configure Authorization Callback URL: http://localhost:3000/api/auth/callback/vercel
10442
10633
  4. Generate a Client Secret in your app settings
10443
10634
  5. Get the Client ID from your app settings
10444
- 6. For better-auth: https://www.better-auth.com/docs/plugins/oauth#vercel`
10635
+ 6. For better-auth: https://www.better-auth.com/docs/plugins/oauth#vercel`,
10636
+ microsoft: `
10637
+ Microsoft OAuth Setup:
10638
+ 1. Requires a registerd account on Microsoft Entra admin center for app registration
10639
+ 2. Redirect URI: http://localhost:3000/api/auth/callback/microsoft
10640
+ 3. Need: Client ID and Client Secret from the application's Overview Page
10641
+ 4. Setup involves creating an app registration, configuring API permissions and creating a client secret. For detailed steps, refer to the Microsoft provider documentation.`
10445
10642
  };
10446
10643
  function showProviderHelp(provider) {
10447
10644
  const help = PROVIDER_HELP[provider.toLowerCase()];
@@ -10530,6 +10727,19 @@ async function setupOAuthServices(oauthServices, customCallbackUrl) {
10530
10727
  }
10531
10728
  const vercelProvider = new VercelAuthProvider;
10532
10729
  await vercelProvider.run(vercelOauthCallback);
10730
+ } else if (service === "microsoft") {
10731
+ R2.step("Microsoft OAuth Setup");
10732
+ const microsoftOauthCallback = globalConfig.skipPrompts ? defaultCallback : await Ze({
10733
+ message: "Enter the Microsoft OAuth callback URL:",
10734
+ placeholder: defaultCallback,
10735
+ defaultValue: defaultCallback
10736
+ });
10737
+ if (Ct(microsoftOauthCallback)) {
10738
+ Ne("Setup aborted.");
10739
+ return;
10740
+ }
10741
+ const microsoftProvider = new MicrosoftAuthProvider;
10742
+ await microsoftProvider.run(microsoftOauthCallback);
10533
10743
  }
10534
10744
  }
10535
10745
  Le("OAuth setup completed! Thank you for using oauth-init!");
@@ -10572,7 +10782,7 @@ Examples:
10572
10782
  process.exit(0);
10573
10783
  }
10574
10784
  if (flags.provider) {
10575
- const validProviders = ["google", "github", "discord", "gitlab", "vercel"];
10785
+ const validProviders = ["google", "github", "discord", "gitlab", "vercel", "microsoft"];
10576
10786
  const providers = flags.provider.split(",").map((p) => p.trim().toLowerCase());
10577
10787
  const invalid = providers.filter((p) => !validProviders.includes(p));
10578
10788
  if (invalid.length > 0) {
@@ -10617,7 +10827,7 @@ Examples:
10617
10827
  { value: "discord", label: "Discord" },
10618
10828
  { value: "gitlab", label: "GitLab" },
10619
10829
  { value: "vercel", label: "Vercel" },
10620
- { value: "microsoft", label: "Microsoft", disabled: true, hint: "Coming soon" }
10830
+ { value: "microsoft", label: "Microsoft" }
10621
10831
  ]
10622
10832
  });
10623
10833
  if (Ct(oauthToSetup)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauth-init",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "CLI for setting up OAuth providers for your project",
5
5
  "license": "MIT",
6
6
  "type": "module",