Passport: How to create token (password grant) for special user (without password)

Created on 17 Jan 2018  ·  12Comments  ·  Source: laravel/passport

Hi, everyone!
First, sorry if such issue is already was. And sorry for my English...
I am newer at laravel and I like it.
Now I learning how to create REST API app and for this I use laravel/passport.
And my target is to make social networks authorize via API. How it should work:

  1. Client app, for example - mobile app, must send me (my app at laravel) request with Google token (for example).
  2. From receive token I get the data about user, save it or find already existent.
  3. After that I must send a token (from my app, not Google one), refresh token and expires_at.

Of course in normal api auth I use password_grant where you must do request with login and password, and it generate token, refresh token,expires_at. But how to do it if you have not password? How to create token, refresh token and expires_at for special user?
I know about personal tokens, but it only 'longlive' token? It make no sense! Why is not exist personal token that go with refresh token and expires_at or password token where you can create it directly?
Is there are some right solution? Will be solution in a future version of laravel/passport?

I will be very thankful if you can advise some really good solution.

Most helpful comment

All 12 comments

exact same problem here

@makz maybe this can help you: passport-social-grant

@makz maybe this can help you: https://github.com/laravel/passport/issues/71#issuecomment-330506407

Closing this issue because it's already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue.

want to generate the token without password for the third party or api using email only....

To create token without password you can use validateForPassportPasswordGrant() method in User model, it will override credentials check, now to work without password just return true inside the function.

 public function validateForPassportPasswordGrant($password)
    {
        return true;
    }

It's in the laravel docs.

To create token without password you can use validateForPassportPasswordGrant() method in User model, it will override credentials check, now to work without password just return true inside the function.

 public function validateForPassportPasswordGrant($password)
    {
        return true;
    }

It's in the laravel docs.

Thanks for this, but what if i want to create tokens with and without password?

To create token without password you can use validateForPassportPasswordGrant() method in User model, it will override credentials check, now to work without password just return true inside the function.

 public function validateForPassportPasswordGrant($password)
    {
        return true;
    }

It's in the laravel docs.

Thanks for this, but what if i want to create tokens with and without password?

Then you can put some conditions inside the function to do that.

To create token without password you can use validateForPassportPasswordGrant() method in User model, it will override credentials check, now to work without password just return true inside the function.

 public function validateForPassportPasswordGrant($password)
    {
        return true;
    }

It's in the laravel docs.

Thanks for this, but what if i want to create tokens with and without password?

Then you can put some conditions inside the function to do that.

You can't put conditions here because the only field you can access inside this function is the password

To create token without password you can use validateForPassportPasswordGrant() method in User model, it will override credentials check, now to work without password just return true inside the function.

 public function validateForPassportPasswordGrant($password)
    {
        return true;
    }

It's in the laravel docs.

Thanks for this, but what if i want to create tokens with and without password?

Then you can put some conditions inside the function to do that.

You can't put conditions here because the only field you can access inside this function is the password

You have access to $this!

To create token without password you can use validateForPassportPasswordGrant() method in User model, it will override credentials check, now to work without password just return true inside the function.

 public function validateForPassportPasswordGrant($password)
    {
        return true;
    }

It's in the laravel docs.

Thanks for this, but what if i want to create tokens with and without password?

Then you can put some conditions inside the function to do that.

You can't put conditions here because the only field you can access inside this function is the password

You have access to $this!

We still don't have access to any custom params inside this method, that we could have passed in the token POST request to obtain access token.

Was this page helpful?
0 / 5 - 0 ratings