-
Notifications
You must be signed in to change notification settings - Fork 554
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
Generic OAuth error "due to an internal error" for "invalid_client_metadata" #3096
Comments
I get a 404 when I curl that endpoint, it needs to return the client-metadata.json content and it must match with what is passed to the NodeOAuthClient:
I built a passport strategy you might want to try with your node app, or at least look at the working example: https://github.com/mikestaub/passport-atprotocol |
Oops, I did a bad job of keeping this example in sync while I was trying things today. The new metadata URL is: Thanks for the library as well, I will give it a read! |
I thought the lack of keysets and a token endpoint auth method might be the culprit so, thanks to Tyler from Sill, I now have a locally working version with keys that looks like this: const privateKeyPKCS8 = Buffer.from(
process.env.PRIVATE_KEY_ES256_B64 as string,
"base64",
).toString();
const privateKey = await JoseKey.fromImportable(privateKeyPKCS8, "key1");
const isDev = process.env.NODE_ENV == "development";
const origin = isDev ? "http://127.0.0.1:3000" : "https://skylights.my";
const abs = (s: string) => `${origin}/${s}`;
const enc = encodeURIComponent;
const SCOPE = "atproto transition:generic";
const REDIRECT_URI = abs("oauth/atproto-callback");
export const authClient = new NodeOAuthClient({
clientMetadata: {
client_id: isDev
? `http://localhost?redirect_uri=${enc(REDIRECT_URI)}&scope=${enc(SCOPE)}`
: abs("oauth/client-metadata.json"),
client_name: "Skylights",
client_uri: origin,
redirect_uris: [REDIRECT_URI],
grant_types: ["authorization_code", "refresh_token"],
response_types: ["code"],
application_type: "web",
scope: SCOPE,
token_endpoint_auth_method: "private_key_jwt",
token_endpoint_auth_signing_alg: "ES256",
dpop_bound_access_tokens: true,
jwks_uri: abs("oauth/jwks.json"),
},
keyset: [privateKey],
...stores
}); Unfortunately it still fails with the exact same error on prod :( |
I am wondering if it would be possible to add info about which FetchError failed, maybe adding status code and path wouldn't be too much of an information leak? atproto/packages/oauth/oauth-provider/src/client/client-manager.ts Lines 121 to 128 in 3303ff1
Update: Sorry that didn't make sense, just realized that the original error is bubbled out as well. |
invalid_client_metadata likely means they simply do not match. Can you try logging out the JSON of your client metadata on the server and then diffing it with the json response from your public endpoint? |
I just logged {
"application_type": "web",
"client_id": "https://skylights.my/oauth/client-metadata.json",
"client_name": "Skylights",
"client_uri": "https://skylights.my",
"dpop_bound_access_tokens": true,
"grant_types": [
"authorization_code",
"refresh_token"
],
"jwks_uri": "https://skylights.my/oauth/jwks.json",
"redirect_uris": [
"https://skylights.my/oauth/atproto-callback"
],
"response_types": [
"code"
],
"scope": "atproto transition:generic",
"token_endpoint_auth_method": "private_key_jwt",
"token_endpoint_auth_signing_alg": "ES256"
} Thanks for the idea, happy to investigate any avenue at this point 😵💫 |
strange, that looks good to me. The last thing I would try is removing the "refresh_token" from the metadata |
No luck with that one either, appreciate the attempt tho! |
How did you generate your private key? Here is a working example: https://github.com/mikestaub/passport-atprotocol/blob/main/scripts/generate-keys.js |
A friend helped me solve it! It was something stupid that felt unrelated to me. I though my main domain was the one without WWW and that the one with redirected towards it. Turned out it was the other way around. So the obtuse error because instead of getting a 200 for the client metadata it got a 308. It would be very helpful if that error would bubble out though, so I'll keep this issue open. Thank you for holding my hand @mikestaub! |
Closing as #3135 will improve error reporting (in particular in the case of an invalid redirect). |
Thansk for the report |
* Improve messaging of client metadata loading errors Fixes #3096 * Support parsing of more fetch() errors
Hi there 👋🏼
Describe the bug
In prod OAuth fails for me with the following (it works in dev):
To Reproduce
This is my OAuth config:
Hope I gave enough info, please let me know if not!
The text was updated successfully, but these errors were encountered: