php - 如何使用开发人员 key 、应用程序 ID 和用户名在 php 中生成 token ?

标签 php key token vidyo

任何人都可以描述我如何使用开发人员 key 、应用程序 ID 和用户名在 php 中生成 token 。 Videoyo只提供html js,他们对php没有任何支持。请提示我。 token 长度为 200 以上。

最佳答案

这里是生成 token 的示例 php 代码。不要忘记将 $DEV_KEY 和 $APP_ID 替换为您的开发人员 key 和应用程序 ID,您可以在 - https://developer.vidyo.io/dashboard 上找到它们。 。 对于用户名,不要添加任何特殊字符,尤其是“@”符号。该代码使用“@”将 appId 附加到用户名,因此如果在用户名中使用它,将会扰乱应用程序 ID 的解码。 对于更短或更长的 token 持续时间,请更改 $expiresInSecs 值。

<!DOCTYPE html>
    <html>
      <head>
        <title>Token Generation php script</title>
      </head>
      <body>
        <p><?php echo "Token Generation Sample <br />";
        $DEV_KEY = "XXXXX" ;            // Copy your dev key from vidyo.io dashboard
        $APP_ID = "XXXXX.vidyo.io" ;    // Copy your app Id from vidyo.io dashboard
        $username = "Batman" ;          // Username, hard coded for debug purposes
        $expiresInSecs = 1000 ;         // Generated token will expire after these many seconds

        // time() by default subtracts datetime(1970, 1, 1) from the datetime
        // on which we call it, therefore the number of seconds is smaller
        // by (pseudocode!) seconds("1970-01-01").
        // In Erlang, on the other hand, we get the actual number of seconds,
        // hence we adjust for this difference here.
        // IMPORTANT! A 64bit architecture is assumed! Otherwise, the timestamp
        // might be stored as a 32bit integer, therefore limiting the "capacity"
        // to 2038 (see https://en.wikipedia.org/wiki/Year_2038_problem).
        $EPOCH_SECONDS = 62167219200 ;
        $expires = $EPOCH_SECONDS + $expiresInSecs + time();

        echo "<br />" ;
        echo "Developer key" . "\t" ."\t" ."\t" . ":" . $DEV_KEY . "<br />" ;
        echo "App ID          : " . $APP_ID . "<br />" ;
        echo "Username        : " . $username . "<br />" ;
        echo "Expires         : " . date("F j, Y, g:i a", $expiresInSecs + time()) . "<br />" ;

        $jid = $username . "@" . $APP_ID ;
        //echo "JID: " . $jid . "<br />" ;

        // Must place \0 within double quotes, not single quotes.
        $body = "provision" . "\0" . $jid . "\0" . $expires . "\0" . "" ;
        echo "BODY: " . $body . "<br />" ;

        // Important to convert to UTF8. I found this is what made the difference.
        $utf8_body = utf8_encode( $body ) ;
        echo "UTF8 BODY: " . $utf8_body . "<br />" ;

        // Ensure the SHA384 Algo is being used.
        $mac_hash = hash_hmac( "sha384", $utf8_body, $DEV_KEY ) ;
        echo "HMAC (384): " . $mac_hash . "<br />" ;

        // Again, ensure \0 are encapsulated with double quotes. Single quotes does not append the null character to the string
        $serialized = $utf8_body . "\0" . $mac_hash ;
        echo "SERIALIZED: " . $serialized . "<br />" ;

        // Base64 Encode the serialized string
        $b64_encoded = base64_encode( $serialized ) ;
        echo "<br /> B64 ENCODED TOKEN :<br /><br />" . $b64_encoded . "<br />" ;
    ?></p>
      </body>
    </html>

关于php - 如何使用开发人员 key 、应用程序 ID 和用户名在 php 中生成 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47278120/

相关文章:

php - 如果用户选择级联的某个选项,则删除带有文本输入的选择标签

php - Laravel Eloquent Join vs Inner Join?

python - PyAutoGui - 按键 X 秒

c# - 为什么 MS Access 2007 不允许行插入,但在下一次插入尝试时允许它?

perl - 如何确定 Perl 哈希是否包含到未定义值的键映射?

php - 如何获取ListView中的数据取决于用户?

php - Laravel: Eloquent all() 不返回对象数组

php - 生成登录 token 的最佳方法是什么?这种身份验证方法是否容易受到攻击?

api - POST token 停止工作 : How could we generate a token passing the grant_type as password? 超过 401 未经授权 - invalid_grant

node.js - 我应该将用户信息放入 JWT token 中,还是只放入用户 ID,然后从数据库中选择信息?