File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 1
- # CHANGELOG
2
-
1
+ * added access token authentication
3
2
4
3
## 1.5.0 (2023-02-22)
5
4
Original file line number Diff line number Diff line change @@ -34,6 +34,38 @@ YDB supports the following authentication methods:
34
34
- Metadata URL
35
35
- Anonymous
36
36
37
+ ## Access token
38
+
39
+ Use your access token:
40
+
41
+ ``` php
42
+ <?php
43
+
44
+ use YdbPlatform\Ydb\Ydb;
45
+
46
+ $config = [
47
+
48
+ // Database path
49
+ 'database' => '/ru-central1/b1glxxxxxxxxxxxxxxxx/etn0xxxxxxxxxxxxxxxx',
50
+
51
+ // Database endpoint
52
+ 'endpoint' => 'ydb.serverless.yandexcloud.net:2135',
53
+
54
+ // Auto discovery (dedicated server only)
55
+ 'discovery' => false,
56
+
57
+ // IAM config
58
+ 'iam_config' => [
59
+ 'root_cert_file' => './CA.pem', // Root CA file (dedicated server only!)
60
+
61
+ // Access token authentication
62
+ 'access_token' => 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
63
+ ],
64
+ ];
65
+
66
+ $ydb = new Ydb($config);
67
+ ```
68
+
37
69
## OAuth token
38
70
39
71
You should obtain [ a new OAuth token] ( https://cloud.yandex.com/docs/iam/concepts/authorization/oauth-token ) .
@@ -67,7 +99,6 @@ $config = [
67
99
];
68
100
69
101
$ydb = new Ydb($config);
70
-
71
102
```
72
103
73
104
## JWT + private key
Original file line number Diff line number Diff line change @@ -73,7 +73,10 @@ public function config($key, $default = null)
73
73
*/
74
74
public function token ($ force = false )
75
75
{
76
- if ($ force || !($ token = $ this ->loadToken ()))
76
+ if ($ token = $ this ->config ('access_token ' )){
77
+ return $ token ;
78
+ }
79
+ else if ($ force || !($ token = $ this ->loadToken ()))
77
80
{
78
81
$ token = $ this ->newToken ();
79
82
}
@@ -184,6 +187,7 @@ protected function parseConfig(array $config)
184
187
$ stringParams = [
185
188
'temp_dir ' ,
186
189
'root_cert_file ' ,
190
+ 'access_token ' ,
187
191
'oauth_token ' ,
188
192
'key_id ' ,
189
193
'service_account_id ' ,
@@ -272,6 +276,9 @@ protected function initConfig()
272
276
throw new Exception ('Private key [ ' . $ privateKeyFile . '] is missing. ' );
273
277
}
274
278
}
279
+ else if ($ this ->config ('access_token ' )){
280
+ $ this ->logger ()->info ('YDB: Authentication method: Access token ' );
281
+ }
275
282
else if ($ this ->config ('oauth_token ' ))
276
283
{
277
284
$ this ->logger ()->info ('YDB: Authentication method: OAuth token ' );
You can’t perform that action at this time.
0 commit comments