UNPKG

3.5 kBTypeScriptView Raw
1import { JwtPayload } from 'jsonwebtoken';
2import { JwtKeyMapping } from './jwt';
3/**
4 * Representation of the user i.e. authenticated persona. The authentication is done by the XSUAA.
5 */
6export interface UserData {
7 id: string;
8 userName: string;
9 givenName?: string;
10 familyName?: string;
11 email?: string;
12 scopes: Scope[];
13 customAttributes: Map<string, string[]>;
14}
15/**
16 * Representation of the user i.e. authenticated persona. The authentication is done by the XSUAA.
17 */
18export interface User extends UserData {
19 hasScope: (scope: Scope) => boolean;
20}
21/**
22 * Extracts the custom attributes from the JWT.
23 * @param jwtPayload - Token payload to read the custom attributes from.
24 * @returns Custom attributes added by the XSUAA service to the issued JWT.
25 */
26export declare function customAttributes(jwtPayload: JwtPayload): Map<string, string[]>;
27/**
28 * Mapping between key name in the User and key name in decoded JWT and the
29 */
30export declare const mappingUserFields: JwtKeyMapping<UserData, 'user_id' | 'user_name' | 'given_name' | 'family_name' | 'email' | 'scope' | 'xs.user.attributes'>;
31/**
32 * Get the user's given name from the JWT payload.
33 * @param jwtPayload - Token payload to read the user's given name from.
34 * @returns The user's given name if available.
35 */
36export declare function userGivenName(jwtPayload: JwtPayload): string | undefined;
37/**
38 * Get the user's family name from the JWT payload.
39 * @param jwtPayload - Token payload to read the user's family from.
40 * @returns The user's family name if available.
41 */
42export declare function userFamilyName(jwtPayload: JwtPayload): string | undefined;
43/**
44 * Get the user name from the JWT payload.
45 * @param jwtPayload - Token payload to read the user name from.
46 * @returns The user name if available.
47 */
48export declare function userName(jwtPayload: JwtPayload): string | undefined;
49/**
50 * Get the user's e-mail address from the JWT payload.
51 * @param jwtPayload - Token payload to read the user e-mail address from.
52 * @returns The user's e-mail address if available.
53 */
54export declare function userEmail(jwtPayload: JwtPayload): string | undefined;
55/**
56 * Get the user's scopes from the JWT payload.
57 * @param jwtPayload - Token payload to read the user's scopes from.
58 * @returns The user's scopes if available.
59 */
60export declare function userScopes(jwtPayload: JwtPayload): Scope[];
61/**
62 * Get the user id from the JWT payload.
63 * @param jwtPayload - Token payload to read the user id from.
64 * @returns The user id if available.
65 */
66export declare function userId(jwtPayload: JwtPayload): string | undefined;
67/**
68 * @deprecated Since v1.46.0. This interface will not be replaced. Use the higher level JWT types directly.
69 * Keys in the JWT related to the user.
70 */
71export interface RegisteredJWTClaimsUser {
72 user_id?: string;
73 user_name?: string;
74 given_name?: string;
75 family_name?: string;
76 email?: string;
77 scope?: string[];
78 'xs.user.attributes'?: Map<string, string[]>;
79}
80/**
81 * Representation of the scope. A scope is assigned to a user via role-collection in cloud foundry.
82 */
83export interface Scope {
84 name: string;
85}
86/**
87 * Creates a user object from the decoded JWT.
88 * Throws an error if no `id` or `userName` property is present on the JWT payload.
89 * @param jwtPayload - Token payload to get the user from.
90 * @returns Representation of the user.
91 */
92export declare function userFromJwt(jwtPayload: JwtPayload): User;
93//# sourceMappingURL=user.d.ts.map
\No newline at end of file