Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: KINDE_SCOPE + getUser upgrades #186

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const KINDE_AUDIENCE = process.env.KINDE_AUDIENCE;
const KINDE_COOKIE_DOMAIN = removeTrailingSlash(
process.env.KINDE_COOKIE_DOMAIN
);
const KINDE_SCOPE = process.env.KINDE_SCOPE || 'openid profile email offline';

const isDebugMode = process.env.KINDE_DEBUG_MODE === 'true';

Expand All @@ -71,7 +72,6 @@ export const config = {
audience: KINDE_AUDIENCE,
cookieDomain: KINDE_COOKIE_DOMAIN,
responseType: 'code',
scope: 'openid profile email offline',
codeChallengeMethod: 'S256',
redirectRoutes: {
callback: `${KINDE_AUTH_API_PATH}/kinde_callback`
Expand All @@ -91,7 +91,8 @@ export const config = {
logoutRedirectURL: KINDE_POST_LOGOUT_REDIRECT_URL || '',
redirectURL: `${KINDE_SITE_URL}/api/auth/kinde_callback`,
frameworkVersion: version,
framework: 'Next.js'
framework: 'Next.js',
scope: KINDE_SCOPE
},
grantType: GrantType.AUTHORIZATION_CODE
};
5 changes: 3 additions & 2 deletions src/routerClients/AppRouterClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class AppRouterClient extends RouterClient {
*
* @param {NextRequest} req
* @param {*} res
* @param {{onError?: () => void; config: {audience?: string | string[], clientId?: string, clientSecret?: string, issuerURL?: string, siteUrl?: string, postLoginRedirectUrl?: string, postLogoutRedirectUrl?: string}}} options
* @param {{onError?: () => void; config: {audience?: string | string[], clientId?: string, clientSecret?: string, issuerURL?: string, siteUrl?: string, postLoginRedirectUrl?: string, postLogoutRedirectUrl?: string, scope?: string}}} options
*/
constructor(req, res, options) {
super();
Expand All @@ -28,7 +28,8 @@ export default class AppRouterClient extends RouterClient {
redirectURL: options?.config?.siteUrl
? `${options?.config?.siteUrl}/api/auth/kinde_callback`
: config.clientOptions.redirectURL,
siteUrl: config.redirectURL || options.config.siteUrl
siteUrl: config.redirectURL || options.config.siteUrl,
scope: options?.config?.scope || config.clientOptions.scope
};
this.kindeClient = createKindeServerClient(
config.grantType,
Expand Down
2 changes: 1 addition & 1 deletion src/routerClients/PagesRouterClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class PagesRouterClient extends RouterClient {
*
* @param {import('next').NextApiRequest} req
* @param {import('next').NextApiResponse} res
* @param {{onError?: () => void; config: {audience?: string | string[], clientId?: string, clientSecret?: string, issuerURL?: string, siteUrl?: string, postLoginRedirectUrl?: string, postLogoutRedirectUrl?: string}}} options
* @param {{onError?: () => void; config: {audience?: string | string[], clientId?: string, clientSecret?: string, issuerURL?: string, siteUrl?: string, postLoginRedirectUrl?: string, postLogoutRedirectUrl?: string, scope?: string}}} options
*/
constructor(req, res, options) {
super();
Expand Down
12 changes: 12 additions & 0 deletions src/session/getUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ export const getUserFactory = (req, res) => async () => {
sessionManager(req, res),
'user_properties'
);
const phone_number = await kindeClient.getClaimValue(
sessionManager(req, res),
'phone_number',
'id_token'
);
const username = await kindeClient.getClaimValue(
sessionManager(req, res),
'preferred_username',
'id_token'
);
return {
...user,
phone_number,
username,
properties: {
city: userProperties?.kp_usr_city?.v,
industry: userProperties?.kp_usr_industry?.v,
Expand Down
2 changes: 2 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export type KindeUser = {
given_name: string | null;
family_name: string | null;
picture: string | null;
username?: string | null;
phone_number?: string | null;
properties?: {
usr_city?: string;
usr_industry?: string;
Expand Down