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

refactor(core): recognize developer id in header (#1031)

This commit is contained in:
Gao Sun 2022-06-02 16:01:33 +08:00 committed by GitHub
parent 91e2f055f2
commit 36c958a11d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -41,6 +41,19 @@ describe('koaAuth middleware', () => {
spy.mockRestore();
});
it('should read `development-user-id` from headers if not production', async () => {
const mockCtx = {
...ctx,
request: {
...ctx.request,
headers: { ...ctx.request.headers, 'development-user-id': 'foo' },
},
};
await koaAuth()(mockCtx, next);
expect(mockCtx.auth).toEqual('foo');
});
it('should set user auth with given sub returned from accessToken', async () => {
ctx.request = {
...ctx.request,

View file

@ -35,9 +35,10 @@ const extractBearerTokenFromHeaders = ({ authorization }: IncomingHttpHeaders) =
const getUserInfoFromRequest = async (request: Request) => {
const { isProduction, developmentUserId, oidc } = envSet.values;
const userId = developmentUserId || request.headers['development-user-id']?.toString();
if (!isProduction && developmentUserId) {
return developmentUserId;
if (!isProduction && userId) {
return userId;
}
const { publicKey, issuer } = oidc;