Skip to content

Commit e483d3d

Browse files
committed
chore: PR comments
1 parent 6a7d025 commit e483d3d

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/core/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
import type { BaseConfig } from './config/sdk-config';
12-
import type { TokenInfo } from './auth/types';
12+
import type { TokenInfo, TokenIdentity } from './auth/types';
1313

1414
export interface IUiPath {
1515
/** Read-only configuration for the SDK instance */
@@ -47,6 +47,13 @@ export interface IUiPath {
4747
*/
4848
getToken(): string | undefined;
4949

50+
/**
51+
* Retrieves identity claims (email, firstName, lastName, preferredUsername, name)
52+
* of the currently authenticated user by decoding the JWT access token.
53+
* Does not work with PAT tokens.
54+
*/
55+
getTokenIdentity(): TokenIdentity;
56+
5057
/**
5158
* Logout from the SDK, clearing all authentication state.
5259
* After calling this method, the user will need to re-initialize to authenticate again.

tests/unit/core/uipath.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,19 @@ describe('UiPath Core', () => {
443443
expect(() => sdk.getTokenIdentity()).toThrow(ValidationError);
444444
});
445445

446+
it('should throw ValidationError when token has more than 3 segments', () => {
447+
mockAuthState.token = 'header.payload.sig.extra';
448+
449+
const sdk = new UiPath({
450+
baseUrl: TEST_CONSTANTS.BASE_URL,
451+
orgName: TEST_CONSTANTS.ORGANIZATION_ID,
452+
tenantName: TEST_CONSTANTS.TENANT_ID,
453+
secret: TEST_CONSTANTS.CLIENT_SECRET
454+
});
455+
456+
expect(() => sdk.getTokenIdentity()).toThrow(ValidationError);
457+
});
458+
446459
it('should throw ValidationError when payload is not valid JSON', () => {
447460
const header = Buffer.from(JSON.stringify({ alg: 'none' })).toString('base64url');
448461
const invalidPayload = Buffer.from('not-json-content').toString('base64url');

0 commit comments

Comments
 (0)