0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

Merge pull request #1026 from logto-io/charles-log-2841-update-role-names-prop-name

fix(core): update roleNames to role_names to resolve 401 errors
This commit is contained in:
Charles Zhao 2022-06-02 12:16:04 +08:00 committed by GitHub
commit df934c2daf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -9,7 +9,7 @@ import { createContextWithRouteParameters } from '@/utils/test-utils';
import koaAuth, { WithAuthContext } from './koa-auth';
jest.mock('jose', () => ({
jwtVerify: jest.fn(() => ({ payload: { sub: 'fooUser', roleNames: ['admin'] } })),
jwtVerify: jest.fn(() => ({ payload: { sub: 'fooUser', role_names: ['admin'] } })),
}));
describe('koaAuth middleware', () => {
@ -81,7 +81,7 @@ describe('koaAuth middleware', () => {
await expect(koaAuth()(ctx, next)).rejects.toMatchError(unauthorizedError);
});
it('expect to throw if jwt roleNames is missing', async () => {
it('expect to throw if jwt role_names is missing', async () => {
const mockJwtVerify = jwtVerify as jest.Mock;
mockJwtVerify.mockImplementationOnce(() => ({ payload: { sub: 'fooUser' } }));
@ -95,10 +95,10 @@ describe('koaAuth middleware', () => {
await expect(koaAuth()(ctx, next)).rejects.toMatchError(unauthorizedError);
});
it('expect to throw if jwt roleNames does not include admin', async () => {
it('expect to throw if jwt role_names does not include admin', async () => {
const mockJwtVerify = jwtVerify as jest.Mock;
mockJwtVerify.mockImplementationOnce(() => ({
payload: { sub: 'fooUser', roleNames: ['foo'] },
payload: { sub: 'fooUser', role_names: ['foo'] },
}));
ctx.request = {

View file

@ -41,7 +41,7 @@ const getUserInfoFromRequest = async (request: Request) => {
const { publicKey, issuer } = oidc;
const {
payload: { sub, roleNames },
payload: { sub, role_names: roleNames },
} = await jwtVerify(extractBearerTokenFromHeaders(request.headers), publicKey, {
issuer,
audience: managementApiResource,