Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Oct 9, 2024
1 parent 324e674 commit 547dcc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions packages/oauth/oauth-client/src/oauth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,20 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
return this.keyset?.publicJwks ?? ({ keys: [] as const } as const)
}

async authorize(input: string, options?: AuthorizeOptions): Promise<URL> {
async authorize(
input: string,
{ signal, ...options }: AuthorizeOptions = {},
): Promise<URL> {
const redirectUri =
options?.redirect_uri ?? this.clientMetadata.redirect_uris[0]
if (!this.clientMetadata.redirect_uris.includes(redirectUri)) {
// The server will enforce this, but let's catch it early
throw new TypeError('Invalid redirect_uri')
}

const { identity, metadata } = await this.oauthResolver.resolve(
input,
options,
)
const { identity, metadata } = await this.oauthResolver.resolve(input, {
signal,
})

const pkce = await this.runtime.generatePKCE()
const dpopKey = await this.runtime.generateKey(
Expand Down
8 changes: 4 additions & 4 deletions packages/oauth/oauth-client/src/oauth-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class OAuthSession {
constructor(
public readonly server: OAuthServerAgent,
public readonly sub: string,
private readonly tokenGetter: SessionGetter,
private readonly sessionGetter: SessionGetter,
fetch: Fetch = globalThis.fetch,
) {
this.dpopFetch = dpopFetchWrapper<void>({
Expand Down Expand Up @@ -56,7 +56,7 @@ export class OAuthSession {
* if, and only if, they are (about to be) expired. Defaults to `undefined`.
*/
protected async getTokenSet(refresh: boolean | 'auto'): Promise<TokenSet> {
const { tokenSet } = await this.tokenGetter.get(this.sub, {
const { tokenSet } = await this.sessionGetter.get(this.sub, {
noCache: refresh === true,
allowStale: refresh === false,
})
Expand Down Expand Up @@ -88,7 +88,7 @@ export class OAuthSession {
const tokenSet = await this.getTokenSet(false)
await this.server.revoke(tokenSet.access_token)
} finally {
await this.tokenGetter.delStored(
await this.sessionGetter.delStored(
this.sub,
new TokenRevokedError(this.sub),
)
Expand Down Expand Up @@ -146,7 +146,7 @@ export class OAuthSession {
// TODO: Is there a "softer" way to handle this, e.g. by marking the
// session as "expired" in the session store, allowing the user to trigger
// a new login (using login_hint)?
await this.tokenGetter.delStored(
await this.sessionGetter.delStored(
this.sub,
new TokenInvalidError(this.sub),
)
Expand Down

0 comments on commit 547dcc0

Please sign in to comment.