@@ -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 )
@@ -788,6 +789,51 @@ public class Startup
788789}
789790```
790791
792+ ### Customizing StateStorage
793+
794+ 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 ).
795+
796+ To do so , implement the IStateStorage interface in your own class :
797+
798+ ```csharp
799+ using ActiveLogin .Authentication .BankId .Core ;
800+
801+ public class CustomStateStorage : IStateStorage
802+ {
803+ public async Task < StateKey > WriteAsync (object value )
804+ {
805+ // Implement your custom logic to store the state,
806+ // for example, saving data into a database.
807+ var key = Guid .NewGuid ().ToString ();
808+ // ...custom persistence logic here...
809+ return await Task .FromResult (new StateKey (key ));
810+ }
811+
812+ public async Task < object ? > ReadAsync (StateKey key )
813+ {
814+ // Retrieve the state associated with the key.
815+ return await Task .FromResult <object ?>(null );
816+ }
817+
818+ public async Task < object ? > RemoveAsync (StateKey key )
819+ {
820+ // Remove the stored state.
821+ return await Task .FromResult <object ?>(null );
822+ }
823+ }
824+ ```
825+
826+ Register your custom implementation during startup :
827+
828+ ```csharp
829+ services
830+ .AddBankId (bankId =>
831+ {
832+ bankId .AddStateStorage <CustomStateStorage >();
833+ // ...other configuration...
834+ });
835+ ```
836+
791837### Customize the UI
792838
793839Active 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