diff --git a/CHANGELOG.md b/CHANGELOG.md index 436ad40..6d1491f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # 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 @@ -33,4 +51,3 @@ ## 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 38315a9..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", 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