Typically, the angular-oauth2-oidc library saves tokens in session storage by default.
While you can provide your own storage provider through the OAuthStorage class, it requires a storage provider that can retrieve data synchronously.
I am developing a mobile hybrid app using Ionic and CapacitorJS, and I need to store tokens using the CapacitorJS Storage plug-in.
The CapacitorJS Storage plug-in only allows asynchronous data retrieval methods, such as:
get(options: GetOptions) => Promise<GetResult>
This poses a challenge when integrating with the synchronous expectations of the angular-oauth2-oidc library. For instance, their method to fetch an access token follows this pattern:
public getAccessToken(): string {
return this._storage ? this._storage.getItem('access_token') : null;
}
Is there a way for me to create an implementation of the OAuthStorage class with a synchronous getItem
method that can utilize the asynchronous CapacitorjS.Storage.get
method?
Alternatively, is it possible to convert data from an asynchronous method to be compatible with a synchronous method without altering the caller?