-
Notifications
You must be signed in to change notification settings - Fork 796
Closed
Description
Just a feature request to support string-based Client ID. IMHO, having an auto-incremented Client ID is pretty plain and might lead to security vulnerability (i.e. brute-force attack on implicit grants).
I would suggest to have something like this on the Client Model:
static::creating(function (Client $client) {
if (!$client->id) {
$client->id = Passport::generateClientId($client->name);
}
});
And have something like this on the Passport helper:
/**
* Generates Client ID
*
* @param $clientName
* @return string
*/
public static function generateClientId($clientName)
{
if (static::$clientIdGenerator instanceof \Closure) {
return (string)static::$clientIdGenerator->call(new static, $clientName);
}
$length = config('passport.id_length', 12);
$max = pow(10, $length) - 1;
if ($max > PHP_INT_MAX) {
$max = PHP_INT_MAX;
}
$out = random_int(0, $max);
return str_pad($out, $length, '0', STR_PAD_LEFT);
}
/**
* Set the Client ID Generator function. The function should receive a Client Name
* and return an ID in string format.
*
* @param \Closure $generator
*/
public static function setClientIdGenerator(\Closure $generator)
{
static::$clientIdGenerator = $generator;
}
I'd be happy to create a PR request if this one is planned.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels