Skip to content

Commit

Permalink
Merge pull request #186 from kinde-oss/peter/feat/phone-scope
Browse files Browse the repository at this point in the history
feat: KINDE_SCOPE + getUser upgrades
  • Loading branch information
peterphanouvong authored Jul 8, 2024
2 parents 10071b7 + 074855b commit 410cb6d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
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

0 comments on commit 410cb6d

Please sign in to comment.