5
5
TenantId ,
6
6
} from "pagopa-interop-models" ;
7
7
import { z } from "zod" ;
8
+ import { SystemRole } from "../auth/authData.js" ;
8
9
9
10
export const ORGANIZATION = "organization" ;
10
11
export const UID = "uid" ;
@@ -18,7 +19,6 @@ export const ORGANIZATION_EXTERNAL_ID_ORIGIN_CLAIM = "origin";
18
19
export const ORGANIZATION_EXTERNAL_ID_VALUE_CLAIM = "value" ;
19
20
export const USER_ROLES = "user-roles" ;
20
21
const PURPOSE_ID_CLAIM = "purposeId" ;
21
- export const GENERATED_INTEROP_TOKEN_M2M_ROLE = "m2m" ;
22
22
export const ROLE_CLAIM = "role" ;
23
23
24
24
export interface InteropJwtHeader {
@@ -37,43 +37,69 @@ export type InteropJwtCommonPayload = {
37
37
exp : number ;
38
38
} ;
39
39
40
+ /* ==========================================
41
+ Interop CONSUMER Token
42
+ ========================================== */
40
43
export type InteropJwtConsumerPayload = InteropJwtCommonPayload & {
41
44
client_id : ClientId ;
42
45
sub : ClientId ;
43
46
[ PURPOSE_ID_CLAIM ] : PurposeId ;
44
47
digest ?: ClientAssertionDigest ;
45
48
} ;
46
49
47
- export type InteropJwtApiPayload = InteropJwtCommonPayload & {
50
+ export type InteropConsumerToken = {
51
+ header : InteropJwtHeader ;
52
+ payload : InteropJwtConsumerPayload ;
53
+ serialized : string ;
54
+ } ;
55
+
56
+ /* ==========================================
57
+ Interop API Token
58
+ ========================================== */
59
+ export type InteropJwtApiOrganizationClientPayload = InteropJwtCommonPayload & {
48
60
client_id : ClientId ;
49
61
sub : ClientId ;
50
62
[ ORGANIZATION_ID_CLAIM ] : TenantId ;
51
- [ ROLE_CLAIM ] : string ;
52
63
} ;
53
64
54
- export type InteropJwtPayload = InteropJwtCommonPayload & {
55
- sub : string ;
56
- role : string ;
65
+ export type InteropJwtApiM2MPayload = InteropJwtApiOrganizationClientPayload & {
66
+ [ ROLE_CLAIM ] : Extract < SystemRole , "m2m" > ;
57
67
} ;
58
68
59
- export type InteropToken = {
69
+ export type InteropJwtApiM2MAdminPayload =
70
+ InteropJwtApiOrganizationClientPayload & {
71
+ [ ROLE_CLAIM ] : Extract < SystemRole , "m2m-admin" > ;
72
+ userId : UserId ;
73
+ // ^ ID of the admin user associated with the client
74
+ } ;
75
+
76
+ export type InteropJWTApiPayload =
77
+ | InteropJwtApiM2MAdminPayload
78
+ | InteropJwtApiM2MPayload ;
79
+
80
+ export type InteropApiToken = {
60
81
header : InteropJwtHeader ;
61
- payload : InteropJwtPayload ;
82
+ payload : InteropJWTApiPayload ;
62
83
serialized : string ;
63
84
} ;
64
85
65
- export type InteropConsumerToken = {
66
- header : InteropJwtHeader ;
67
- payload : InteropJwtConsumerPayload ;
68
- serialized : string ;
86
+ /* ================================= =========
87
+ Interop INTERNAL Token
88
+ ========================================== */
89
+ export type InteropJwtPayload = InteropJwtCommonPayload & {
90
+ sub : string ;
91
+ role : string ;
69
92
} ;
70
93
71
- export type InteropApiToken = {
94
+ export type InteropToken = {
72
95
header : InteropJwtHeader ;
73
- payload : InteropJwtApiPayload ;
96
+ payload : InteropJwtPayload ;
74
97
serialized : string ;
75
98
} ;
76
99
100
+ /* ==========================================
101
+ Interop SESSION Token
102
+ ========================================== */
77
103
const Organization = z . object ( {
78
104
id : z . string ( ) ,
79
105
name : z . string ( ) ,
0 commit comments