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