Select Git revision
displays.ts
oauth2.ts 2.04 KiB
import { SvelteKitAuth } from "sk-auth"
import { OAuth2Provider } from "sk-auth/providers"
import config from "$lib/server/config"
import type { User } from "$lib/users"
type Profile = User
interface Tokens {
access_token: string
expires_in: number
id_token: string
"not-before-policy"?: number
refresh_expires_in?: number
refresh_token?: string
session_state?: string
scope: string // "openid email profile"
token_type: string // "Bearer"
}
const { baseUrl, oauth2 } = config
export const oauth2Authenticator =
oauth2 === undefined
? undefined
: new SvelteKitAuth({
basePath: "/authentication",
// callbacks: {
// jwt(token, profile) {
// if (profile?.provider) {
// const { provider, ...account } = profile;
// token = {
// ...token,
// user: {
// ...(token.user ?? {}),
// connections: { ...(token.user?.connections ?? {}), [provider]: account },
// },
// };
// }
// return token;
// },
// },
host: new URL(baseUrl).host,
jwtSecret: oauth2.jwtSecret,
protocol: new URL(baseUrl).protocol.replace(/:$/, ""),
providers: [
new OAuth2Provider<Profile, Tokens>({
accessTokenUrl: oauth2.accessTokenUrl,
// authorizationParams?: any;
authorizationUrl: oauth2.authorizationUrl,
clientId: oauth2.clientId,
clientSecret: oauth2.clientSecret,
// contentType: "application/json",
contentType: "application/x-www-form-urlencoded",
// grantType: "authorization_code",
// headers?: any;
id: "leximpact",
// params: any;
profileUrl: oauth2.profileUrl,
// responseType: "code",
scope: ["openid", "profile", "email"],
profile(profile) {
return { ...profile, provider: "leximpact" }
},
}),
],
})