[GH-ISSUE #490] [Social] Issue signin with apple #8293

Closed
opened 2026-04-13 03:22:08 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @emroot on GitHub (Nov 10, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/490

When I try to sign in with apple, I keep getting the following error:

response_mode must be form_post when name or email scope is requested.
image this the authorization url:
https://appleid.apple.com/auth/authorize?client_id=XXX&response_type=code&redirect_uri=https://local.api.ambrosia.events/api/auth/callback/apple&scope=email%20name%20openid&state=XXX```

When I append `&response_mode=form_post` to the url manually, the error is no more. But then it fails on the callback url.

<img width="1343" alt="image" src="https://github.com/user-attachments/assets/654811e1-f9b0-44e8-afcb-ea7a40195092">
Originally created by @emroot on GitHub (Nov 10, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/490 When I try to sign in with apple, I keep getting the following error: ```invalid_request response_mode must be form_post when name or email scope is requested. ``` <img width="1343" alt="image" src="https://github.com/user-attachments/assets/bc79bdcf-c1ee-48c8-baca-9c523358a2ea"> this the authorization url: ``` https://appleid.apple.com/auth/authorize?client_id=XXX&response_type=code&redirect_uri=https://local.api.ambrosia.events/api/auth/callback/apple&scope=email%20name%20openid&state=XXX``` When I append `&response_mode=form_post` to the url manually, the error is no more. But then it fails on the callback url. <img width="1343" alt="image" src="https://github.com/user-attachments/assets/654811e1-f9b0-44e8-afcb-ea7a40195092">
GiteaMirror added the locked label 2026-04-13 03:22:08 -05:00
Author
Owner

@Bekacru commented on GitHub (Nov 11, 2024):

Hey could you please check if v0.8.2-beta.2 resolves the issues?

<!-- gh-comment-id:2467319887 --> @Bekacru commented on GitHub (Nov 11, 2024): Hey could you please check if `v0.8.2-beta.2` resolves the issues?
Author
Owner

@emroot commented on GitHub (Nov 11, 2024):

Not working. You wanna add response_mode=form_post and keep response_type=code, or change it to response_type=code id_token

https://developer.apple.com/documentation/sign_in_with_apple/request_an_authorization_to_the_sign_in_with_apple_server

image

but again even after changing it manually on my end, I keep getting
image

<!-- gh-comment-id:2468726438 --> @emroot commented on GitHub (Nov 11, 2024): Not working. You wanna add `response_mode=form_post` and keep `response_type=code`, or change it to `response_type=code id_token` https://developer.apple.com/documentation/sign_in_with_apple/request_an_authorization_to_the_sign_in_with_apple_server <img width="1343" alt="image" src="https://github.com/user-attachments/assets/364f6318-c323-4855-a73e-63a6b36df916"> but again even after changing it manually on my end, I keep getting <img width="1343" alt="image" src="https://github.com/user-attachments/assets/13d1cecd-9391-489c-a6c2-3a47f7ad6dd7">
Author
Owner

@tensei commented on GitHub (Nov 11, 2024):

apple is sending a POST request to the callback url with a state and code

<!-- gh-comment-id:2468979444 --> @tensei commented on GitHub (Nov 11, 2024): apple is sending a POST request to the callback url with a `state` and `code`
Author
Owner

@emroot commented on GitHub (Nov 11, 2024):

changing this line to ["GET", "POST"] should do the trick I think.

<!-- gh-comment-id:2469161101 --> @emroot commented on GitHub (Nov 11, 2024): changing this [line](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/api/routes/callback.ts#L15) to `["GET", "POST"]` should do the trick I think.
Author
Owner

@emroot commented on GitHub (Nov 12, 2024):

@Bekacru I was able to move a little further on my end, and make it work.
changing callback.ts to

method: ["GET", "POST"],
		body: z.object({
			state: z.string(),
			code: z.string().optional(),
			error: z.string().optional(),
		}),

and updating any call from c.query to c.body.
But then this will break other oauth integrations.
Maybe updating better-call to add queryOrBody might solve that but I'm not sure if this the right route to go. or adding another metadata attribute that will take the body and pass it as query when post request?

<!-- gh-comment-id:2471274991 --> @emroot commented on GitHub (Nov 12, 2024): @Bekacru I was able to move a little further on my end, and make it work. changing callback.ts to ``` typescript method: ["GET", "POST"], body: z.object({ state: z.string(), code: z.string().optional(), error: z.string().optional(), }), ``` and updating any call from `c.query` to `c.body`. But then this will break other oauth integrations. Maybe updating better-call to add `queryOrBody` might solve that but I'm not sure if this the right route to go. or adding another metadata attribute that will take the body and pass it as query when post request?
Author
Owner

@Bekacru commented on GitHub (Nov 12, 2024):

Yeah, I was planning to see if there's a way to avoid the POST request (i.e., not using form_post as the response mode). But if that's necessary, we can make both the body and the query optional, and check inside the handler to make sure that at least one of them is provided.

<!-- gh-comment-id:2471286468 --> @Bekacru commented on GitHub (Nov 12, 2024): Yeah, I was planning to see if there's a way to avoid the `POST` request (i.e., not using `form_post` as the response mode). But if that's necessary, we can make both the body and the query optional, and check inside the handler to make sure that at least one of them is provided.
Author
Owner

@emroot commented on GitHub (Nov 13, 2024):

I have a PR here if that's the direction we wanna go. https://github.com/better-auth/better-auth/pull/521/

<!-- gh-comment-id:2474799671 --> @emroot commented on GitHub (Nov 13, 2024): I have a PR here if that's the direction we wanna go. https://github.com/better-auth/better-auth/pull/521/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8293