-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new updates connected account interface and implementation
- Loading branch information
Joel Butcher
committed
Mar 2, 2021
1 parent
c5f4e08
commit 368268a
Showing
6 changed files
with
93 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace JoelButcher\Socialstream\Contracts; | ||
|
||
use JoelButcher\Socialstream\ConnectedAccount; | ||
use Laravel\Socialite\Contracts\User; | ||
|
||
interface UpdatesConnectedAccounts | ||
{ | ||
/** | ||
* Update a given connected account. | ||
* | ||
* @param mixed $user | ||
* @param \JoelButcher\Socialstream\ConnectedAccount $connectedAccount | ||
* @param string $provider | ||
* @param \Laravel\Socialite\Contracts\User $providerUser | ||
* @return \JoelButcher\Socialstream\ConnectedAccount | ||
*/ | ||
public function update($user, ConnectedAccount $connectedAccount, string $provider, User $providerUser); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Actions\Socialstream; | ||
|
||
use Illuminate\Support\Facades\Gate; | ||
use JoelButcher\Socialstream\ConnectedAccount; | ||
use JoelButcher\Socialstream\Contracts\UpdatesConnectedAccounts; | ||
use Laravel\Socialite\Contracts\User; | ||
|
||
class UpdateConnectedAccount implements UpdatesConnectedAccounts | ||
{ | ||
/** | ||
* Update a given connected account. | ||
* | ||
* @param mixed $user | ||
* @param \JoelButcher\Socialstream\ConnectedAccount $connectedAccount | ||
* @param string $provider | ||
* @param \Laravel\Socialite\Contracts\User $providerUser | ||
* @return \JoelButcher\Socialstream\ConnectedAccount | ||
*/ | ||
public function update($user, ConnectedAccount $connectedAccount, string $provider, User $providerUser) | ||
{ | ||
Gate::forUser($user)->authorize('update', $connectedAccount); | ||
|
||
$connectedAccount->forceFill([ | ||
'provider' => strtolower($provider), | ||
'provider_id' => $providerUser->getId(), | ||
'name' => $providerUser->getName(), | ||
'nickname' => $providerUser->getNickname(), | ||
'email' => $providerUser->getEmail(), | ||
'avatar_path' => $providerUser->getAvatar(), | ||
'token' => $providerUser->token, | ||
'secret' => $providerUser->tokenSecret ?? null, | ||
'refresh_token' => $providerUser->refreshToken ?? null, | ||
'expires_at' => property_exists($providerUser, 'expiresIn') ? now()->addSeconds($providerUser->expiresIn) : null, | ||
])->save(); | ||
|
||
return $connectedAccount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters