Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Allow to provide other secure storage #45

Open
ms-emp opened this issue Sep 16, 2024 · 5 comments
Open

[FEATURE] Allow to provide other secure storage #45

ms-emp opened this issue Sep 16, 2024 · 5 comments
Labels
enhancement New feature or request needs triage

Comments

@ms-emp
Copy link
Contributor

ms-emp commented Sep 16, 2024

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

@ms-emp ms-emp added enhancement New feature or request needs triage labels Sep 16, 2024
@ms-emp ms-emp changed the title [FEATURE] <Provide other secure storage> [FEATURE] Provide other secure storage Sep 16, 2024
@ms-emp ms-emp changed the title [FEATURE] Provide other secure storage [FEATURE] Allow to provide other secure storage Sep 16, 2024
@Badisi
Copy link
Owner

Badisi commented Sep 16, 2024

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
Copy link
Owner

Badisi commented Sep 18, 2024

@ms-emp, did it worked ?

@ms-emp
Copy link
Contributor Author

ms-emp commented Sep 18, 2024

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
Copy link
Owner

Badisi commented Sep 18, 2024

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
    })
  }
}
  1. By overriding one of the reference the library is using:
// 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
Copy link
Owner

Badisi commented Sep 18, 2024

Let me know how it goes 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage
Projects
None yet
Development

No branches or pull requests

2 participants