2024-11-24 17:22:28 +00:00
|
|
|
import { AuthOptions } from "next-auth";
|
|
|
|
|
|
|
|
export const authOptions: AuthOptions = {
|
|
|
|
providers: [
|
2024-12-10 23:41:55 +00:00
|
|
|
{
|
|
|
|
id: "oauth2",
|
|
|
|
name: "oauth2",
|
|
|
|
type: "oauth",
|
|
|
|
clientId: process.env.OAUTH_CLIENT_ID,
|
|
|
|
clientSecret: process.env.OAUTH_CLIENT_SECRET,
|
|
|
|
authorization: {
|
|
|
|
url: process.env.OAUTH_AUTHORIZATION_URL,
|
|
|
|
params: {
|
|
|
|
scope: "openid email profile",
|
|
|
|
response_type: "code",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
token: process.env.OAUTH_TOKEN_URL,
|
|
|
|
userinfo: process.env.OAUTH_USERINFO_URL,
|
|
|
|
issuer: process.env.OAUTH_ISSUER,
|
|
|
|
jwks_endpoint: process.env.OAUTH_JWKS_ENDPOINT,
|
|
|
|
profile(profile) {
|
|
|
|
return {
|
|
|
|
id: profile.sub || profile.id,
|
|
|
|
name:
|
|
|
|
profile.name ||
|
|
|
|
`${profile.given_name} ${profile.family_name}`,
|
|
|
|
email: profile.email,
|
|
|
|
image: profile.picture || null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2024-11-24 17:22:28 +00:00
|
|
|
],
|
|
|
|
session: {
|
|
|
|
strategy: "jwt",
|
|
|
|
},
|
|
|
|
callbacks: {
|
|
|
|
async jwt({ token, account, user }) {
|
|
|
|
if (account) {
|
2024-12-10 23:41:55 +00:00
|
|
|
token.accessToken = account.access_token;
|
|
|
|
token.refreshToken = account.refresh_token;
|
|
|
|
token.expiresAt = Date.now() + account.expires_in * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
token.userId = user.id;
|
2024-11-24 17:22:28 +00:00
|
|
|
}
|
2024-12-10 23:41:55 +00:00
|
|
|
|
2024-11-24 17:22:28 +00:00
|
|
|
return token;
|
|
|
|
},
|
|
|
|
async session({ session, token }) {
|
2024-12-10 23:41:55 +00:00
|
|
|
if (token) {
|
|
|
|
session.user.id = token.userId;
|
|
|
|
session.accessToken = token.accessToken;
|
|
|
|
session.refreshToken = token.refreshToken;
|
|
|
|
session.expiresAt = token.expiresAt;
|
|
|
|
}
|
|
|
|
|
2024-11-24 17:22:28 +00:00
|
|
|
return session;
|
|
|
|
},
|
|
|
|
},
|
2024-12-10 23:41:55 +00:00
|
|
|
};
|