Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/LogtoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,23 @@ function getIdToken(): ?string
*/
function getIdTokenClaims(): IdTokenClaims
{
return new IdTokenClaims(...json_decode(base64_decode(explode('.', $this->getIdToken())[1]), true));
$playload = explode('.', $this->getIdToken())[1] ?? null;
if (empty($playload)) throw new \Exception("Invalid Playload data");

// 解决编码标准不一致的问题: (RFC 4648 §5) 与标准 Base64 (RFC 4648 §4)

// 1. 替换字符 (- -> +, _ -> /)
$data = strtr($playload, '-_', '+/');

// 2. 补全填充 (=)
$mod = strlen($data) % 4;
if ($mod > 0) {
$data .= str_repeat('=', 4 - $mod);
}

$playloadDecode = base64_decode($data, true);

return new IdTokenClaims(...json_decode($playloadDecode, true));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only fixes base64url decoding for ID tokens. getAccessTokenClaims() still uses raw base64_decode() on the JWT payload, so valid access tokens that need URL-safe normalization or padding will still fail. Please extract this decode logic into a shared helper and reuse it for both token-claim paths.

}

/**
Expand Down