Skip to content

Commit 97c1dc8

Browse files
authored
#18252 - [REQ] add sessionToken support to AWS4Auth (#18253)
1 parent 44ae981 commit 97c1dc8

15 files changed

Lines changed: 197 additions & 0 deletions

File tree

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,29 @@ public class ApiClient {
652652
throw new RuntimeException("No AWS4 authentication configured!");
653653
}
654654

655+
/**
656+
* Helper method to set credentials for AWSV4 Signature
657+
*
658+
* @param accessKey Access Key
659+
* @param secretKey Secret Key
660+
* @param sessionToken Session Token
661+
* @param region Region
662+
* @param service Service to access to
663+
*/
664+
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
665+
{{#withAWSV4Signature}}
666+
for (Authentication auth : authentications.values()) {
667+
if (auth instanceof AWS4Auth) {
668+
((AWS4Auth) auth).setCredentials(accessKey, secretKey, sessionToken);
669+
((AWS4Auth) auth).setRegion(region);
670+
((AWS4Auth) auth).setService(service);
671+
return;
672+
}
673+
}
674+
{{/withAWSV4Signature}}
675+
throw new RuntimeException("No AWS4 authentication configured!");
676+
}
677+
655678
/**
656679
* Set the User-Agent header's value (by adding to the default header map).
657680
*

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/AWS4Auth.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
1616

1717
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
1818
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
19+
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
1920
import software.amazon.awssdk.auth.credentials.AwsCredentials;
2021
import software.amazon.awssdk.auth.signer.Aws4Signer;
2122
import software.amazon.awssdk.auth.signer.params.Aws4SignerParams;
@@ -41,6 +42,10 @@ public class AWS4Auth implements Authentication {
4142
this.credentials = AwsBasicCredentials.create(accessKey, secretKey);
4243
}
4344

45+
public void setCredentials(String accessKey, String secretKey, String sessionToken) {
46+
this.credentials = AwsSessionCredentials.create(accessKey, secretKey, sessionToken);
47+
}
48+
4449
public void setRegion(String region) {
4550
this.region = region;
4651
}

samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,19 @@ public void setAWS4Configuration(String accessKey, String secretKey, String regi
491491
throw new RuntimeException("No AWS4 authentication configured!");
492492
}
493493

494+
/**
495+
* Helper method to set credentials for AWSV4 Signature
496+
*
497+
* @param accessKey Access Key
498+
* @param secretKey Secret Key
499+
* @param sessionToken Session Token
500+
* @param region Region
501+
* @param service Service to access to
502+
*/
503+
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
504+
throw new RuntimeException("No AWS4 authentication configured!");
505+
}
506+
494507
/**
495508
* Set the User-Agent header's value (by adding to the default header map).
496509
*

samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,19 @@ public void setAWS4Configuration(String accessKey, String secretKey, String regi
465465
throw new RuntimeException("No AWS4 authentication configured!");
466466
}
467467

468+
/**
469+
* Helper method to set credentials for AWSV4 Signature
470+
*
471+
* @param accessKey Access Key
472+
* @param secretKey Secret Key
473+
* @param sessionToken Session Token
474+
* @param region Region
475+
* @param service Service to access to
476+
*/
477+
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
478+
throw new RuntimeException("No AWS4 authentication configured!");
479+
}
480+
468481
/**
469482
* Set the User-Agent header's value (by adding to the default header map).
470483
*

samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,19 @@ public void setAWS4Configuration(String accessKey, String secretKey, String regi
465465
throw new RuntimeException("No AWS4 authentication configured!");
466466
}
467467

468+
/**
469+
* Helper method to set credentials for AWSV4 Signature
470+
*
471+
* @param accessKey Access Key
472+
* @param secretKey Secret Key
473+
* @param sessionToken Session Token
474+
* @param region Region
475+
* @param service Service to access to
476+
*/
477+
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
478+
throw new RuntimeException("No AWS4 authentication configured!");
479+
}
480+
468481
/**
469482
* Set the User-Agent header's value (by adding to the default header map).
470483
*

samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,19 @@ public void setAWS4Configuration(String accessKey, String secretKey, String regi
547547
throw new RuntimeException("No AWS4 authentication configured!");
548548
}
549549

550+
/**
551+
* Helper method to set credentials for AWSV4 Signature
552+
*
553+
* @param accessKey Access Key
554+
* @param secretKey Secret Key
555+
* @param sessionToken Session Token
556+
* @param region Region
557+
* @param service Service to access to
558+
*/
559+
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
560+
throw new RuntimeException("No AWS4 authentication configured!");
561+
}
562+
550563
/**
551564
* Set the User-Agent header's value (by adding to the default header map).
552565
*

samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,27 @@ public void setAWS4Configuration(String accessKey, String secretKey, String regi
559559
throw new RuntimeException("No AWS4 authentication configured!");
560560
}
561561

562+
/**
563+
* Helper method to set credentials for AWSV4 Signature
564+
*
565+
* @param accessKey Access Key
566+
* @param secretKey Secret Key
567+
* @param sessionToken Session Token
568+
* @param region Region
569+
* @param service Service to access to
570+
*/
571+
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
572+
for (Authentication auth : authentications.values()) {
573+
if (auth instanceof AWS4Auth) {
574+
((AWS4Auth) auth).setCredentials(accessKey, secretKey, sessionToken);
575+
((AWS4Auth) auth).setRegion(region);
576+
((AWS4Auth) auth).setService(service);
577+
return;
578+
}
579+
}
580+
throw new RuntimeException("No AWS4 authentication configured!");
581+
}
582+
562583
/**
563584
* Set the User-Agent header's value (by adding to the default header map).
564585
*

samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/auth/AWS4Auth.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
2929
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
30+
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
3031
import software.amazon.awssdk.auth.credentials.AwsCredentials;
3132
import software.amazon.awssdk.auth.signer.Aws4Signer;
3233
import software.amazon.awssdk.auth.signer.params.Aws4SignerParams;
@@ -52,6 +53,10 @@ public void setCredentials(String accessKey, String secretKey) {
5253
this.credentials = AwsBasicCredentials.create(accessKey, secretKey);
5354
}
5455

56+
public void setCredentials(String accessKey, String secretKey, String sessionToken) {
57+
this.credentials = AwsSessionCredentials.create(accessKey, secretKey, sessionToken);
58+
}
59+
5560
public void setRegion(String region) {
5661
this.region = region;
5762
}

samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,19 @@ public void setAWS4Configuration(String accessKey, String secretKey, String regi
564564
throw new RuntimeException("No AWS4 authentication configured!");
565565
}
566566

567+
/**
568+
* Helper method to set credentials for AWSV4 Signature
569+
*
570+
* @param accessKey Access Key
571+
* @param secretKey Secret Key
572+
* @param sessionToken Session Token
573+
* @param region Region
574+
* @param service Service to access to
575+
*/
576+
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
577+
throw new RuntimeException("No AWS4 authentication configured!");
578+
}
579+
567580
/**
568581
* Set the User-Agent header's value (by adding to the default header map).
569582
*

samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,19 @@ public void setAWS4Configuration(String accessKey, String secretKey, String regi
547547
throw new RuntimeException("No AWS4 authentication configured!");
548548
}
549549

550+
/**
551+
* Helper method to set credentials for AWSV4 Signature
552+
*
553+
* @param accessKey Access Key
554+
* @param secretKey Secret Key
555+
* @param sessionToken Session Token
556+
* @param region Region
557+
* @param service Service to access to
558+
*/
559+
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
560+
throw new RuntimeException("No AWS4 authentication configured!");
561+
}
562+
550563
/**
551564
* Set the User-Agent header's value (by adding to the default header map).
552565
*

0 commit comments

Comments
 (0)