如何从JWT电子邮件中获取价值

时间:2019-03-07 13:08:40

标签: php jwt dialogflow

在我的对话框中创建预订表助手。 要按用户获取信息,他需要使用google登录,以便在完成对话后我将采用用户的uderId值。 我使用jose-php库这样:

header( 'Access-Control-Allow-Headers: *' );
header( 'Access-Control-Allow-Origin: *' );
header( "Access-Control-Allow-Credentials: true" );
header( 'Content-Type: application/json' );

include('../phpseclib/Net/SSH2.php');
include('../JOSE/JWT.php');
include('../JOSE/URLSafeBase64.php');
$jwt_string = 'userIdtoken';
$jwt = JOSE_JWT::decode($jwt_string);
echo $jwt['JOSE_JWT']['Claims']['email'];

问题是我收到错误的打印电子邮件值的提示! 我怎么能得到它?

$ jwt值的结果如下:

JOSE_JWT Object
(
    [header] => Array
        (
            [alg] => RS256
            [kid] => cf022a49e9786148ad0e379cc854844e36c3edc1
            [typ] => JWT
        )

    [claims] => Array
        (
            [iss] => https://accounts.google.com
            [nbf] => 1551435957967
            [aud] => 284549458086-fdoluk70pqkcuh8vj4tj1dou15v444tiua.apps.googleusercontent.com
            [sub] => 1092379345381822971290339
            [email] => dasdasddas@gmail.com
            [email_verified] => 1
            [name] => frank rossi
            [picture] => https://lh4.googleusercontent.com/-79eVyjn_YU8/AAAAAAAAAAI/AAAAAAAAPBs/uvq_fruLiB0/s96-c/photo.jpg
            [given_name] => Federico
            [family_name] => Idsfdsfdsf
            [iat] => 1545351958267
            [exp] => 155143534961867
            [jti] => 428254345532cddf49dec17d24ace2e6f45f8af4b14b2
        )

    [signature] => 'somthing'
    [raw] => 'somthing'
)

1 个答案:

答案 0 :(得分:0)

在我看来,这个问题是错字。您写了$jwt['JOSE_JWT']['Claims']['email'];,但是密钥是claims,而不是Claims

此外,$jwt似乎是类JOSE_JWT的对象,而不是数组。因此,不可能像这样将其与下标运算符一起使用。您应该改为访问其属性:

$jwt->claims['email']