Skip to content

Commit

Permalink
support bearer token
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 authored and peze committed Apr 11, 2022
1 parent c79ed85 commit 5543cd1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
71 changes: 58 additions & 13 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1134,27 +1134,42 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime

request_.Headers["x-acs-content-sha256"] = hashedRequestPayload
if !tea.BoolValue(util.EqualString(params.AuthType, tea.String("Anonymous"))) {
accessKeyId, _err := client.GetAccessKeyId()
authType, _err := client.GetType()
if _err != nil {
return _result, _err
}

accessKeySecret, _err := client.GetAccessKeySecret()
if _err != nil {
return _result, _err
}
if !tea.BoolValue(util.EqualString(authType, tea.String("bearer"))) {
bearerToken, _err := client.GetBearerToken()
if _err != nil {
return _result, _err
}

securityToken, _err := client.GetSecurityToken()
if _err != nil {
return _result, _err
}
request_.Headers["x-acs-bearer-token"] = bearerToken
} else {
accessKeyId, _err := client.GetAccessKeyId()
if _err != nil {
return _result, _err
}

if !tea.BoolValue(util.Empty(securityToken)) {
request_.Headers["x-acs-accesskey-id"] = accessKeyId
request_.Headers["x-acs-security-token"] = securityToken
accessKeySecret, _err := client.GetAccessKeySecret()
if _err != nil {
return _result, _err
}

securityToken, _err := client.GetSecurityToken()
if _err != nil {
return _result, _err
}

if !tea.BoolValue(util.Empty(securityToken)) {
request_.Headers["x-acs-accesskey-id"] = accessKeyId
request_.Headers["x-acs-security-token"] = securityToken
}

request_.Headers["Authorization"] = openapiutil.GetAuthorization(request_, signatureAlgorithm, hashedRequestPayload, accessKeyId, accessKeySecret)
}

request_.Headers["Authorization"] = openapiutil.GetAuthorization(request_, signatureAlgorithm, hashedRequestPayload, accessKeyId, accessKeySecret)
}

response_, _err := tea.DoRequest(request_, _runtime)
Expand Down Expand Up @@ -1506,6 +1521,36 @@ func (client *Client) GetSecurityToken() (_result *string, _err error) {
return _result, _err
}

/**
* Get bearer token by credential
* @return bearer token
*/
func (client *Client) GetBearerToken() (_result *string, _err error) {
if tea.BoolValue(util.IsUnset(client.Credential)) {
_result = tea.String("")
return _result, _err
}

token := client.Credential.GetBearerToken()
_result = token
return _result, _err
}

/**
* Get credential type by credential
* @return credential type e.g. access_key
*/
func (client *Client) GetType() (_result *string, _err error) {
if tea.BoolValue(util.IsUnset(client.Credential)) {
_result = tea.String("")
return _result, _err
}

authType := client.Credential.GetType()
_result = authType
return _result, _err
}

/**
* If inputValue is not null, return it or return defaultValue
* @param inputValue users input value
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4
github.com/alibabacloud-go/darabonba-string v1.0.0
github.com/alibabacloud-go/openapi-util v0.0.10
github.com/alibabacloud-go/openapi-util v0.0.11
github.com/alibabacloud-go/tea v1.1.17
github.com/alibabacloud-go/tea-utils v1.4.3
github.com/aliyun/credentials-go v1.1.2
Expand Down

0 comments on commit 5543cd1

Please sign in to comment.