Skip to content

Commit 42eabb4

Browse files
author
Илья
committed
Move decodeHeaderAndPayload function to Jwt
1 parent 328aa07 commit 42eabb4

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/Auth/IamAuth.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,4 @@ public function requestToken($request_data)
5757
throw new Exception('Failed to obtain new iamToken: response status is ' . $status);
5858
}
5959
}
60-
61-
public function decodeHeaderAndPayload(string $jwtToken) : array {
62-
$paths = explode(".", $jwtToken);
63-
$result = [];
64-
$result["header"] = json_decode(base64_decode($paths[0]), true);
65-
$result["payload"] = json_decode(base64_decode($paths[1]), true);
66-
return $result;
67-
}
6860
}

src/Auth/Implement/StaticAuthentication.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use YdbPlatform\Ydb\Auth\IamAuth;
66
use YdbPlatform\Ydb\Auth\TokenInfo;
77
use YdbPlatform\Ydb\Auth\UseConfigInterface;
8+
use YdbPlatform\Ydb\Jwt\Jwt;
89
use YdbPlatform\Ydb\Ydb;
910

1011
class StaticAuthentication extends IamAuth implements UseConfigInterface
@@ -26,7 +27,7 @@ public function __construct(string $user, string $password)
2627
public function getTokenInfo(): TokenInfo
2728
{
2829
$this->token = $this->ydb->auth()->getToken($this->user, $this->password);
29-
$jwtData = $this->decodeHeaderAndPayload($this->token);
30+
$jwtData = Jwt::decodeHeaderAndPayload($this->token);
3031
$expiresIn = $this->convertExpiresAt($jwtData['payload']['exp']);
3132
$ratio = $this->getRefreshTokenRatio();
3233

src/Jwt/Jwt.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,12 @@ public function urlEncode($value)
136136
}
137137
return str_replace('=', '', strtr(base64_encode($value), '+/', '-_'));
138138
}
139+
140+
public static function decodeHeaderAndPayload(string $jwtToken) : array {
141+
$paths = explode(".", $jwtToken);
142+
$result = [];
143+
$result["header"] = json_decode(base64_decode($paths[0]), true);
144+
$result["payload"] = json_decode(base64_decode($paths[1]), true);
145+
return $result;
146+
}
139147
}

0 commit comments

Comments
 (0)