1717
1818import static io .serverlessworkflow .api .types .OAuth2AuthenticationDataClient .ClientAuthentication .CLIENT_SECRET_POST ;
1919import static io .serverlessworkflow .impl .WorkflowUtils .isValid ;
20+ import static io .serverlessworkflow .impl .auth .AuthUtils .ACTOR ;
21+ import static io .serverlessworkflow .impl .auth .AuthUtils .ACTOR_TOKEN ;
22+ import static io .serverlessworkflow .impl .auth .AuthUtils .ACTOR_TOKEN_TYPE ;
2023import static io .serverlessworkflow .impl .auth .AuthUtils .AUDIENCES ;
2124import static io .serverlessworkflow .impl .auth .AuthUtils .AUTHENTICATION ;
2225import static io .serverlessworkflow .impl .auth .AuthUtils .CLIENT ;
2326import static io .serverlessworkflow .impl .auth .AuthUtils .ENCODING ;
2427import static io .serverlessworkflow .impl .auth .AuthUtils .REQUEST ;
2528import static io .serverlessworkflow .impl .auth .AuthUtils .SCOPES ;
29+ import static io .serverlessworkflow .impl .auth .AuthUtils .SUBJECT ;
30+ import static io .serverlessworkflow .impl .auth .AuthUtils .SUBJECT_TOKEN ;
31+ import static io .serverlessworkflow .impl .auth .AuthUtils .SUBJECT_TOKEN_TYPE ;
32+ import static io .serverlessworkflow .impl .auth .AuthUtils .TOKEN ;
33+ import static io .serverlessworkflow .impl .auth .AuthUtils .TYPE ;
2634
2735import io .serverlessworkflow .api .types .OAuth2AuthenticationData ;
2836import io .serverlessworkflow .api .types .OAuth2AuthenticationDataClient ;
37+ import io .serverlessworkflow .api .types .OAuth2TokenDefinition ;
2938import io .serverlessworkflow .impl .WorkflowApplication ;
3039import io .serverlessworkflow .impl .WorkflowUtils ;
3140import java .util .Arrays ;
@@ -51,6 +60,7 @@ public HttpRequestInfo apply(T authenticationData) {
5160 audience (authenticationData );
5261 scope (authenticationData );
5362 authenticationMethod (authenticationData );
63+ subjectActor (authenticationData );
5464 return requestBuilder .build ();
5565 }
5666
@@ -61,6 +71,7 @@ public HttpRequestInfo apply(Map<String, Object> secret) {
6171 audience (secret );
6272 scope (secret );
6373 authenticationMethod (secret );
74+ subjectActor (secret );
6475 return requestBuilder .build ();
6576 }
6677
@@ -80,44 +91,62 @@ protected void audience(Map<String, Object> secret) {
8091 }
8192
8293 protected void authenticationMethod (T authenticationData ) {
83- ClientSecretHandler secretHandler ;
84- switch (getClientAuthentication (authenticationData )) {
85- case CLIENT_SECRET_BASIC :
86- secretHandler = new ClientSecretBasic (application , requestBuilder );
87- case CLIENT_SECRET_JWT :
88- throw new UnsupportedOperationException ("Client Secret JWT is not supported yet" );
89- case PRIVATE_KEY_JWT :
90- throw new UnsupportedOperationException ("Private Key JWT is not supported yet" );
91- default :
92- secretHandler = new ClientSecretPost (application , requestBuilder );
93- }
94+ ClientSecretHandler secretHandler =
95+ switch (getClientAuthentication (authenticationData )) {
96+ case CLIENT_SECRET_BASIC -> new ClientSecretBasic (application , requestBuilder );
97+ case CLIENT_SECRET_JWT , PRIVATE_KEY_JWT ->
98+ new JwtClientAssertion (application , requestBuilder );
99+ default -> new ClientSecretPost (application , requestBuilder );
100+ };
94101 secretHandler .accept (authenticationData );
95102 }
96103
104+ @ SuppressWarnings ("unchecked" )
97105 protected void authenticationMethod (Map <String , Object > secret ) {
98106 Map <String , Object > client = (Map <String , Object >) secret .get (CLIENT );
99107 ClientSecretHandler secretHandler ;
100108 String auth = (String ) client .get (AUTHENTICATION );
101109 if (auth == null ) {
102110 secretHandler = new ClientSecretPost (application , requestBuilder );
103111 } else {
104- switch (auth ) {
105- case "client_secret_basic" :
106- secretHandler = new ClientSecretBasic (application , requestBuilder );
107- break ;
108- default :
109- case "client_secret_post" :
110- secretHandler = new ClientSecretPost (application , requestBuilder );
111- break ;
112- case "private_key_jwt" :
113- throw new UnsupportedOperationException ("Private Key JWT is not supported yet" );
114- case "client_secret_jwt" :
115- throw new UnsupportedOperationException ("Client Secret JWT is not supported yet" );
116- }
112+ secretHandler =
113+ switch (auth ) {
114+ case "client_secret_basic" -> new ClientSecretBasic (application , requestBuilder );
115+ case "private_key_jwt" , "client_secret_jwt" ->
116+ new JwtClientAssertion (application , requestBuilder );
117+ default -> new ClientSecretPost (application , requestBuilder );
118+ };
117119 }
118120 secretHandler .accept (secret );
119121 }
120122
123+ protected void subjectActor (T authenticationData ) {
124+ tokenParam (SUBJECT_TOKEN , SUBJECT_TOKEN_TYPE , authenticationData .getSubject ());
125+ tokenParam (ACTOR_TOKEN , ACTOR_TOKEN_TYPE , authenticationData .getActor ());
126+ }
127+
128+ private void tokenParam (String tokenKey , String typeKey , OAuth2TokenDefinition definition ) {
129+ if (definition != null ) {
130+ requestBuilder
131+ .addQueryParam (
132+ tokenKey , WorkflowUtils .buildStringFilter (application , definition .getToken ()))
133+ .addQueryParam (typeKey , definition .getType ());
134+ }
135+ }
136+
137+ protected void subjectActor (Map <String , Object > secret ) {
138+ tokenParam (SUBJECT_TOKEN , SUBJECT_TOKEN_TYPE , secret .get (SUBJECT ));
139+ tokenParam (ACTOR_TOKEN , ACTOR_TOKEN_TYPE , secret .get (ACTOR ));
140+ }
141+
142+ private void tokenParam (String tokenKey , String typeKey , Object rawDefinition ) {
143+ if (rawDefinition instanceof Map <?, ?> definition ) {
144+ requestBuilder
145+ .addQueryParam (tokenKey , (String ) definition .get (TOKEN ))
146+ .addQueryParam (typeKey , (String ) definition .get (TYPE ));
147+ }
148+ }
149+
121150 private OAuth2AuthenticationDataClient .ClientAuthentication getClientAuthentication (
122151 OAuth2AuthenticationData authenticationData ) {
123152 return authenticationData .getClient () == null
0 commit comments