简体   繁体   中英

How to generate unique token for Client Id & Client Secret for OAuth 2 in PHP?

I'm working on an OAuth Server in PHP. Currently using PHP Library http://bshaffer.github.io/oauth2-server-php-docs/ for it. Till now everything has been clear. Just want to know how to create the unique token for Client Id & Client Secret in PHP.

Now, I'm using the following piece of code for creating Client Id & Client Secret token.

$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

Use 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

For PHP 7 Use random_bytes

$client_secret = bin2hex(random_bytes(32));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM