From f2d0c348aa785f41212decd32b4d77ea63ebaacd Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Fri, 24 Nov 2023 17:50:30 +0200 Subject: [PATCH 1/2] Remove `` and `bump.yml` (#80) --- .github/workflows/bump.yml | 98 -------------------------------------- Directory.Build.props | 4 -- 2 files changed, 102 deletions(-) delete mode 100644 .github/workflows/bump.yml diff --git a/.github/workflows/bump.yml b/.github/workflows/bump.yml deleted file mode 100644 index 5ada5c9..0000000 --- a/.github/workflows/bump.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: bump - -on: - workflow_dispatch: - inputs: - version: - type: string - required: true - description: Version to bump to - -env: - BUMP_BRANCH_NAME: bump-${{ inputs.version }}-${{ github.run_id }} - -jobs: - # Ensure that the provided version is greater than the current version - validate: - runs-on: ubuntu-latest - permissions: - contents: read - - steps: - - name: Checkout - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Get current version - id: current-version - run: | - props=$(cat Directory.Build.props) - version=$(echo "$props" | grep -oPm1 "(?<=)[^<]*") - echo "version=$version" >> $GITHUB_OUTPUT - - - name: Validate new version (format) - # Use regex to make sure the version is 1.2.3 or 1.2.3-ci-abcdef0 - run: | - if ! [[ "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z].*)?$ ]]; then - echo "Invalid version: ${{ inputs.version }}" - exit 1 - fi - - - name: Validate new version (increment) - run: > - npx semver@7.5.4 "${{ inputs.version }}" - --range "> ${{ steps.current-version.outputs.version }}" - --include-prerelease - - # Update version and commit - update: - needs: validate - runs-on: ubuntu-latest - permissions: - contents: write - - steps: - - name: Checkout - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Configure credentials - run: | - git config --local user.email "106330231+passwordless-bot@users.noreply.github.com" - git config --local user.name "passwordless-bot" - - - name: Create branch - run: git checkout -b $BUMP_BRANCH_NAME - - - name: Rewrite version - run: sed -i "s/[^<]*/${{ inputs.version }}/" Directory.Build.props - - - name: Commit changes - run: | - git add Directory.Build.props - git commit -m "Bump version to ${{ inputs.version }}" - - - name: Push changes - run: git push origin $BUMP_BRANCH_NAME - - # Create a pull request - pr: - needs: - - validate - - update - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - - steps: - - name: Checkout - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Create pull request - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: > - gh pr create - --base main - --head $BUMP_BRANCH_NAME - --title "Bump version to ${{ inputs.version }}" - --body "This is an automated pull request that bumps the version to ${{ inputs.version }}." \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 9b3a70f..f93f983 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,9 +1,5 @@ - - 2.0.0-beta4 - - latest enable From c9303c596c1f2b5d646104a49c8ac95689f2f2f5 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Fri, 24 Nov 2023 17:55:05 +0200 Subject: [PATCH 2/2] Add a more convenient overload of `AddPasswordlessSdk` (#81) --- README.md | 2 +- .../Program.cs | 3 ++- examples/Passwordless.Example/Startup.cs | 15 ++++++--------- .../IdentityBuilderExtensions.cs | 2 +- src/Passwordless/Passwordless.csproj | 1 + .../ServiceCollectionExtensions.cs | 18 ++++++++++++++++++ 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 247fc4b..6114b71 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ Add Passwordless to your service container: // In Program.cs or Startup.cs services.AddPasswordlessSdk(options => { - options.ApiKey = "your_api_key"; options.ApiSecret = "your_api_secret"; + options.ApiKey = "your_api_key"; }); ``` diff --git a/examples/Passwordless.AspNetIdentity.Example/Program.cs b/examples/Passwordless.AspNetIdentity.Example/Program.cs index 2b58d59..1abee73 100644 --- a/examples/Passwordless.AspNetIdentity.Example/Program.cs +++ b/examples/Passwordless.AspNetIdentity.Example/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Passwordless.AspNetCore; @@ -12,7 +13,7 @@ builder.Services.AddDataContext(); builder.Services.AddIdentity() .AddEntityFrameworkStores() - .AddPasswordless(builder.Configuration.GetSection("Passwordless")); + .AddPasswordless(builder.Configuration.GetRequiredSection("Passwordless")); builder.Services.AddRazorPages(options => { diff --git a/examples/Passwordless.Example/Startup.cs b/examples/Passwordless.Example/Startup.cs index fbcc369..71c6841 100644 --- a/examples/Passwordless.Example/Startup.cs +++ b/examples/Passwordless.Example/Startup.cs @@ -19,27 +19,24 @@ public Startup(IConfiguration configuration) // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - // add support for routing to controllers + // Add support for routing to controllers services.AddControllers(); // Inject the Passwordless SDK - services.AddPasswordlessSdk(options => - { - Configuration.GetRequiredSection("Passwordless").Bind(options); - }); + services.AddPasswordlessSdk(Configuration.GetRequiredSection("Passwordless")); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); + if (env.IsDevelopment()) + app.UseDeveloperExceptionPage(); - // add support for serving index.html + // Add support for serving index.html app.UseDefaultFiles(); app.UseStaticFiles(); app.UseRouting(); - - app.UseEndpoints(endpoints => { endpoints.MapDefaultControllerRoute(); }); + app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute()); } } \ No newline at end of file diff --git a/src/Passwordless.AspNetCore/IdentityBuilderExtensions.cs b/src/Passwordless.AspNetCore/IdentityBuilderExtensions.cs index 55144ee..71adc1f 100644 --- a/src/Passwordless.AspNetCore/IdentityBuilderExtensions.cs +++ b/src/Passwordless.AspNetCore/IdentityBuilderExtensions.cs @@ -96,8 +96,8 @@ private static IServiceCollection AddPasswordlessCore(this IServiceCollection se .Configure>((options, aspNetCoreOptionsAccessor) => { var aspNetCoreOptions = aspNetCoreOptionsAccessor.Value; - options.ApiSecret = aspNetCoreOptions.ApiSecret; options.ApiUrl = aspNetCoreOptions.ApiUrl; + options.ApiSecret = aspNetCoreOptions.ApiSecret; options.ApiKey = aspNetCoreOptions.ApiKey; }); diff --git a/src/Passwordless/Passwordless.csproj b/src/Passwordless/Passwordless.csproj index d58819d..23f96a5 100644 --- a/src/Passwordless/Passwordless.csproj +++ b/src/Passwordless/Passwordless.csproj @@ -22,6 +22,7 @@ + diff --git a/src/Passwordless/ServiceCollectionExtensions.cs b/src/Passwordless/ServiceCollectionExtensions.cs index e8a49c7..b384b2c 100644 --- a/src/Passwordless/ServiceCollectionExtensions.cs +++ b/src/Passwordless/ServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; using Passwordless; @@ -33,4 +34,21 @@ public static IServiceCollection AddPasswordlessSdk( return services; } + + /// + /// Adds and configures Passwordless-related services. + /// + public static IServiceCollection AddPasswordlessSdk( + this IServiceCollection services, + IConfiguration configuration) => + services.AddPasswordlessSdk(o => + { + o.ApiUrl = configuration["ApiUrl"] ?? PasswordlessOptions.CloudApiUrl; + + o.ApiSecret = + configuration["ApiSecret"] ?? + throw new InvalidOperationException("Missing 'ApiSecret' configuration value."); + + o.ApiKey = configuration["ApiKey"]; + }); } \ No newline at end of file