[英]How to generate unique token for Client Id & Client Secret for OAuth 2 in PHP?
I'm working on an OAuth Server in PHP. 我正在使用PHP中的OAuth服务器。 Currently using PHP Library
http://bshaffer.github.io/oauth2-server-php-docs/
for it. 目前正在使用PHP库
http://bshaffer.github.io/oauth2-server-php-docs/
。 Till now everything has been clear. 直到现在一切都很清楚。 Just want to know how to create the unique token for Client Id & Client Secret in PHP.
只想知道如何在PHP中为Client Id和Client Secret创建唯一令牌。
Now, I'm using the following piece of code for creating Client Id & Client Secret token. 现在,我正在使用以下代码来创建客户端ID和客户端密钥令牌。
$token = bin2hex(random_bytes($length));
But, a little bit confuses. 但是,有点混乱。 whether, Is it a right way to do this thing or not?
是否,这是否是做这件事的正确方法? I also searched for any library to do this.
我还搜索了任何库来执行此操作。 But, didn't get one.
但是,没有得到一个。
For PHP 5 >= 5.3.0, PHP 7 对于PHP 5> = 5.3.0,PHP 7
Use openssl_random_pseudo_bytes 使用openssl_random_pseudo_bytes
$client_secret = bin2hex(openssl_random_pseudo_bytes(32));
There is also an article about OAuth 2.0 Client SecretID The Client ID and Secret 还有一篇关于OAuth 2.0 Client SecretID 的文章客户ID和秘密
For PHP 7 Use random_bytes 对于PHP 7使用random_bytes
$client_secret = bin2hex(random_bytes(32));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.