Skip to content

Commit 7e5e474

Browse files
authored
Anonymous users (#445)
+ test related to descope/etc#9497
1 parent 4ee51be commit 7e5e474

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

lib/management/jwt.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,28 @@ describe('Management JWT', () => {
197197
expect(resp).toEqual({ code: 200, data: mockJWTResponse, ok: true, response: httpResponse });
198198
});
199199
});
200+
201+
describe('anonymous', () => {
202+
it('should send the correct request and receive correct response', async () => {
203+
const httpResponse = {
204+
ok: true,
205+
json: () => mockJWTResponse,
206+
clone: () => ({
207+
json: () => Promise.resolve(mockJWTResponse),
208+
}),
209+
status: 200,
210+
};
211+
mockHttpClient.post.mockResolvedValue(httpResponse);
212+
213+
const resp: SdkResponse<JWTResponse> = await management.jwt.anonymous({ k1: 'v1' }, 't1');
214+
215+
expect(mockHttpClient.post).toHaveBeenCalledWith(
216+
apiPaths.jwt.anonymous,
217+
{ customClaims: { k1: 'v1' }, selectedTenant: 't1' },
218+
{ token: 'key' },
219+
);
220+
221+
expect(resp).toEqual({ code: 200, data: mockJWTResponse, ok: true, response: httpResponse });
222+
});
223+
});
200224
});

lib/management/jwt.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { CoreSdk } from '../types';
33
import apiPaths from './paths';
44
import { MgmtLoginOptions, MgmtSignUpOptions, MgmtUserOptions, UpdateJWTResponse } from './types';
55

6+
type AnonymousJWTResponse = Omit<JWTResponse, 'user' | 'firstSeen'>;
7+
68
const withJWT = (sdk: CoreSdk, managementKey?: string) => ({
79
update: (
810
jwt: string,
@@ -62,6 +64,17 @@ const withJWT = (sdk: CoreSdk, managementKey?: string) => ({
6264
{ token: managementKey },
6365
),
6466
),
67+
anonymous: (
68+
customClaims?: Record<string, any>,
69+
selectedTenant?: string,
70+
): Promise<SdkResponse<AnonymousJWTResponse>> =>
71+
transformResponse(
72+
sdk.httpClient.post(
73+
apiPaths.jwt.anonymous,
74+
{ customClaims, selectedTenant },
75+
{ token: managementKey },
76+
),
77+
),
6578
});
6679

6780
export default withJWT;

lib/management/paths.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default {
9696
signIn: '/v1/mgmt/auth/signin',
9797
signUp: '/v1/mgmt/auth/signup',
9898
signUpOrIn: '/v1/mgmt/auth/signup-in',
99+
anonymous: '/v1/mgmt/auth/anonymous',
99100
},
100101
password: {
101102
settings: '/v1/mgmt/password/settings',

0 commit comments

Comments
 (0)