JWT 解码包括不需要的 html 标签
JWT decode includes unwanted html tags
我使用以下 php 函数来 return jwt 的有效负载中的 'uid' 声明的值:
function isLoggedIn($headers)
{
$ret = false;
if (!empty($headers['Authorization']))
{
$parts = explode('.', $headers['Authorization']);
echo base64_decode($parts[1]);
return 7; //currently set a 7 just function
}
}
return 中的字符串
echo base64_decode($parts[1]);
包含 html 个标签
<br />"iss": "www.thetenticle.com",<br />"iat": "1449405778",<br />"nbf": "1449405838",<br />"exp": "1449492238",<br />"uid": "batman"<br />}
我不想要这个,因为我需要找出 'uid' 的值是什么。
我做错了什么?
ps 我知道处理 jwt 比这更多,但现在我只需要获取登录用户的 ID。
我基本上需要一系列声明
来自另一个 SO:
The problem is related to the fact that the base64 alphabet is not URL-safe. In this particular case, your base64-encoded string contains a +, which is interpreted as a space.
来自 php-jwt 的安全解码输入的代码:
public static function urlsafeB64Decode($input) {
$remainder = strlen($input) % 4;
if($remainder) {
$padlen = 4 - $remainder;
$input .= str_repeat('=', $padlen);
}
return base64_decode(strtr($input, '-_', '+/'));
}
我使用以下 php 函数来 return jwt 的有效负载中的 'uid' 声明的值:
function isLoggedIn($headers)
{
$ret = false;
if (!empty($headers['Authorization']))
{
$parts = explode('.', $headers['Authorization']);
echo base64_decode($parts[1]);
return 7; //currently set a 7 just function
}
}
echo base64_decode($parts[1]);
包含 html 个标签
<br />"iss": "www.thetenticle.com",<br />"iat": "1449405778",<br />"nbf": "1449405838",<br />"exp": "1449492238",<br />"uid": "batman"<br />}
我不想要这个,因为我需要找出 'uid' 的值是什么。 我做错了什么?
ps 我知道处理 jwt 比这更多,但现在我只需要获取登录用户的 ID。
我基本上需要一系列声明
来自另一个
The problem is related to the fact that the base64 alphabet is not URL-safe. In this particular case, your base64-encoded string contains a +, which is interpreted as a space.
来自 php-jwt 的安全解码输入的代码:
public static function urlsafeB64Decode($input) {
$remainder = strlen($input) % 4;
if($remainder) {
$padlen = 4 - $remainder;
$input .= str_repeat('=', $padlen);
}
return base64_decode(strtr($input, '-_', '+/'));
}