Skip to content

Feature Request: Support String-based Client ID #469

@edmandiesamonte

Description

@edmandiesamonte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions