@@ -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
9681014Active 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