22
33namespace YdbPlatform \Ydb \Auth \Implement ;
44
5- use YdbPlatform \Ydb \Auth \Auth ;
5+ use YdbPlatform \Ydb \Auth \IamAuth ;
66use YdbPlatform \Ydb \Auth \TokenInfo ;
77use YdbPlatform \Ydb \Auth \UseConfigInterface ;
8- use YdbPlatform \Ydb \AuthService ;
98use YdbPlatform \Ydb \Ydb ;
109
11- class StaticAuthentication extends Auth implements UseConfigInterface
10+ class StaticAuthentication extends IamAuth implements UseConfigInterface
1211{
1312 protected $ user ;
1413 protected $ password ;
@@ -27,10 +26,11 @@ public function __construct(string $user, string $password)
2726 public function getTokenInfo (): TokenInfo
2827 {
2928 $ this ->token = $ this ->ydb ->auth ()->getToken ($ this ->user , $ this ->password );
30- $ expiresIn = 12 *60 *60 ;
29+ $ jwtData = $ this ->decodeHeaderAndPayload ($ this ->token );
30+ $ expiresIn = $ this ->convertExpiresAt ($ jwtData ['payload ' ]['exp ' ]);
3131 $ ratio = $ this ->getRefreshTokenRatio ();
3232
33- return new TokenInfo ($ this ->token , time ()+ $ expiresIn , $ ratio );
33+ return new TokenInfo ($ this ->token , $ expiresIn , $ ratio );
3434 }
3535
3636 public function getName (): string
@@ -41,7 +41,7 @@ public function getName(): string
4141 public function setYdbConnectionConfig (array $ config )
4242 {
4343 unset($ config ['credentials ' ]);
44- $ config ['credentials ' ] = new AccessTokenAuthentication ( '' );
44+ $ config ['credentials ' ] = new AnonymousAuthentication ( );
4545 $ this ->ydb = new Ydb ($ config , $ this ->logger );
4646 }
4747}
0 commit comments