Badisi / auth-js

🛡️ Authentication and authorization support for web based desktop and mobile applications
GNU General Public License v3.0
9 stars 1 forks source link

[FEATURE] Allow to provide other secure storage #45

Open ms-emp opened 1 month ago

ms-emp commented 1 month ago

Description

I would like to use a different capacitor plugin for secure storage. for example: capacitor-secure-storage

Proposed solution

It should be a way to provide a different secure storage

Alternatives considered

No response

Badisi commented 1 month ago

Already supported : https://github.com/Badisi/auth-js/blob/main/projects/auth-js/oidc/mobile/mobile-storage.ts#L27

As long as you have the package installed, the library will use it 😉

Badisi commented 1 month ago

@ms-emp, did it worked ?

ms-emp commented 1 month ago

Hi @Badisi

The library looks for this specific plugin, my question is if we can provide a different secure plugin or use a custom implementation for saving/retrieving the tokens.

Badisi commented 1 month ago

Sorry I misread the name of the plugin you mentioned as it's quite similar with capacitor-secure-storage-plugin.

So you can provide your own implementation, either:

  1. By using the initialization settings:
    
    import { InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
    import { AuthUtils } from '@badisi/auth-js'; // or '@badisi/ngx-auth'

initAuth({ ..., internal: { userStore: new WebStorageStateStore({ store: AuthUtils.isNativeMobile() ? new MyMobileStorage() : new InMemoryWebStorage() // or simply "store: new MyMobileStorage()" if you are only developing for mobile }) } }


2. By overriding one of the reference the library is using:
```ts
// Example
window.Capacitor.Plugins.SecureStoragePlugin = new MyMobileStorage()

And in your case maybe:

import { SecureStorage } from '@aparajita/capacitor-secure-storage';
...
  store: new SecureStorage()
...

// or

window.Capacitor.Plugins.SecureStoragePlugin = window.Capacitor.Plugins.AparajitaCapacitorSecureStorage;
Badisi commented 1 month ago

Let me know how it goes 😉