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

OAuth: Fix for multiple redirect_uris #2756

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type Schema = {
iss: string
verifier?: string
appState?: string
redirectUri?: string
}>
session: Item<{
dpopKey: EncodedKey
Expand Down
9 changes: 8 additions & 1 deletion packages/oauth/oauth-client/src/oauth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
dpopKey,
verifier: pkce.verifier,
appState: options?.state,
...(redirectUri !== this.clientMetadata.redirect_uris[0]
? { redirectUri }
: {}),
})

const parameters: OAuthAuthorizationRequestParameters = {
Expand Down Expand Up @@ -443,7 +446,11 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
)
}

const tokenSet = await server.exchangeCode(codeParam, stateData.verifier)
const tokenSet = await server.exchangeCode(
codeParam,
stateData.redirectUri ?? this.clientMetadata.redirect_uris[0],
stateData.verifier,
)
try {
await this.sessionGetter.setStored(tokenSet.sub, {
dpopKey: stateData.dpopKey,
Expand Down
8 changes: 6 additions & 2 deletions packages/oauth/oauth-client/src/oauth-server-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ export class OAuthServerAgent {
}
}

async exchangeCode(code: string, codeVerifier?: string): Promise<TokenSet> {
async exchangeCode(
code: string,
redirectUri: string,
codeVerifier?: string,
): Promise<TokenSet> {
const now = Date.now()

const tokenResponse = await this.request('token', {
grant_type: 'authorization_code',
redirect_uri: this.clientMetadata.redirect_uris[0]!,
redirect_uri: redirectUri,
code,
code_verifier: codeVerifier,
})
Expand Down
1 change: 1 addition & 0 deletions packages/oauth/oauth-client/src/state-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type InternalStateData = {
dpopKey: Key
verifier?: string
appState?: string
redirectUri?: string
}

export type StateStore = SimpleStore<string, InternalStateData>