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 3 commits into
base: main
Choose a base branch
from

Conversation

sugyan
Copy link
Contributor

@sugyan sugyan commented Aug 28, 2024

In the client metadata, multiple redirect_uri can be specified,

const clientMetadata: OAuthClientMetadata = {
  client_id: "https://oauth.example.com/client.json",
  response_types: ["code"],
  grant_types: ["authorization_code"],
  redirect_uris: [
    "https://oauth.example.com/callback1",
    "https://oauth.example.com/callback2",
  ],
};

Any value contained in the redirect_uris can be used in the options of the OAuthClient.authorize() method.

const client = new OAuthClient({
  clientMetadata,
  responseMode: "query",

  ...

});
const authorization_url = await client.authorize(input, {
  scope: "atproto",
  redirect_uri: "https://oauth.example.com/callback2",
});

However, even in the above case, the current implementation automatically selects and sends this.clientMetadata.redirect_uris[0] in the token request, so even if the redirected params are correctly obtained, exchangeCode() returns the following error.

{"error": "invalid_grant", "error_description": "This code was issued for another redirect_uri"}

Actually, the callback() method does not receive the redirect_uri, so I think the only way to get the value of the redirect_uri used in the PAR is through stateStore.

@matthieusieben
Copy link
Contributor

I would be fine with incorporating something like this only it should be optional, especially for clients that only have one redirect uri.

@sugyan
Copy link
Contributor Author

sugyan commented Sep 4, 2024

Thank you for responding to my pull request!
I changed the redirectUri stored in the stateStore to an optional one. The same behavior as before is achieved by implementing the following: save only when the value is not equal to this.clientMetadata.redirect_uris[0], and use this.clientMetadata.redirect_uris[0] as the default value if there is no value when retrieving.
This will avoid wasting space in the stateStore since the value is saved only in special cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants