简体   繁体   English

如何在PHP中为OAuth 2生成客户端ID和客户端密钥的唯一令牌?

[英]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.

相关问题 oauth2 通过 db 通过为受信任的 3rd 方客户端提供的客户端 id/secret 获取访问令牌 - oauth2 get access token via db by supplied client id/secret for trusted 3rd party client 用php生成API客户端密钥和客户端密钥 - Generate API Client Key and Client Secret with php 如何在使用OAuth时在Android应用上存储'client_secret'和'client_id'? - how to store 'client_secret' and 'client_id' on Android app when using OAuth? 如何在php中使用oauth令牌和秘密进行推文 - how to tweet using oauth token and secret in php 如何使用Google API PHP客户端获取OAuth2访问令牌? - How to get OAuth2 access token with Google API PHP client? 使用tumblrs官方php客户端获取oauth令牌 - get oauth token with tumblrs official php client 无法通过uber api授权,我有server_token,client_id和client_secret,如何发送请求? - Can not authorization by uber api, I have server_token, client_id and client_secret, how send request? 在iOS + PHP中使用Braintree生成客户端令牌 - Generate client token with braintree in iOS + php Oauth2 和 Laravel - `Client_id` 和 `Client_secret` - 在哪里放置、存储、调用? - Oauth2 & Laravel - `Client_id` & `Client_secret` - where to place, store, call? 在yii2-oauth2-server中需要client_id和client_secret的资源所有者授权类型 - Resource Owner grant type requiring client_id and client_secret in yii2-oauth2-server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM