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:
parent
91e2f055f2
commit
36c958a11d
2 changed files with 16 additions and 2 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue