问题
I need to validate extra fields in my users
table before i create the requested tokens, but i can't find a simple way to do it with Passport
.
I find similar workarunds which returns a token using $user->createToken()
but i can't find someone covering all default /oauth/token
options like the refresh_token
Also i see Passport
have some simple ways to customize the username column and the password validation but i think this not cover my neededs.
Update
Im not sure if this is the best solution but in Laravel 5.8
the passport
package have this validateForPassportPasswordGrant()
function which allow you to add some extra conditionals before allowing the authentication process to get completed.
class User extends Authenticatable
{
public function validateForPassportPasswordGrant($password)
{
if ($this->active != true) {
throw OAuthServerException::accessDenied('The account is not active');
}
return Hash::check($password, $this->password);
}
}
回答1:
In your login method
if (Auth::attempt(['email' => $request->email, 'password' => $request->password, 'is_active' => 1, 'username' => $request->username])) {
// create a token here
}
来源:https://stackoverflow.com/questions/56614651/laravel-passport-custom-validation-for-any-oauth-token-request