Skip to content

Commit b58c977

Browse files
fix: strip code_verifier from request body when the provider doesn't support PKCE (#10765)
* fix: strip `code_verifier` when provider does not support it * drop `PKCE` check for LinkedIn * add LinkedIn to dev app * drop session callback from dev app * drop default profile * fix: nextjs dev app fallback avatar URL --------- Co-authored-by: ndom91 <[email protected]>
1 parent 5d9a1ce commit b58c977

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

apps/dev/nextjs/auth.config.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Google from "next-auth/providers/google"
55
import Facebook from "next-auth/providers/facebook"
66
import Twitter from "next-auth/providers/twitter"
77
import Keycloak from "next-auth/providers/keycloak"
8+
import LinkedIn from "next-auth/providers/linkedin"
89

910
declare module "next-auth" {
1011
/**
@@ -41,20 +42,13 @@ export default {
4142
Keycloak,
4243
Facebook,
4344
Twitter,
45+
LinkedIn,
4446
].filter(Boolean) as NextAuthConfig["providers"],
4547
callbacks: {
4648
jwt({ token, trigger, session }) {
4749
if (trigger === "update") token.name = session.user.name
4850
return token
4951
},
50-
async session({ session, token }) {
51-
return {
52-
...session,
53-
user: {
54-
...token,
55-
},
56-
}
57-
},
5852
},
5953
basePath: "/auth",
6054
} satisfies NextAuthConfig

apps/dev/nextjs/components/header.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export function Header({
1616
<div className={styles.signedInStatus}>
1717
<img
1818
src={
19-
session?.user?.image ?? "https://source.boringavatars.com/beam/120"
19+
session?.user?.image ??
20+
"https://source.boringavatars.com/marble/120"
2021
}
2122
className={styles.avatar}
2223
/>

packages/core/src/lib/actions/callback/oauth/callback.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,18 @@ export async function handleOAuth(
109109
client,
110110
codeGrantParams,
111111
redirect_uri,
112-
codeVerifier ?? "auth" // TODO: review fallback code verifier
112+
codeVerifier ?? "auth", // TODO: review fallback code verifier,
113+
{
114+
[o.experimental_customFetch]: (...args) => {
115+
if (
116+
!provider.checks.includes("pkce") &&
117+
args[1]?.body instanceof URLSearchParams
118+
) {
119+
args[1].body.delete("code_verifier")
120+
}
121+
return fetch(...args)
122+
},
123+
}
113124
)
114125

115126
if (provider.token?.conform) {

packages/core/src/providers/linkedin.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,8 @@ export default function LinkedIn<P extends LinkedInProfile>(
7979
type: "oidc",
8080
client: { token_endpoint_auth_method: "client_secret_post" },
8181
issuer: "https://www.linkedin.com/oauth",
82-
async profile(profile) {
83-
return {
84-
id: profile.sub,
85-
name: profile.name,
86-
email: profile.email,
87-
image: profile.picture,
88-
}
89-
},
9082
style: { bg: "#069", text: "#fff" },
83+
checks: ["state"],
9184
options,
9285
}
9386
}

0 commit comments

Comments
 (0)