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