From 5b34a9f67e8287359976c8ce69841c640d4ed5fc Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Fri, 5 Jan 2024 11:57:03 +1100 Subject: [PATCH 1/3] feat: raw access token and raw id token available via helpers --- src/frontend/KindeBrowserClient.js | 19 ++++++++++++++++++- src/handlers/setup.js | 3 +++ src/session/getAccessTokenRaw.js | 18 ++++++++++++++++++ src/session/getIdTokenRaw.js | 18 ++++++++++++++++++ src/session/index.js | 4 ++++ types.d.ts | 6 ++++++ 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/session/getAccessTokenRaw.js create mode 100644 src/session/getIdTokenRaw.js diff --git a/src/frontend/KindeBrowserClient.js b/src/frontend/KindeBrowserClient.js index 41a511e..0586258 100644 --- a/src/frontend/KindeBrowserClient.js +++ b/src/frontend/KindeBrowserClient.js @@ -8,10 +8,11 @@ import {flagDataTypeMap} from './AuthProvider.jsx'; export const useKindeBrowserClient = () => { const [state, setState] = useState({ accessToken: null, - accessTokenEncoded: null, + accessTokenRaw: null, error: null, featureFlags: [], idToken: null, + idTokenRaw: null, isAuthenticated: false, isLoading: true, organization: null, @@ -142,6 +143,20 @@ export const useKindeBrowserClient = () => { const getToken = () => { return state.accessTokenEncoded; }; + + /** + * @returns {string | null} + */ + const getAccessTokenRaw = () => { + return state.accessTokenEncoded; + }; + + /** + * @returns {string | null} + */ + const getIdTokenRaw = () => { + return state.idTokenRaw; + }; /** * @returns {import('../../types.js').KindeIdToken | null} */ @@ -181,6 +196,7 @@ export const useKindeBrowserClient = () => { return { ...state, isAuthenticated: !!state.user, + getIdTokenRaw, getPermission, getBooleanFlag, getIntegerFlag, @@ -189,6 +205,7 @@ export const useKindeBrowserClient = () => { getClaim, getAccessToken, getToken, + getAccessTokenRaw, getIdToken, getOrganization, getPermissions, diff --git a/src/handlers/setup.js b/src/handlers/setup.js index f24b1b1..4625e1c 100644 --- a/src/handlers/setup.js +++ b/src/handlers/setup.js @@ -45,7 +45,10 @@ export const setup = async (routerClient) => { return routerClient.json({ accessToken, accessTokenEncoded, + accessTokenRaw: accessTokenEncoded, idToken, + idTokenRaw: idTokenEncoded, + idTokenEncoded, user, permissions: { permissions, diff --git a/src/session/getAccessTokenRaw.js b/src/session/getAccessTokenRaw.js new file mode 100644 index 0000000..df18a76 --- /dev/null +++ b/src/session/getAccessTokenRaw.js @@ -0,0 +1,18 @@ +import {sessionManager} from './sessionManager'; + +/** + * @callback getAccessTokenRaw + * @returns {Promise} + */ + +/** + * + * @param {import('next').NextApiRequest} [req] + * @param {import('next').NextApiResponse} [res] + * + * @returns {getAccessTokenRaw} + */ +// @ts-ignore +export const getAccessTokenRawFactory = (req, res) => async () => { + return await sessionManager(req, res).getSessionItem('access_token'); +}; diff --git a/src/session/getIdTokenRaw.js b/src/session/getIdTokenRaw.js new file mode 100644 index 0000000..cbc0600 --- /dev/null +++ b/src/session/getIdTokenRaw.js @@ -0,0 +1,18 @@ +import {sessionManager} from './sessionManager'; + +/** + * @callback getIdTokenRaw + * @returns {Promise} + */ + +/** + * + * @param {import('next').NextApiRequest} [req] + * @param {import('next').NextApiResponse} [res] + * @returns {getIdTokenRaw} + */ + +// @ts-ignore +export const getIdTokenRawFactory = (req, res) => async () => { + return await sessionManager(req, res).getSessionItem('id_token'); +}; diff --git a/src/session/index.js b/src/session/index.js index 73993ad..dff93f9 100644 --- a/src/session/index.js +++ b/src/session/index.js @@ -10,6 +10,8 @@ import {getStringFlagFactory} from './getStringFlag'; import {getUserFactory} from './getUser'; import {getUserOrganizationsFactory} from './getUserOrganizations'; import {isAuthenticatedFactory} from './isAuthenticated'; +import {getAccessTokenRawFactory} from './getAccessTokenRaw'; +import {getIdTokenRawFactory} from './getIdTokenRaw'; /** * @@ -23,6 +25,8 @@ export default function (req, res) { getBooleanFlag: getBooleanFlagFactory(req, res), getFlag: getFlagFactory(req, res), getIdToken: getIdTokenFactory(req, res), + getIdTokenRaw: getIdTokenRawFactory(req, res), + getAccessTokenRaw: getAccessTokenRawFactory(req, res), getIntegerFlag: getIntegerFlagFactory(req, res), getOrganization: getOrganizationFactory(req, res), getPermission: getPermissionFactory(req, res), diff --git a/types.d.ts b/types.d.ts index de407a5..f37c831 100644 --- a/types.d.ts +++ b/types.d.ts @@ -159,8 +159,12 @@ export type KindeClient = { export type KindeState = { accessToken: KindeAccessToken | null; + accessTokenEncoded: string | null; + accessTokenRaw: string | null; error?: string | null; idToken: KindeIdToken | null; + idTokenRaw: string | null; + idTokenEncoded: string | null; isAuthenticated: boolean | null; isLoading: boolean | null; organization: KindeOrganization; @@ -168,6 +172,8 @@ export type KindeState = { user: KindeUser | null; userOrganizations: KindeOrganizations; getAccessToken: () => KindeAccessToken | null; + getAccessTokenRaw: () => string | null; + getIdTokenRaw: () => string | null; getBooleanFlag: ( code: string, defaultValue: boolean From 83e21ed8d747d80c58bf8318291fc4eeb9501b92 Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Fri, 5 Jan 2024 12:01:25 +1100 Subject: [PATCH 2/3] chore(release): v2.1.0 --- CHANGELOG.md | 21 +++++++++++++++++++++ package.json | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3152472..0dd2440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,27 @@ # Changelog +## v2.1.0 + +[compare changes](https://github.com/kinde-oss/kinde-auth-nextjs/compare/v2.0.12...v2.1.0) + +### 🚀 Enhancements + +- Cookie domain ([2dad216](https://github.com/kinde-oss/kinde-auth-nextjs/commit/2dad216)) +- Raw access token and raw id token available via helpers ([5b34a9f](https://github.com/kinde-oss/kinde-auth-nextjs/commit/5b34a9f)) + +### 🩹 Fixes + +- Remove payload cookies ([a7838a9](https://github.com/kinde-oss/kinde-auth-nextjs/commit/a7838a9)) + +### 🏡 Chore + +- Version bump ([7efd078](https://github.com/kinde-oss/kinde-auth-nextjs/commit/7efd078)) + +### ❤️ Contributors + +- Peter Phanouvong ([@peterphanouvong](http://github.com/peterphanouvong)) + ## v2.0.0 [compare changes](https://github.com/kinde-oss/kinde-auth-nextjs/compare/v2.0.0-alpha.2...v2.0.0) diff --git a/package.json b/package.json index 6ccb4ee..06e59dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kinde-oss/kinde-auth-nextjs", - "version": "2.0.12", + "version": "2.1.0", "description": "Kinde Auth SDK for NextJS", "main": "dist/cjs/index.js", "module": "dist/index.js", @@ -67,4 +67,4 @@ "middleware", "types.d.ts" ] -} +} \ No newline at end of file From f1ccfaa27db4228940185022c302d5883422285c Mon Sep 17 00:00:00 2001 From: Peter Phanouvong Date: Wed, 17 Jan 2024 09:17:20 +1100 Subject: [PATCH 3/3] chore(release): v2.1.3 --- CHANGELOG.md | 19 +++++++++++++++++++ package.json | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faefdf9..6d1491f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## v2.1.3 + +[compare changes](https://github.com/kinde-oss/kinde-auth-nextjs/compare/v2.1.2...v2.1.3) + +### 🚀 Enhancements + +- Raw access token and raw id token available via helpers ([5b34a9f](https://github.com/kinde-oss/kinde-auth-nextjs/commit/5b34a9f)) +- Programmatically define kinde management api audience ([a8519e8](https://github.com/kinde-oss/kinde-auth-nextjs/commit/a8519e8)) + +### 🏡 Chore + +- **release:** V2.1.0 ([83e21ed](https://github.com/kinde-oss/kinde-auth-nextjs/commit/83e21ed)) +- **release:** V2.0.13 ([1261b3b](https://github.com/kinde-oss/kinde-auth-nextjs/commit/1261b3b)) +- **release:** V2.1.1 ([2f9685f](https://github.com/kinde-oss/kinde-auth-nextjs/commit/2f9685f)) + +### ❤️ Contributors + +- Peter Phanouvong ([@peterphanouvong](http://github.com/peterphanouvong)) + ## v2.1.2 [compare changes](https://github.com/kinde-oss/kinde-auth-nextjs/compare/v2.1.0...v2.1.2) diff --git a/package.json b/package.json index 1f55c60..894075d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kinde-oss/kinde-auth-nextjs", - "version": "2.1.2", + "version": "2.1.3", "description": "Kinde Auth SDK for NextJS", "main": "dist/cjs/index.js", "module": "dist/index.js", @@ -67,4 +67,4 @@ "middleware", "types.d.ts" ] -} +} \ No newline at end of file