Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a more convenient overload of AddPasswordlessSdk #81

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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";
});
```

Expand Down
3 changes: 2 additions & 1 deletion examples/Passwordless.AspNetIdentity.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +13,7 @@
builder.Services.AddDataContext();
builder.Services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<PasswordlessContext>()
.AddPasswordless(builder.Configuration.GetSection("Passwordless"));
.AddPasswordless(builder.Configuration.GetRequiredSection("Passwordless"));

builder.Services.AddRazorPages(options =>
{
Expand Down
15 changes: 6 additions & 9 deletions examples/Passwordless.Example/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion src/Passwordless.AspNetCore/IdentityBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ private static IServiceCollection AddPasswordlessCore(this IServiceCollection se
.Configure<IOptions<PasswordlessAspNetCoreOptions>>((options, aspNetCoreOptionsAccessor) =>
{
var aspNetCoreOptions = aspNetCoreOptionsAccessor.Value;
options.ApiSecret = aspNetCoreOptions.ApiSecret;
options.ApiUrl = aspNetCoreOptions.ApiUrl;
options.ApiSecret = aspNetCoreOptions.ApiSecret;
options.ApiKey = aspNetCoreOptions.ApiKey;
});

Expand Down
1 change: 1 addition & 0 deletions src/Passwordless/Passwordless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
Expand Down
18 changes: 18 additions & 0 deletions src/Passwordless/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Passwordless;

Expand Down Expand Up @@ -33,4 +34,21 @@ public static IServiceCollection AddPasswordlessSdk(

return services;
}

/// <summary>
/// Adds and configures Passwordless-related services.
/// </summary>
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"];
});
}
Loading