Skip to content

Commit

Permalink
refactor: improve all credentials providers
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Sep 23, 2024
1 parent 8750d18 commit 1d6a525
Show file tree
Hide file tree
Showing 66 changed files with 3,951 additions and 1,232 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
1 change: 1 addition & 0 deletions .phpunit.result.cache

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ $bearerToken = new Credential([
'bearer_token' => '<bearer_token>',
]);
$bearerToken->getBearerToken();
$bearerToken->getSignature();
```

## 默认凭证提供程序链
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ $bearerToken = new Credential([
'bearer_token' => '<bearer_token>',
]);
$bearerToken->getBearerToken();
$bearerToken->getSignature();
```

## Default credential provider chain
Expand Down
25 changes: 15 additions & 10 deletions src/AccessKeyCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace AlibabaCloud\Credentials;

use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
use AlibabaCloud\Credentials\Utils\Filter;
use AlibabaCloud\Credentials\Credential\CredentialModel;

/**
* @deprecated
* Use the AccessKey to complete the authentication.
*/
class AccessKeyCredential implements CredentialsInterface
Expand All @@ -29,7 +31,7 @@ public function __construct($access_key_id, $access_key_secret)
{
Filter::accessKey($access_key_id, $access_key_secret);

$this->accessKeyId = $access_key_id;
$this->accessKeyId = $access_key_id;
$this->accessKeySecret = $access_key_secret;
}

Expand Down Expand Up @@ -57,16 +59,19 @@ public function __toString()
return "$this->accessKeyId#$this->accessKeySecret";
}

/**
* @return ShaHmac1Signature
*/
public function getSignature()
{
return new ShaHmac1Signature();
}

public function getSecurityToken()
{
return '';
}
/**
* @inheritDoc
*/
public function getCredential()
{
return new CredentialModel([
'accessKeyId' => $this->accessKeyId,
'accessKeySecret' => $this->accessKeySecret,
'type' => 'access_key',
]);
}
}
13 changes: 9 additions & 4 deletions src/BearerTokenCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace AlibabaCloud\Credentials;

use AlibabaCloud\Credentials\Signature\BearerTokenSignature;
use AlibabaCloud\Credentials\Utils\Filter;
use AlibabaCloud\Credentials\Credential\CredentialModel;

/**
* Class BearerTokenCredential
Expand Down Expand Up @@ -44,10 +45,14 @@ public function __toString()
}

/**
* @return BearerTokenSignature
* @inheritDoc
*/
public function getSignature()
public function getCredential()
{
return new BearerTokenSignature();
return new CredentialModel([
'bearerToken' => $this->bearerToken,
'type' => 'bearer',
]);
}

}
Loading

0 comments on commit 1d6a525

Please sign in to comment.