@@ -43,6 +43,7 @@ The most common scenbario is to use Active Login for BankID auth/login, so most
4343 - [ Return URL for cancellation] ( #return-url-for-cancellation )
4444 - [ Handle missing or invalid state cookie] ( #handle-missing-or-invalid-state-cookie )
4545 - [ Multi tenant scenario] ( #multi-tenant-scenario )
46+ - [ Customizing StateStorage] ( #customizing-statestorage )
4647 - [ Customize the UI] ( #customize-the-ui )
4748 - [ Simulate BankID API errors] ( #simulate-bankid-api-errors )
4849 - [ Simulated API error usage] ( #simulated-api-error-usage )
@@ -783,6 +784,51 @@ public class Startup
783784}
784785```
785786
787+ ### Customizing StateStorage
788+
789+ 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 ).
790+
791+ To do so , implement the IStateStorage interface in your own class :
792+
793+ ```csharp
794+ using ActiveLogin .Authentication .BankId .Core ;
795+
796+ public class CustomStateStorage : IStateStorage
797+ {
798+ public async Task < StateKey > WriteAsync (object value )
799+ {
800+ // Implement your custom logic to store the state,
801+ // for example, saving data into a database.
802+ var key = Guid .NewGuid ().ToString ();
803+ // ...custom persistence logic here...
804+ return await Task .FromResult (new StateKey (key ));
805+ }
806+
807+ public async Task < object ? > ReadAsync (StateKey key )
808+ {
809+ // Retrieve the state associated with the key.
810+ return await Task .FromResult <object ?>(null );
811+ }
812+
813+ public async Task < object ? > RemoveAsync (StateKey key )
814+ {
815+ // Remove the stored state.
816+ return await Task .FromResult <object ?>(null );
817+ }
818+ }
819+ ```
820+
821+ Register your custom implementation during startup :
822+
823+ ```csharp
824+ services
825+ .AddBankId (bankId =>
826+ {
827+ bankId .AddStateStorage <CustomStateStorage >();
828+ // ...other configuration...
829+ });
830+ ```
831+
786832### Customize the UI
787833
788834Active 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