burnstony#1975
burnstony#19756mo ago

Convex Auth Apple

got github and google working in dev in prod. make sure using at least @convex-dev/auth@0.0.39 Now trying to get Apple working. It's super confusing, but with the help of this article https://medium.com/identity-beyond-borders/how-to-configure-sign-in-with-apple-77c61e336003, I believe I know have the right AUTH_APPLE_ID (client_id) and AUTH_APPLE_SECRET (client_secret) Now I get the following error invalid_request invalid client scope
Medium
No description
71 Replies
Michal Srb
Michal Srb6mo ago
This is what I got as well. Unfortunately to my understanding that's a generic error message that can happen for any number of reasons.
burnstony#1975
burnstony#1975OP6mo ago
is there a way to log exactly the call to Apple does convex auth send any query params, or payload?
Michal Srb
Michal Srb6mo ago
You can see all the arguments in the Network tab, since the communication is done via a server redirect. Your convex backend replies with Location header, which your browser uses to redirect. In case of RN I'm not sure how to see the Network logs actually for the in-app browser.
burnstony#1975
burnstony#1975OP6mo ago
you get the same error on the web. Is it a problem related to Website URLs Provide your web domain and return URLs that will support Sign in with Apple. Your website must support TLS 1.2 or higher. All Return URLs must be registered with the https:// protocol included in the URI string. After registering new website URLs, confirm the list you’d like to add to this Services ID and click Done. To complete the process, click Continue, then click Save. I notice that Clerk uses a callback url that uses my domain, while Convex uses its own url
Michal Srb
Michal Srb6mo ago
Yeah, but presumably you can register the Convex backend URL as well? Otherwise we might need to figure out a way to proxy the OAuth flow through your hosting server - or you could drive the OAuth flow from the in-app browser and at the end exchange the credentials.
burnstony#1975
burnstony#1975OP6mo ago
for github and google it doesn't seem to matter at all from RN Has anyone got Apple log in working with convex auth?
burnstony#1975
burnstony#1975OP6mo ago
No description
burnstony#1975
burnstony#1975OP6mo ago
I added these but, but still error this comment seems possible The scope query parameter supports the following values for Sign in with Apple: name email https://forums.developer.apple.com/forums/thread/690097 @Michal Srb is scope being sent with the first call to Apple @Michal Srb Has anyone got Apple log in working with convex auth?
burnstony#1975
burnstony#1975OP6mo ago
https://developer.apple.com/documentation/technotes/tn3107-resolving-sign-in-with-apple-response-errors?changes=_7 invalid_scope | The requested scope is invalid. | Make sure the request is correct, and that the provided scope is supported, etc.
Apple Developer Documentation
TN3107: Resolving Sign in with Apple response errors | Apple Develo...
Diagnose errors received by the Sign in with Apple client, or its server infrastructure, by identifying the underlying causes of common error codes and explore their potential solutions.
Michal Srb
Michal Srb6mo ago
I think it might be set to openid profile email , I'll check
burnstony#1975
burnstony#1975OP6mo ago
is there a way to override that? Or just to see a log statement to confirm @Michal Srb does the apple oauth with convex auth work for anyone?
burnstony#1975
burnstony#1975OP6mo ago
'): OAuthConfig<P> { return { id: "apple", name: "Apple", type: "oidc", issuer: "https://appleid.apple.com", authorization: { params: { scope: "name email", response_mode: "form_post" }, },'
ian
ian6mo ago
I haven't personally heard of anyone using Apple yet, or done it myself (yet). So please report back with your experience if you get it working
burnstony#1975
burnstony#1975OP6mo ago
No luck so far and I can’t figure out how to see exactly what the call to Apple is. I currently only have this in react native and I don’t see the call in the networking tab of the Java script console I’m pretty sure Apple is rejecting that first call
ian
ian6mo ago
To debug whether it's a bug with Auth.js or Convex Auth, you could make a dummy project using our Auth.js adapter (or the Apple provider with any Auth.js project): https://stack.convex.dev/nextauth
Stack
Convex with Auth.js (NextAuth)
Learn how to use Auth.js with your Next.js server and Convex backend to build a full-featured authentication system.
Tiger 🐅
Tiger 🐅6mo ago
thank fucking god i didnt try apple auth i was so close to lol
burnstony#1975
burnstony#1975OP6mo ago
I’d like to first just log what the call to Apple is but I’m unsure how to
Michal Srb
Michal Srb6mo ago
@burnstony#1975 sorry, I'm working on something else, if you want to debug yourself you can: 1. Edit node_modules/@convex-dev/auth/dist/server/implementation.js 2. On line 360 add console.log("Sent to apple", redirect); 3. Deploy (have npx convex dev running) 4. Observe the logs on your Convex dashboard This will show you the URL that's used to open the Apple OAuth page (the URL params are all the arguments provided to Apple).
burnstony#1975
burnstony#1975OP6mo ago
Awesome Jul 24, 09:31:54 H GET /api/auth/signin/apple log 'Sent to apple' 'https://appleid.apple.com/auth/authorize?response_type=code&client_id=com.everwhz.service&redirect_uri=https%3A%2F%2Fdoting-bee-40.convex.site%2Fapi%2Fauth%2Fcallback%2Fapple&nonce=kSpty8sYh1nmhBoLnyBd8V3IGgCrbSPxhNRK-t05dSo&scope=openid+profile+email'
Michal Srb
Michal Srb6mo ago
That's wrong. @burnstony#1975 can you try again with @convex-dev/auth@0.0.40. I'm hoping it fixes the scope.
Michal Srb
Michal Srb6mo ago
The URL should have scope=name+email&response_mode=form_post
Michal Srb
Michal Srb6mo ago
Is the URL failing still? Does it work when you remove response_type?
burnstony#1975
burnstony#1975OP6mo ago
No description
burnstony#1975
burnstony#1975OP6mo ago
actually thats a new error
Michal Srb
Michal Srb6mo ago
Ok, response_type has to be response_type=code+id_token Then I get a new error, invalid redirect URL But that presumably is fixable in your apple config
burnstony#1975
burnstony#1975OP6mo ago
same
No description
burnstony#1975
burnstony#1975OP6mo ago
let me look the apple configs are way confusing
Michal Srb
Michal Srb6mo ago
Way way
burnstony#1975
burnstony#1975OP6mo ago
progress
No description
burnstony#1975
burnstony#1975OP6mo ago
now it does the whole log in, but than I get this error
No description
burnstony#1975
burnstony#1975OP6mo ago
No matching routes found also same thing in PROD
Michal Srb
Michal Srb6mo ago
Awesome! What did you change to fix the redirect URL?
burnstony#1975
burnstony#1975OP6mo ago
I had done it before, but you have to hit continue a few times than save or it doesn't save it
Michal Srb
Michal Srb6mo ago
Ok so now the error is that your backend isn't handling https://doting-bee-40.convex.site/api/auth/callback/apple Do you get any logs on your dashboard? (I just tried it in my browser against your backend)
burnstony#1975
burnstony#1975OP6mo ago
Jul 24, 11:08:40 H GET /api/auth/callback/apple error [Error: pkce cookie is missing.]
Michal Srb
Michal Srb6mo ago
It's weird that it's returning 404 though
burnstony#1975
burnstony#1975OP6mo ago
if you try again I'll send all the logs thats what I thought
Michal Srb
Michal Srb6mo ago
I obviously don't have the cookie set since I'm starting from the Apple URL
burnstony#1975
burnstony#1975OP6mo ago
import { convexAuth } from "@convex-dev/auth/server"; import Google from "@auth/core/providers/google"; import GitHub from "@auth/core/providers/github"; import Apple from "@auth/core/providers/apple"; export const { auth, signIn, signOut, store } = convexAuth({ providers: [Google, GitHub, Apple], callbacks: { async redirect({ redirectTo }) { console.log('redirectTo:', redirectTo) return redirectTo; }, }, });
burnstony#1975
burnstony#1975OP6mo ago
No description
Michal Srb
Michal Srb6mo ago
Can you try: 1. Upgrade to @convex-dev/auth@0.0.41 (now the scope should be actually fixed) 2. Change auth.ts to have:
Apple({
authorization: {
params: { scope: "name email", response_mode: "form_post", response_type: "code id_token" }
}
})
Apple({
authorization: {
params: { scope: "name email", response_mode: "form_post", response_type: "code id_token" }
}
})
burnstony#1975
burnstony#1975OP6mo ago
where do I put that
Michal Srb
Michal Srb6mo ago
export const { auth, signIn, signOut, store } = convexAuth({
providers: [Google, GitHub,
Apple({
authorization: {
params: { scope: "name email", response_mode: "form_post", response_type: "code id_token" }
}
})
],
callbacks: {
async redirect({ redirectTo }) {
console.log('redirectTo:', redirectTo)
return redirectTo;
},
},
});
export const { auth, signIn, signOut, store } = convexAuth({
providers: [Google, GitHub,
Apple({
authorization: {
params: { scope: "name email", response_mode: "form_post", response_type: "code id_token" }
}
})
],
callbacks: {
async redirect({ redirectTo }) {
console.log('redirectTo:', redirectTo)
return redirectTo;
},
},
});
burnstony#1975
burnstony#1975OP6mo ago
Argument of type '{ authorization: { params: { scope: string; response_mode: string; response_type: string; }; }; }' is not assignable to parameter of type 'Omit<OAuthUserConfig<any>, "clientSecret"> & { clientSecret: string; }'. Property 'clientSecret' is missing in type '{ authorization: { params: { scope: string; response_mode: string; response_type: string; }; }; }' but required in type '{ clientSecret: string; }'.ts(2345) apple.d.ts(140, 5): 'clientSecret' is declared here. clientSecret is required import Google from "@auth/core/providers/google"; import GitHub from "@auth/core/providers/github"; import Apple from "@auth/core/providers/apple"; export const { auth, signIn, signOut, store } = convexAuth({ providers: [Google, GitHub, Apple({ authorization: { params: { scope: "name email", response_mode: "form_post", response_type: "code id_token" } }, clientSecret: "" }) ], callbacks: { async redirect({ redirectTo }) { console.log('redirectTo:', redirectTo) return redirectTo; }, }, }); that will compile at least
Michal Srb
Michal Srb6mo ago
You can ignore that type error, or set clientSecret: process.env.AUTH_APPLE_SECRET
burnstony#1975
burnstony#1975OP6mo ago
same error
Michal Srb
Michal Srb6mo ago
404? And where do you see the pkce cookie is missing error (can you screenshot) (and are you starting the whole flow, not just from the Apple URL)
burnstony#1975
burnstony#1975OP6mo ago
I think I only got the pkce error when you tried
Michal Srb
Michal Srb6mo ago
Ok. So which error are you getting now?
burnstony#1975
burnstony#1975OP6mo ago
No description
burnstony#1975
burnstony#1975OP6mo ago
did you just try something
burnstony#1975
burnstony#1975OP6mo ago
No description
Michal Srb
Michal Srb6mo ago
The later ones are me hitting your backend haha
burnstony#1975
burnstony#1975OP6mo ago
can you try with apple
Michal Srb
Michal Srb6mo ago
Do you have something else in your http.ts file besides the setup code?
burnstony#1975
burnstony#1975OP6mo ago
import { httpRouter } from "convex/server"; import { auth } from "./auth"; const http = httpRouter(); auth.addHttpRoutes(http); export default http;
Michal Srb
Michal Srb6mo ago
Baffling And I cannot repro on my backend Oh, why are they POSTing One sec
burnstony#1975
burnstony#1975OP6mo ago
good eye @Michal Srb any thoughts
Michal Srb
Michal Srb6mo ago
@convex-dev/auth@0.0.42
burnstony#1975
burnstony#1975OP6mo ago
exciting, are these new versions just for me?
Michal Srb
Michal Srb6mo ago
They're for everyone, but I'm making these fixes thanks to you! 😇
burnstony#1975
burnstony#1975OP6mo ago
No description
Michal Srb
Michal Srb6mo ago
(dm'd you on Discord as well)
burnstony#1975
burnstony#1975OP6mo ago
the response from const result = await openAuthSessionAsync(redirect!.toString(), redirectTo); is lacking the code from apple apple returned {"error": null, "type": "success", "url": "exp://192.168.1.153:8081"} google returned {"error": null, "type": "success", "url": "exp://192.168.1.153:8081/?code=21516484"}
Michal Srb
Michal Srb6mo ago
Ok, got it to work. Use @convex-dev/auth@0.0.43 And configure Apple like this:
Apple({
clientSecret: process.env.AUTH_APPLE_SECRET!,
client: {
token_endpoint_auth_method: "client_secret_post",
},
profile: undefined,
}),
Apple({
clientSecret: process.env.AUTH_APPLE_SECRET!,
client: {
token_endpoint_auth_method: "client_secret_post",
},
profile: undefined,
}),
I'll open a PR with Auth.js to fix the provider config so this config isn't needed in the future.
Michal Srb
Michal Srb6mo ago
Would appreciate a heart/thumbs up on the PR to Auth.js: https://github.com/nextauthjs/next-auth/pull/11453
GitHub
Update Apple provider config by xixixao · Pull Request #11453 · nex...
☕️ Reasoning Sing In with Apple is currently broken, but these changes bring it closer to working (and make it work in Convex Auth). Don't require clientSecret when options are provided. This ...
burnstony#1975
burnstony#1975OP5mo ago
thank you so much it works now @Michal Srb