Skip to content

Commit

Permalink
Merge pull request #106 from kinde-oss/peter/access-token
Browse files Browse the repository at this point in the history
feat: raw access token and raw id token available via helpers
  • Loading branch information
kinde-engineering authored Jan 16, 2024
2 parents 5aca0de + f1ccfaa commit 944950b
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 3 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 18 additions & 1 deletion src/frontend/KindeBrowserClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
*/
Expand Down Expand Up @@ -181,6 +196,7 @@ export const useKindeBrowserClient = () => {
return {
...state,
isAuthenticated: !!state.user,
getIdTokenRaw,
getPermission,
getBooleanFlag,
getIntegerFlag,
Expand All @@ -189,6 +205,7 @@ export const useKindeBrowserClient = () => {
getClaim,
getAccessToken,
getToken,
getAccessTokenRaw,
getIdToken,
getOrganization,
getPermissions,
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export const setup = async (routerClient) => {
return routerClient.json({
accessToken,
accessTokenEncoded,
accessTokenRaw: accessTokenEncoded,
idToken,
idTokenRaw: idTokenEncoded,
idTokenEncoded,
user,
permissions: {
permissions,
Expand Down
18 changes: 18 additions & 0 deletions src/session/getAccessTokenRaw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {sessionManager} from './sessionManager';

/**
* @callback getAccessTokenRaw
* @returns {Promise<string>}
*/

/**
*
* @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');
};
18 changes: 18 additions & 0 deletions src/session/getIdTokenRaw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {sessionManager} from './sessionManager';

/**
* @callback getIdTokenRaw
* @returns {Promise<string>}
*/

/**
*
* @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');
};
4 changes: 4 additions & 0 deletions src/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
*
Expand All @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,21 @@ 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;
permissions: KindePermissions;
user: KindeUser | null;
userOrganizations: KindeOrganizations;
getAccessToken: () => KindeAccessToken | null;
getAccessTokenRaw: () => string | null;
getIdTokenRaw: () => string | null;
getBooleanFlag: (
code: string,
defaultValue: boolean
Expand Down

0 comments on commit 944950b

Please sign in to comment.