sfelix-martins /
passport-multiauth
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace SMartins\PassportMultiauth; |
||||||
| 4 | |||||||
| 5 | use Laravel\Passport\Token; |
||||||
| 6 | use Illuminate\Container\Container; |
||||||
| 7 | use Laravel\Passport\PersonalAccessTokenResult; |
||||||
| 8 | use Laravel\Passport\PersonalAccessTokenFactory; |
||||||
| 9 | use Laravel\Passport\HasApiTokens as BaseHasApiTokens; |
||||||
| 10 | use SMartins\PassportMultiauth\Config\AuthConfigHelper; |
||||||
| 11 | use SMartins\PassportMultiauth\Exceptions\MissingConfigException; |
||||||
| 12 | |||||||
| 13 | trait HasMultiAuthApiTokens |
||||||
| 14 | { |
||||||
| 15 | use BaseHasApiTokens; |
||||||
| 16 | |||||||
| 17 | /** |
||||||
| 18 | * Get all of the access tokens for the user relating with Provider. |
||||||
| 19 | * |
||||||
| 20 | * @return \Illuminate\Database\Eloquent\Collection |
||||||
| 21 | */ |
||||||
| 22 | 2 | public function tokens() |
|||||
| 23 | { |
||||||
| 24 | 2 | return $this->hasMany(Token::class, 'user_id') |
|||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 25 | ->join('oauth_access_token_providers', function ($join) { |
||||||
| 26 | 2 | $join->on( |
|||||
| 27 | 2 | 'oauth_access_tokens.id', '=', 'oauth_access_token_id' |
|||||
| 28 | 2 | )->where('oauth_access_token_providers.provider', '=', AuthConfigHelper::getUserProvider($this)); |
|||||
|
0 ignored issues
–
show
$this of type SMartins\PassportMultiauth\HasMultiAuthApiTokens is incompatible with the type Illuminate\Contracts\Auth\Authenticatable expected by parameter $user of SMartins\PassportMultiau...lper::getUserProvider().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 29 | 2 | })->orderBy('created_at', 'desc') |
|||||
| 30 | 1 | ->select('oauth_access_tokens.*') |
|||||
| 31 | 1 | ->get(); |
|||||
| 32 | } |
||||||
| 33 | |||||||
| 34 | /** |
||||||
| 35 | * Create a new personal access token for the user and create . |
||||||
| 36 | * |
||||||
| 37 | * @param string $name |
||||||
| 38 | * @param array $scopes |
||||||
| 39 | * @return PersonalAccessTokenResult |
||||||
| 40 | * @throws MissingConfigException |
||||||
| 41 | */ |
||||||
| 42 | 4 | public function createToken($name, array $scopes = []) |
|||||
| 43 | { |
||||||
| 44 | // Backup default provider |
||||||
| 45 | 4 | $defaultProvider = config('auth.guards.api.provider'); |
|||||
| 46 | |||||||
| 47 | 4 | $userProvider = AuthConfigHelper::getUserProvider($this); |
|||||
|
0 ignored issues
–
show
$this of type SMartins\PassportMultiauth\HasMultiAuthApiTokens is incompatible with the type Illuminate\Contracts\Auth\Authenticatable expected by parameter $user of SMartins\PassportMultiau...lper::getUserProvider().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 48 | |||||||
| 49 | // Change config to when the token is created set the provider from model creating the token. |
||||||
| 50 | 3 | config(['auth.guards.api.provider' => $userProvider]); |
|||||
| 51 | |||||||
| 52 | 3 | $token = Container::getInstance()->make(PersonalAccessTokenFactory::class)->make( |
|||||
| 53 | 3 | $this->getKey(), $name, $scopes |
|||||
|
0 ignored issues
–
show
It seems like
getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 54 | ); |
||||||
| 55 | |||||||
| 56 | // Reset config to defaults |
||||||
| 57 | 3 | config(['auth.guards.api.provider' => $defaultProvider]); |
|||||
| 58 | |||||||
| 59 | 3 | return $token; |
|||||
| 60 | } |
||||||
| 61 | } |
||||||
| 62 |