Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support String-based Client ID #469

Closed
edmandiesamonte opened this issue Aug 12, 2017 · 4 comments
Closed

Feature Request: Support String-based Client ID #469

edmandiesamonte opened this issue Aug 12, 2017 · 4 comments

Comments

@edmandiesamonte
Copy link

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.

@emiliopedrollo
Copy link

There has been some effort before in using uuid as client_id. Maybe the developers should consider that.

@cweiske
Copy link
Contributor

cweiske commented Feb 8, 2018

Duplicate of #14.

@mloberg
Copy link

mloberg commented Aug 17, 2018

You can achieve UUIDs by updating the migration and using model listeners. https://mlo.io/blog/2018/08/17/laravel-passport-uuid/

@driesvints
Copy link
Member

Duplicate of #14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants