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

fix(core): update roleNames to role_names to resolve 401 errors

This commit is contained in:
Charles Zhao 2022-06-02 11:56:49 +08:00
parent a0d562f7f2
commit 5a1fa14a98
No known key found for this signature in database
GPG key ID: 4858774754C92DF2
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'; import koaAuth, { WithAuthContext } from './koa-auth';
jest.mock('jose', () => ({ jest.mock('jose', () => ({
jwtVerify: jest.fn(() => ({ payload: { sub: 'fooUser', roleNames: ['admin'] } })), jwtVerify: jest.fn(() => ({ payload: { sub: 'fooUser', role_names: ['admin'] } })),
})); }));
describe('koaAuth middleware', () => { describe('koaAuth middleware', () => {
@ -81,7 +81,7 @@ describe('koaAuth middleware', () => {
await expect(koaAuth()(ctx, next)).rejects.toMatchError(unauthorizedError); 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; const mockJwtVerify = jwtVerify as jest.Mock;
mockJwtVerify.mockImplementationOnce(() => ({ payload: { sub: 'fooUser' } })); mockJwtVerify.mockImplementationOnce(() => ({ payload: { sub: 'fooUser' } }));
@ -95,10 +95,10 @@ describe('koaAuth middleware', () => {
await expect(koaAuth()(ctx, next)).rejects.toMatchError(unauthorizedError); 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; const mockJwtVerify = jwtVerify as jest.Mock;
mockJwtVerify.mockImplementationOnce(() => ({ mockJwtVerify.mockImplementationOnce(() => ({
payload: { sub: 'fooUser', roleNames: ['foo'] }, payload: { sub: 'fooUser', role_names: ['foo'] },
})); }));
ctx.request = { ctx.request = {

View file

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