Skip to content

Commit

Permalink
feat: allow user to specify refreshToken
Browse files Browse the repository at this point in the history
  • Loading branch information
xhayper committed Jul 29, 2024
1 parent acfccd5 commit 68ef320
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type AuthorizeOptions = {
scopes: (OAuth2Scopes | `${OAuth2Scopes}`)[];
prompt?: "consent" | "none";
useRPCToken?: boolean;

refreshToken?: string;
};

export interface ClientOptions {
Expand Down Expand Up @@ -389,9 +391,14 @@ export class Client extends (EventEmitter as new () => TypedEventEmitter<ClientE
return;
}

if (!this.clientSecret) throw new ReferenceError("Client secret is required for authorization!");
if (options.refreshToken) {
this.refreshToken = options.refreshToken;
await this.refreshAccessToken();
} else {
if (!this.clientSecret) throw new ReferenceError("Client secret is required for authorization!");
await this.authorize(options);
}

await this.authorize(options);
await this.authenticate();
}

Expand Down

0 comments on commit 68ef320

Please sign in to comment.