Files
fdesk/app/common/utils/OauthClients.php
T
2025-07-01 19:39:13 +08:00

27 lines
841 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\common\utils;
class OauthClients
{
/**
* 生成 OAuth2 client 凭证
*
* @param int $idBytes 用于生成 client_id 的随机字节长度(最终 hex 长度 = $idBytes * 2)
* @param int $secretBytes 用于生成 client_secret 的随机字节长度(最终 hex 长度 = $secretBytes * 2)
* @return array ['client_id' => string, 'client_secret' => string]
*/
public function generateClientCredentials(int $idBytes = 16, int $secretBytes = 32): array
{
// 生成随机字节,并转为十六进制字符串
$clientId = bin2hex(random_bytes($idBytes));
$clientSecret = bin2hex(random_bytes($secretBytes));
return [
'client_id' => $clientId,
'client_secret' => $clientSecret,
];
}
}