Skip to content

Commit 969d25c

Browse files
elinohlssonElin Fokine
andauthored
Feature/504 device data cookie (#510)
* Improved documentation about risk indication. * Clarified documentation about cookies, data protection and the need to configure a persisted key store in some scenarios. * Added an important note in the release notes about cookies introduced in version 10.1, which have been shown to cause problems for some users. * Clarified documentation about Device Data (app and web parameters) and removed incorrect references to non-existing classes and methods. --------- Co-authored-by: Elin Fokine <ElinO@activesolution.se>
1 parent 7d154b3 commit 969d25c

3 files changed

Lines changed: 115 additions & 54 deletions

File tree

BREAKINGCHANGES.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,62 @@ ___Note:___ We might, and will probably, miss to document some of this - if so -
2525
Breaking changes between version 11.0.0 and 10.0.0
2626

2727
### Remove allowed risk Level
28-
Removed support for blocking auth and sign transactions based on risk level, since no longer supported by BankID. Use return risk instead and handle risk level in your application.
28+
Removed support for blocking auth and sign transactions based on risk level, since no longer supported by BankID.
29+
```csharp
30+
services.Configure<BankIdAuthOptions>(options =>
31+
{
32+
options.BankIdAllowedRiskLevel = BankIdAllowedRiskLevel.Low;
33+
});
34+
```
35+
36+
Use return risk instead and handle risk level in your application.
2937
```csharp
3038
services.Configure<BankIdAuthOptions>(options =>
3139
{
3240
options.BankIdReturnRisk = true;
3341
});
3442
```
43+
3544
BankID provides futher information more about [Risk Indication](https://www.bankid.com/en/foretag/the-service/risk-indication).
3645

3746

3847
---
3948

4049

50+
## Version 10.1.0
51+
52+
### Important Note
53+
Version 10.1.0 was released as a minor version and should not have introduced breaking changes. However, in practice, some users experienced issues related to the new cookie `__ActiveLogin.BankIdDeviceData`. If you encountered issues after upgrading, please review the guidance below.
54+
55+
### Added New Cookie for Device Data
56+
A new Cookie `__ActiveLogin.BankIdDeviceData` was added to store information about the end user’s device. This information is sent to BankID and used for risk indication.
57+
58+
The cookie is long lived and persisted across sessions. Since all cookies issued by Active Login are protected using ASP.NET Core Data Protection. In certain environments (such as multi-instance deployments or containers) you may need to configure Data Protection to use a persistent key store (e.g. a shared file system, Azure Blob Storage, Redis, or SQL Server) so that cookies can be unprotected across app restarts or multiple instances.
59+
60+
This applies also to the existing UI State cookie in Active Login. However, since that cookie has a very short lifetime compared to the device data cookie, the risk of running in to issues related to data protection is significantly lower for that cookie.
61+
62+
For guidance on configuring a persistent key store, see the official documentation: [Data Protection configuration overview](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-8.0).
63+
64+
65+
---
66+
67+
4168
## Version 10.0.0
4269

4370
Breaking changes between version 10.0.0 and 9.0.0
4471

72+
### Policy handling
73+
4574
* Remove policy handling from API library into Core
4675
* Fall back to mobile BankID policy for OtherDevice flow
4776
* Enum for setting policy instead of string
48-
* Replace embedded BankID certificate for the test environment FPTestcert4_20220818.p12, with the three new versions of the client certificate FPTestcert5_20240610.p12, FPTestcert5_20240610.pem and FPTestcert5_20240610-legacy.pfx. Make it configurable which version to use. For compatibility reasons use FPTestcert5_20240610-legacy.pfx by default.
77+
78+
79+
### Replaced Embedded BankID Certificate for Test Environment
80+
81+
Replace embedded BankID certificate for the test environment FPTestcert4_20220818.p12, with the three new versions of the client certificate FPTestcert5_20240610.p12, FPTestcert5_20240610.pem and FPTestcert5_20240610-legacy.pfx.
82+
83+
Make it configurable which version to use. For compatibility reasons use FPTestcert5_20240610-legacy.pfx by default.
4984

5085

5186
---

docs/articles/bankid.md

Lines changed: 77 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ The most common scenario is to use Active Login for BankID auth/login, so most o
4141
+ [Event listeners](#event-listeners)
4242
+ [Store data on auth completion](#store-data-on-auth-completion)
4343
+ [Resolve the end user ip](#resolve-the-end-user-ip)
44-
+ [Resolve the end user device data](#resolve-the-end-user-device-data)
44+
+ [Resolve the end user device data (app or web)](#resolve-the-end-user-device-data-app-or-web)
4545
+ [Resolve requirements on Auth request](#resolve-requirements-on-auth-request)
4646
+ [Resolve user data on Auth request](#resolve-user-data-on-auth-request)
4747
+ [Custom QR code generation](#custom-qr-code-generation)
4848
+ [Custom browser detection and launch info](#custom-browser-detection-and-launch-info)
49+
+ [Risk indication](#risk-indication)
4950
+ [Verify digital ID card](#verify-digital-id-card)
5051
+ [Use api wrapper only](#use-api-wrapper-only)
5152
+ [Running on Linux](#running-on-linux)
@@ -577,11 +578,7 @@ BankId options allows you to set and override some options such as the below req
577578
// If no policy is set, it will fall back to require mobile BankID for OtherDevice flow
578579
options.BankIdCertificatePolicies = [ BankIdCertificatePolicy.BankIdOnFile, BankIdCertificatePolicy.BankIdOnSmartCard ];
579580

580-
// If this is set to true a risk indicator will be included in the collect response when the order completes.
581-
// If a risk indicator is required for the order to complete, for example, if a risk requirement is applied,
582-
// the returnRisk property is ignored, and a risk indicator is always included; otherwise a default value of
583-
// false is used. The risk indication requires that the endUserIp is correct. Please note that the assessed
584-
// risk will not be returned if the order was blocked, which may happen if a risk requirement is set.
581+
// If set to true a risk indication is requested from BankID and returned as part of the collect response.
585582
options.BankIdReturnRisk = true;
586583
});
587584
```
@@ -778,23 +775,6 @@ public class BankIdPinHintClaimsTransformer : IBankIdClaimsTransformer
778775
}
779776
```
780777

781-
#### Example: Add risk claim
782-
783-
If the application whats to act on the evaluated risk level for the transaction it could be extracted from the completion data returned by BankID.
784-
785-
```csharp
786-
public class BankIdTxnClaimsTransformer : IBankIdClaimsTransformer
787-
{
788-
public Task TransformClaims(BankIdClaimsTransformationContext context)
789-
{
790-
if (context.BankIdCompletionData != null && context.BankIdCompletionData.Risk != null)
791-
context.AddClaim("user_risk", context.BankIdCompletionData.Risk);
792-
793-
return Task.CompletedTask;
794-
}
795-
}
796-
```
797-
798778
### Return URL for cancellation
799779

800780
If a user cancels the login, the user will be redirected to the `cancelReturnUrl`.
@@ -1140,24 +1120,19 @@ services.AddTransient<IBankIdEndUserIpResolver, EndUserIpResolver>();
11401120
```
11411121

11421122
---
1143-
### Device data
1123+
### Resolve the end user device data (app or web)
11441124

1145-
When initiating a flow with BankID, the objects "app" or "web" can be included in the request.
1146-
The information in these two objects differs, but including either of them allows BankID to
1147-
provide a better risk indication.
1125+
When initiating a flow with BankID, you can include either the **`web`** parameter (for **web applications**) or the **`app`** parameter (for **mobile apps**) in the request. In Active Login, these parameters are collectively referred to as **device data**.
1126+
The metadata included with these parameters differs depending on the device type, but providing either one allows BankID to deliver a more accurate [Risk indication](#risk-indication).
11481127

1149-
When using BankID, device information provides valuable metadata that enhances security and ensures a smoother user experience.
1150-
Including the **device type** (e.g., `APP` or `WEB`) helps BankID:
1151-
- **Evaluate risk** for each request.
1152-
- **Take automated actions** based on high-risk scenarios (if enabled).
1153-
- Provide **better insights** into the context of the request.
1128+
**Risk Indication** provides an estimated risk level for a BankID transaction. It is a way to enhance the security of your application by, for example, requiring additional controls such as ID card validation for transactions that are assessed as high risk.
11541129

11551130
#### Configuring Device Data
11561131

1157-
Active Login has a default implementation of the User Device feature that uses a
1158-
web browser as the device type. You can customize the default implementation or create your own.
1132+
Active Login provides a default implementation of the Device Data feature that assumes it is running from a **web application**.
1133+
You can either customize this default implementation or create your own for other device types.
11591134

1160-
The following service interface must be implemented to use the User Device feature:
1135+
The following service interface must be implemented to use the Device Data feature:
11611136
- `IBankIdEndUserDeviceDataResolverFactory`: Factory that provides the resolvers for the device type.
11621137
- `IBankIdEndUserDeviceDataResolver`: Resolver that provides the device data for a given device type.
11631138
- `IBankIdEndUserDeviceDataConfiguration`: Configuration that specifies the device type to use.
@@ -1166,16 +1141,24 @@ The following service interface must be implemented to use the User Device featu
11661141

11671142
| Device Type | Default Resolver Implementation | Metadata Included |
11681143
|---------------|-------------------------------------------|--------------------------------------------|
1169-
| **Web** | `BankIdDefaultEndUserWebDeviceDataResolver` | Referring domain, User-Agent, DeviceIdentifier |
1170-
| **App** | `BankIdDefaultEndUserAppDeviceDataResolver` | App Identifier, Device OS, Model, DeviceIdentifier |
1144+
| **Web** | `BankIdDefaultEndUserWebDeviceDataResolver` | Referring Domain, User-Agent, Device Identifier |
1145+
| **App** | No resolver is configured by default for mobile apps. | App Identifier, Device OS, Model, Device Identifier |
1146+
1147+
The **Device Identifier**, included in both the **`web`** and **`app`** parameters, must remain identical across requests.
1148+
1149+
For **web applications**, the **Device Identifier** should be unique to the user's browser and must not rely on a session cookie, it can be stored in a separate cookie or as a hash of one.
1150+
The `BankIdDefaultEndUserWebDeviceDataResolver` sets a protected cookie named `__ActiveLogin.BankIdDeviceData` containing a unique **Device Identifier**. This ensures that the identifier persists across sessions and requests.
1151+
1152+
For **mobile apps**, the **Device Identifier** uniquely identifies the device your client is running on. It should not be tied to a single user of the device and ideally should remain the same even if the app is reinstalled.
11711153

1172-
The Device identifier must be identical between requests.
11731154

1174-
The `BankIdDefaultEndUserWebDeviceDataResolver` will set a protected cookie named `__ActiveLogin.BankIdDeviceData` that contains
1175-
unique identifier (DeviceIdentifier) to ensure that the identifier is persistent across requests.
1155+
___Note:___
11761156

1177-
#### Customizing the User Device feature
1178-
To customize the User Device feature, use the `UseDeviceData` extension in the BankID client builder.
1157+
Cookies are protected using ASP.NET Core Data Protection. For more information about the cookies used by the package, including how they are protected and considerations for persistent key storage, see the [Cookies issued](#cookies-issued) section above. This is important, especially in distributed environments.
1158+
1159+
1160+
#### Customizing the Device Data feature
1161+
To customize the Device Data feature, use the `UseDeviceData` extension in the BankID client builder.
11791162
This allows you to specify the device type and any relevant metadata using resolvers.
11801163

11811164
The BankIdFlowService will automatically include the device data in the BankID request,
@@ -1202,7 +1185,7 @@ services
12021185
config.UseResolverFactory<BankIdDefaultEndUserDeviceDataResolverFactory>();
12031186

12041187
// Add the default resolver for Web
1205-
config.AddDeviceResolver<BankIdDefaultEndUserWebDeviceDataResolver>();
1188+
config.UseDeviceResolver<BankIdDefaultEndUserWebDeviceDataResolver>();
12061189
});
12071190
});
12081191
```
@@ -1223,7 +1206,7 @@ services
12231206

12241207
// Add a custom resolver for the device type Web
12251208
// that implements IBankIdEndUserDeviceDataResolver
1226-
config.AddDeviceResolver<MyCustomWebDeviceDataResolver>();
1209+
config.UseDeviceResolver<MyCustomWebDeviceDataResolver>();
12271210
});
12281211
});
12291212
```
@@ -1246,7 +1229,7 @@ services
12461229
// Use the default data resolver for the device type app
12471230
// On app devices (e.g. MAUI, Xamarin, etc.) we need to set the
12481231
// device data manually at start
1249-
config.AddDeviceResolver(s => new BankIdDefaultEndUserAppDeviceDataResolver()
1232+
config.UseDeviceResolver<IBankIdEndUserDeviceDataResolver>(_ => new BankIdAppDeviceDataResolver()
12501233
{
12511234
// App ID or package name
12521235
AppIdentifier = "com.example.app",
@@ -1264,7 +1247,9 @@ services
12641247
});
12651248
});
12661249
```
1267-
The information for the BankIdDefaultEndUserAppDeviceDataResolver has to be set during startup.
1250+
1251+
The information for the `BankIdAppDeviceDataResolver` must be configured during application startup. You can also provide your own custom resolver implementation for mobile apps. There is no default resolver that automatically fetches device data for mobile apps because this data must be retrieved from the device hardware, which can vary between devices (iOS, Android, etc.).
1252+
12681253

12691254
#### More information available at:
12701255
- [BankID Risk Indication](https://www.bankid.com/en/foretag/the-service/risk-indication)
@@ -1471,6 +1456,43 @@ public class BankIdFacebookAppBrowserConfig : IBankIdLauncherCustomAppCallback
14711456

14721457
```
14731458

1459+
### Risk indication
1460+
1461+
You can choose to request a risk indication from BankID for both identifications and signatures. It can be used to increase security, protect your customers and reduce the risk of fraud. The indication is categorized as low, medium or high risk.
1462+
You must implement your own logic to act on the assessed risk level from BankID.
1463+
1464+
You need to provide information to BankID in the auth or sign request, to help them make the risk assessment e.g. the end users IP address and the app or web property (which is part of [Device Data](#resolve-the-end-user-device-data) in Active Login).
1465+
1466+
Incorrect information in the call gives an incorrect risk indication.
1467+
1468+
Use the BankID option below to turn on risk indication. Read more about [Customizing BankID options](#customizing-bankid-options).
1469+
1470+
```csharp
1471+
services.Configure<BankIdAuthOptions>(options =>
1472+
{
1473+
options.BankIdReturnRisk = true;
1474+
});
1475+
```
1476+
1477+
To get risk indication extracted from the completion data returned by BankID and issued as a claim from Active Login [create your own claims transformer](#claims-issuing).
1478+
1479+
```csharp
1480+
public class BankIdTxnClaimsTransformer : IBankIdClaimsTransformer
1481+
{
1482+
public Task TransformClaims(BankIdClaimsTransformationContext context)
1483+
{
1484+
if (context.BankIdCompletionData != null && context.BankIdCompletionData.Risk != null)
1485+
context.AddClaim("user_risk", context.BankIdCompletionData.Risk);
1486+
1487+
return Task.CompletedTask;
1488+
}
1489+
}
1490+
```
1491+
1492+
#### More information available at:
1493+
- [BankID Risk Indication](https://www.bankid.com/en/foretag/the-service/risk-indication)
1494+
1495+
14741496
### Verify digital ID card
14751497

14761498
To use the API for "Verify digital ID card" you first need to register the BankID services, select an environment etc.
@@ -1598,9 +1620,16 @@ The `*.AspNetCore` package will issue a cookie to make the auth flow work
15981620
- A more technical deep dive of this cookie can be found in [this issue](https://github.com/ActiveLogin/ActiveLogin.Authentication/issues/156).
15991621
16001622
- Cookie: `__ActiveLogin.BankIdDeviceData`
1601-
- This cookie is used to store the device data for the user, in the default implementation,
1602-
It is used to ensure that the device data is persistent across requests.
1623+
- This cookie is used to store the device data for the user, in the default implementation, it is used to ensure that the device data is persistent across requests.
1624+
16031625

1626+
___Note:___
1627+
1628+
All cookies issued by this package are **protected using ASP.NET Core Data Protection**. This means their contents are encrypted and tamper-proof.
1629+
1630+
In certain environments (such as multi-instance deployments or containers) you may need to **configure Data Protection to use a persistent key store** (e.g., a shared file system, Azure Blob Storage, Redis, or SQL Server) so that cookies can be unprotected across app restarts or multiple instances.
1631+
1632+
For guidance on configuring a persistent key store, see the official documentation: [Data Protection configuration overview](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-8.0).
16041633
16051634

16061635
### Browser support

src/ActiveLogin.Authentication.BankId.AspNetCore/Auth/BankIdAuthOptions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public class BankIdAuthOptions : RemoteAuthenticationOptions
3333

3434
/// <summary>
3535
/// If this is set to true a risk indicator will be included in the collect response when the order completes.
36-
/// If a risk indicator is required for the order to complete, for example, if a risk requirement is applied,
37-
/// the returnRisk property is ignored, and a risk indicator is always included; otherwise a default value of
38-
/// false is used. The risk indication requires that the endUserIp is correct. Please note that the assessed
39-
/// risk will not be returned if the order was blocked, which may happen if a risk requirement is set.
36+
/// The risk indication requires that sending correct information to BankID e.g. the end users IP and device data.
4037
/// </summary>
4138
public bool BankIdReturnRisk { get; set; } = false;
4239

0 commit comments

Comments
 (0)