Skip to content

Commit 374d6a5

Browse files
committed
update docs
1 parent 6a84a81 commit 374d6a5

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"markdownlint.config": {
33
"MD033": {
4-
"allowed_elements": ["nobr", "sup", "a", "img"]
4+
"allowed_elements": ["a", "img"]
55
}
66
}
77
}

docs/articles/bankid.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ The most common scenario is to use Active Login for BankID auth/login, so most o
114114
- [Return URL for cancellation](#return-url-for-cancellation)
115115
- [Handle missing or invalid state cookie](#handle-missing-or-invalid-state-cookie)
116116
- [Multi tenant scenario](#multi-tenant-scenario)
117+
- [Customizing StateStorage](#customizing-statestorage)
117118
- [Customize the UI](#customize-the-ui)
118119
- [Simulate BankID API errors](#simulate-bankid-api-errors)
119120
- [Simulated API error usage](#simulated-api-error-usage)
@@ -963,6 +964,51 @@ public class Startup
963964
}
964965
```
965966

967+
### Customizing StateStorage
968+
969+
ActiveLogin.Authentication uses an implementation of IStateStorage to persist temporary state during the BankID authentication flow. By default an in-memory implementation is used, which works great for development and testing. However, for production you might want to persist state using a different storage mechanism (for example, in a database or through a distributed cache).
970+
971+
To do so, implement the IStateStorage interface in your own class:
972+
973+
```csharp
974+
using ActiveLogin.Authentication.BankId.Core;
975+
976+
public class CustomStateStorage : IStateStorage
977+
{
978+
public async Task<StateKey> WriteAsync(object value)
979+
{
980+
// Implement your custom logic to store the state,
981+
// for example, saving data into a database.
982+
var key = Guid.NewGuid().ToString();
983+
// ...custom persistence logic here...
984+
return await Task.FromResult(new StateKey(key));
985+
}
986+
987+
public async Task<object?> ReadAsync(StateKey key)
988+
{
989+
// Retrieve the state associated with the key.
990+
return await Task.FromResult<object?>(null);
991+
}
992+
993+
public async Task<object?> RemoveAsync(StateKey key)
994+
{
995+
// Remove the stored state.
996+
return await Task.FromResult<object?>(null);
997+
}
998+
}
999+
```
1000+
1001+
Register your custom implementation during startup:
1002+
1003+
```csharp
1004+
services
1005+
.AddBankId(bankId =>
1006+
{
1007+
bankId.AddStateStorage<CustomStateStorage>();
1008+
// ...other configuration...
1009+
});
1010+
```
1011+
9661012
### Customize the UI
9671013

9681014
Active Login comes with predefined views that you can use, but maybe you'd rather use your own views to customize layout or behavior.

0 commit comments

Comments
 (0)