diff --git a/.changeset/kakao-profile-types.md b/.changeset/kakao-profile-types.md index 2d9770a86b..69c7a63190 100644 --- a/.changeset/kakao-profile-types.md +++ b/.changeset/kakao-profile-types.md @@ -2,4 +2,4 @@ "@better-auth/core": minor --- -Kakao profile callbacks now accept responses without account information. Profile mappings must handle an omitted `kakao_account`. +Kakao profile mappings now accept profiles without account information. Authorization requests separate consent scopes with commas as documented by Kakao. diff --git a/packages/core/src/social-providers/kakao.test.ts b/packages/core/src/social-providers/kakao.test.ts index 1f84ff038a..61c5e882c5 100644 --- a/packages/core/src/social-providers/kakao.test.ts +++ b/packages/core/src/social-providers/kakao.test.ts @@ -1,4 +1,4 @@ -import { assertType, it } from "vitest"; +import { assertType, expect, it } from "vitest"; import type { KakaoProfile } from "./kakao"; /** @@ -7,3 +7,29 @@ import type { KakaoProfile } from "./kakao"; it("accepts a Kakao profile without account information", () => { assertType({ id: 123 }); }); + +import { kakao } from "./kakao"; + +/** @see https://developers.kakao.com/docs/ko/kakaologin/rest-api#req-auth-code */ +it("joins authorization scopes with commas", async () => { + const provider = kakao({ clientId: "app", scope: ["openid"] }); + const url = await provider.createAuthorizationURL({ + state: "state", + redirectURI: "https://example.com/callback", + codeVerifier: "", + scopes: ["gender"], + }); + expect(url.searchParams.get("scope")).toBe( + "account_email,profile_image,profile_nickname,openid,gender", + ); + const custom = await kakao({ + clientId: "app", + disableDefaultScope: true, + scope: ["account_email", "gender"], + }).createAuthorizationURL({ + state: "state", + redirectURI: "https://example.com/callback", + codeVerifier: "", + }); + expect(custom.searchParams.get("scope")).toBe("account_email,gender"); +}); diff --git a/packages/core/src/social-providers/kakao.ts b/packages/core/src/social-providers/kakao.ts index 41c762d9c1..d09447dd10 100644 --- a/packages/core/src/social-providers/kakao.ts +++ b/packages/core/src/social-providers/kakao.ts @@ -118,6 +118,7 @@ export const kakao = (options: KakaoOptions) => { options, authorizationEndpoint: "https://kauth.kakao.com/oauth/authorize", scopes: _scopes, + scopeJoiner: ",", state, redirectURI, additionalParams,