Removed Zustand storage, cleanup up auth storage IO interfaces, implementations, and usage.
This commit is contained in:
parent
512f45d357
commit
3c65bdb4c6
1 changed files with 863 additions and 1008 deletions
|
|
@ -103,6 +103,8 @@ export class BaseOAuthClientProvider implements OAuthClientProvider {
|
|||
private capturedAuthUrl: URL | null = null;
|
||||
private eventTarget: EventTarget | null = null;
|
||||
private suppressAuthorizationNavigation = false;
|
||||
/** Cached after {@link prepareForAuth} for sync SDK `clientMetadata.scope`. */
|
||||
private cachedScope: string | undefined;
|
||||
|
||||
protected serverUrl: string;
|
||||
protected storage: OAuthStorage;
|
||||
|
|
@ -118,6 +120,14 @@ export class BaseOAuthClientProvider implements OAuthClientProvider {
|
|||
this.clientMetadataUrl = oauthConfig.clientMetadataUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load persisted scope into {@link cachedScope} before SDK `auth()` (which
|
||||
* reads {@link clientMetadata.scope} synchronously).
|
||||
*/
|
||||
async prepareForAuth(): Promise<void> {
|
||||
this.cachedScope = await this.storage.getScope(this.serverUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event target for dispatching oauthAuthorizationRequired events
|
||||
*/
|
||||
|
|
@ -145,7 +155,7 @@ export class BaseOAuthClientProvider implements OAuthClientProvider {
|
|||
}
|
||||
|
||||
get scope(): string | undefined {
|
||||
return this.storage.getScope(this.serverUrl);
|
||||
return this.cachedScope;
|
||||
}
|
||||
|
||||
get redirectUrl(): string {
|
||||
|
|
@ -200,6 +210,7 @@ export class BaseOAuthClientProvider implements OAuthClientProvider {
|
|||
|
||||
async saveScope(scope: string | undefined): Promise<void> {
|
||||
await this.storage.saveScope(this.serverUrl, scope);
|
||||
this.cachedScope = scope;
|
||||
}
|
||||
|
||||
async savePreregisteredClientInformation(
|
||||
|
|
@ -239,8 +250,8 @@ export class BaseOAuthClientProvider implements OAuthClientProvider {
|
|||
await this.storage.saveCodeVerifier(this.serverUrl, codeVerifier);
|
||||
}
|
||||
|
||||
codeVerifier(): string {
|
||||
const verifier = this.storage.getCodeVerifier(this.serverUrl);
|
||||
async codeVerifier(): Promise<string> {
|
||||
const verifier = await this.storage.getCodeVerifier(this.serverUrl);
|
||||
if (!verifier) {
|
||||
throw new Error("No code verifier saved for session");
|
||||
}
|
||||
|
|
@ -251,7 +262,7 @@ export class BaseOAuthClientProvider implements OAuthClientProvider {
|
|||
await this.storage.clear(this.serverUrl);
|
||||
}
|
||||
|
||||
getServerMetadata(): OAuthMetadata | null {
|
||||
async getServerMetadata(): Promise<OAuthMetadata | null> {
|
||||
return this.storage.getServerMetadata(this.serverUrl);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue