-
Notifications
You must be signed in to change notification settings - Fork 41
/
tenant.ts
46 lines (42 loc) · 1.05 KB
/
tenant.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {
checkMandatoryValue,
DecodedJWT,
JwtKeyMapping,
tenantId,
tenantName
} from '../util';
/**
* Mapping between key name in the Tenant and key name in decoded JWT and the
*/
export const mapping: JwtKeyMapping<Tenant, RegisteredJWTClaimsTenant> = {
id: { keyInJwt: 'zid', extractorFunction: tenantId },
name: { keyInJwt: 'zdn', extractorFunction: tenantName }
};
/**
* Keys in the JWT related to the user
*/
export interface RegisteredJWTClaimsTenant {
zid?: string;
zdn?: string;
}
/**
* Representation of the tenant. A tenant represents the customer account on cloud foundry.
*/
export interface Tenant {
id: string;
name?: string;
}
/**
* Creates a tenant object from the decoded JWT.
*
* @param decodedJWT - Decoded JWT token
* @returns Representation of the tenant.
* @exception Error Raised if no id is found in the decoded JWT.
*/
export function tenantFromJwt(decodedJWT: DecodedJWT): Tenant {
checkMandatoryValue('id', mapping, decodedJWT);
return {
id: tenantId(decodedJWT)!,
name: tenantName(decodedJWT)
};
}