Skip to content

Commit

Permalink
refactor: solve the inconsistency of credentials refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Jul 28, 2023
1 parent 9e05387 commit 3578bf1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>credentials-java</artifactId>
<version>0.2.10</version>
<version>0.3.0</version>
<exclusions>
<exclusion>
<groupId>com.aliyun</groupId>
Expand All @@ -66,7 +66,7 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>openapiutil</artifactId>
<version>0.2.0</version>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
Expand Down
11 changes: 6 additions & 5 deletions java/src/main/java/com/aliyun/teaopenapi/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,15 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception {

request_.headers.put("x-acs-content-sha256", hashedRequestPayload);
if (!com.aliyun.teautil.Common.equalString(params.authType, "Anonymous")) {
String authType = this.getType();
com.aliyun.credentials.models.CredentialModel credentialModel = _credential.getCredential();
String authType = credentialModel.type;
if (com.aliyun.teautil.Common.equalString(authType, "bearer")) {
String bearerToken = this.getBearerToken();
String bearerToken = credentialModel.bearerToken;
request_.headers.put("x-acs-bearer-token", bearerToken);
} else {
String accessKeyId = this.getAccessKeyId();
String accessKeySecret = this.getAccessKeySecret();
String securityToken = this.getSecurityToken();
String accessKeyId = credentialModel.accessKeyId;
String accessKeySecret = credentialModel.accessKeySecret;
String securityToken = credentialModel.securityToken;
if (!com.aliyun.teautil.Common.empty(securityToken)) {
request_.headers.put("x-acs-accesskey-id", accessKeyId);
request_.headers.put("x-acs-security-token", securityToken);
Expand Down
11 changes: 6 additions & 5 deletions main.tea
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,15 @@ api doRequest(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOpti
__request.headers.x-acs-content-sha256 = hashedRequestPayload;

if (!Util.equalString(params.authType, 'Anonymous')) {
var authType = getType();
var credentialModel = @credential.getCredential();
var authType = credentialModel.type;
if (Util.equalString(authType, 'bearer')) {
var bearerToken = getBearerToken();
var bearerToken = credentialModel.bearerToken;
__request.headers.x-acs-bearer-token = bearerToken;
} else {
var accessKeyId = getAccessKeyId();
var accessKeySecret = getAccessKeySecret();
var securityToken = getSecurityToken();
var accessKeyId = credentialModel.accessKeyId;
var accessKeySecret = credentialModel.accessKeySecret;
var securityToken = credentialModel.securityToken;

if (!Util.empty(securityToken)) {
__request.headers.x-acs-accesskey-id = accessKeyId;
Expand Down

0 comments on commit 3578bf1

Please sign in to comment.