-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into EXT-1569-preserve-modules
# Conflicts: # package.json # src/session/refreshAppSession/refreshAppSession.ts # src/storyblok-auth-api/handle-requests/handleCallback/spaceIdFromUrl.ts # src/storyblok-auth-api/refreshToken.ts # src/storyblok-auth-api/user-info/Role/index.ts # src/storyblok-auth-api/user-info/UserInfo/UserInfo.ts # src/storyblok-auth-api/user-info/UserInfo/isUserInfo.test.ts # src/storyblok-auth-api/user-info/UserInfo/isUserInfo.ts # tsconfig.json # yarn.lock
- Loading branch information
Showing
26 changed files
with
753 additions
and
1,307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,22 +34,25 @@ | |
"test": "jest" | ||
}, | ||
"engines": { | ||
"yarn": "^3.2.4" | ||
"yarn": "^3.2.4", | ||
"node": ">=14.21.3" | ||
}, | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"jsonwebtoken": "^8.5.1", | ||
"openid-client": "^5.4.2" | ||
}, | ||
"devDependencies": { | ||
"@jest-mock/express": "^1.4.5", | ||
"@rollup/plugin-commonjs": "21.0.1", | ||
"@rollup/plugin-json": "4.1.0", | ||
"@rollup/plugin-node-resolve": "13.1.3", | ||
"@rollup/plugin-typescript": "8.3.2", | ||
"@testing-library/jest-dom": "^5.16.4", | ||
"@testing-library/react": "^13.1.1", | ||
"@types/cookie": "^0.5.1", | ||
"@types/cookies": "^0.7.7", | ||
"@types/jest": "^27.4.1", | ||
"@types/jsonwebtoken": "^8.5.8", | ||
"@types/node": "18.16.10", | ||
"@types/node": "14.18.47", | ||
"@typescript-eslint/eslint-plugin": "^5.36.2", | ||
"@typescript-eslint/parser": "^5.36.2", | ||
"dotenv": "^16.0.0", | ||
|
@@ -60,26 +63,18 @@ | |
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^27.5.1", | ||
"jest-express": "^1.12.0", | ||
"jsonwebtoken": "^9.0.0", | ||
"node-mocks-http": "1.12.1", | ||
"openid-client": "^5.4.2", | ||
"prettier": "^2.7.1", | ||
"require": "^2.4.20", | ||
"rollup": "^2.78.0", | ||
"rollup-plugin-dts": "4.2.1", | ||
"rollup-plugin-peer-deps-external": "2.2.4", | ||
"rollup-plugin-rename": "^1.0.1", | ||
"rollup-plugin-summary": "^1.4.3", | ||
"rollup-plugin-typescript2": "^0.31.1", | ||
"rollup-plugin-visualizer": "^5.6.0", | ||
"ts-jest": "^27.1.4", | ||
"tsutils": "^3.21.0", | ||
"typescript": "^4.8.3", | ||
"vite": "4.2.1", | ||
"vite-plugin-dts": "1.7.1" | ||
}, | ||
"peerDependencies": { | ||
"jsonwebtoken": "^9.0.0", | ||
"node": "^18.0.0", | ||
"openid-client": "^5.4.2" | ||
"typescript": "^4.8.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
AppSessionCookiePayload, | ||
isAppSessionCookiePayload, | ||
} from './AppSessionCookiePayload' | ||
|
||
const stub: AppSessionCookiePayload = { | ||
sessions: [ | ||
{ | ||
spaceId: 123, | ||
userId: 12345, | ||
appClientId: '094uif90e', | ||
expiresAt: Date.now(), | ||
region: 'eu', | ||
accessToken: 'abctoken123', | ||
roles: ['admin'], | ||
userName: 'Johannes Lindgren', | ||
spaceName: 'My Space', | ||
refreshToken: '98rejf984ej89crejf98je', | ||
}, | ||
], | ||
} | ||
|
||
describe('isAppSessionCookiePayload', () => { | ||
describe('validation', () => { | ||
it('is an object with a property "session"', () => { | ||
expect(isAppSessionCookiePayload({})).toEqual(false) | ||
expect(isAppSessionCookiePayload(stub)).toEqual(true) | ||
}) | ||
it('The property "session" is an array', () => { | ||
expect( | ||
isAppSessionCookiePayload({ | ||
sessions: {}, | ||
}), | ||
).toEqual(false) | ||
expect(isAppSessionCookiePayload(stub)).toEqual(true) | ||
}) | ||
it('The property "session" is an array of AppSession', () => { | ||
expect( | ||
isAppSessionCookiePayload({ | ||
sessions: [], | ||
}), | ||
).toEqual(true) | ||
expect(isAppSessionCookiePayload(stub)).toEqual(true) | ||
expect( | ||
isAppSessionCookiePayload({ | ||
sessions: [{ not: 'aSession' }], | ||
}), | ||
).toEqual(false) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { hasKey } from '../../utils' | ||
import { AppSession, isAppSession } from '../types' | ||
|
||
export type AppSessionCookiePayload = { | ||
sessions: AppSession[] | ||
} | ||
|
||
export const isAppSessionCookiePayload = ( | ||
data: unknown, | ||
): data is AppSessionCookiePayload => | ||
hasKey(data, 'sessions') && | ||
Array.isArray(data.sessions) && | ||
data.sessions.every(isAppSession) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { AuthHandlerParams } from '../../storyblok-auth-api' | ||
import { AppSession } from '../types' | ||
import { getSignedCookie, GetCookie } from '../../utils' | ||
import { GetCookie, getSignedCookie } from '../../utils' | ||
import { authCookieName } from '../authCookieName' | ||
import { isAppSessionCookiePayload } from './AppSessionCookiePayload' | ||
|
||
export type AppSessionCookiePayload = | ||
| { | ||
sessions: AppSession[] | ||
} | ||
| undefined | ||
export type GetAllSessionsParams = Pick< | ||
AuthHandlerParams, | ||
'clientSecret' | 'cookieName' | 'clientId' | ||
> | ||
|
||
export type GetAllSessions = ( | ||
params: GetAllSessionsParams, | ||
getCookie: GetCookie, | ||
) => AppSession[] | ||
|
||
export const getAllSessions: GetAllSessions = (params, getCookie) => { | ||
const signedCookie = getSignedCookie( | ||
params.clientSecret, | ||
getCookie, | ||
authCookieName(params), | ||
) as AppSessionCookiePayload | ||
// TODO validate at runtime | ||
return signedCookie?.sessions ?? [] | ||
) | ||
if (!isAppSessionCookiePayload(signedCookie)) { | ||
return [] | ||
} | ||
return signedCookie.sessions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.