Badisi / auth-js

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

[FEATURE] Allow to provide other secure storage #45

Open ms-emp opened 2 months ago

ms-emp commented 2 months 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 2 months 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 2 months ago

@ms-emp, did it worked ?

ms-emp commented 2 months 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 2 months 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 2 months ago

Let me know how it goes 😉