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