Skip to content
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
12 changes: 12 additions & 0 deletions docs/articles/bankid.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,18 @@ services.AddBankId(bankId =>
});
```

### Using client certificate from custom certificate service

```csharp
services.AddBankId(bankId =>
{
bankId
.UseProductionEnvironment()
.UseClientCertificate(sp => sp.GetRequiredService<MyCustomCertificateService>().GetCertificate())
...
});
```

### Adding schemas

* *Same device*: Launches the BankID app on the same device, no need to enter any personal identity number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,29 @@ public static IBankIdBuilder UseClientCertificate(this IBankIdBuilder builder, F
void ConfigureHttpClientHandler(IServiceProvider sp, SocketsHttpHandler httpClientHandler)
{
var clientCertificate = configureClientCertificate();
httpClientHandler.SslOptions.ClientCertificates = new X509Certificate2Collection { clientCertificate };
httpClientHandler.SslOptions.ClientCertificates ??= new X509Certificate2Collection();
httpClientHandler.SslOptions.ClientCertificates.Add(clientCertificate);
}
}

/// <summary>
/// Add client certificate for authenticating against the BankID API to the list of available certificates for the http client handler to choose from.
/// </summary>
/// <param name="builder"></param>
/// <param name="configureClientCertificate">The certificate to add.</param>
/// <returns></returns>
public static IBankIdBuilder UseClientCertificate(this IBankIdBuilder builder, Func<IServiceProvider, X509Certificate2> configureClientCertificate)
{
builder.ConfigureAppApiHttpClientHandler(ConfigureHttpClientHandler);
builder.ConfigureVerifyApiHttpClientHandler(ConfigureHttpClientHandler);

return builder;

void ConfigureHttpClientHandler(IServiceProvider sp, SocketsHttpHandler httpClientHandler)
{
var clientCertificate = configureClientCertificate(sp);
httpClientHandler.SslOptions.ClientCertificates ??= new X509Certificate2Collection();
httpClientHandler.SslOptions.ClientCertificates.Add(clientCertificate);
}
}

Expand Down Expand Up @@ -186,7 +208,12 @@ internal static IBankIdBuilder UseEnvironment(this IBankIdBuilder builder, Uri a
/// <param name="useBankIdClientCertificate">Use the BankID client certificate (for test) from the BankID documentation.</param>
/// <param name="clientCertificateFormat">If using the BankID client certificate (for test). Select the preferred format p12, pem or pfx.</param>
/// <returns></returns>
public static IBankIdBuilder UseTestEnvironment(this IBankIdBuilder builder, bool useBankIdRootCertificate = true, bool useBankIdClientCertificate = true, TestCertificateFormat clientCertificateFormat = TestCertificateFormat.PFX)
public static IBankIdBuilder UseTestEnvironment(
this IBankIdBuilder builder,
bool useBankIdRootCertificate = true,
bool useBankIdClientCertificate = true,
TestCertificateFormat clientCertificateFormat = TestCertificateFormat.PFX
)
{
builder.UseEnvironment(BankIdUrls.AppApiTestBaseUrl, BankIdUrls.VerifyApiTestBaseUrl, BankIdEnvironments.Test);
builder.Services.AddTransient<IBankIdCertificatePolicyResolver, BankIdCertificatePolicyResolverForTest>();
Expand Down
Loading