-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try to complete oauth sign in method
- Loading branch information
Showing
10 changed files
with
105 additions
and
82 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
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,33 @@ | ||
<?php | ||
|
||
namespace LaravelAuthPro\Credentials; | ||
|
||
use LaravelAuthPro\Contracts\Credentials\OAuthCredentialInterface; | ||
use LaravelAuthPro\Enums\AuthIdentifierType; | ||
|
||
class OAuthCredential extends AuthCredential implements OAuthCredentialInterface | ||
{ | ||
protected ?string $driver; | ||
protected ?string $email; | ||
protected ?string $idToken; | ||
|
||
public function getSupportedIdentifiersTypes(): array | ||
{ | ||
return [AuthIdentifierType::EMAIL]; | ||
} | ||
|
||
public function getEmail(): string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function getIdToken(): string | ||
{ | ||
return $this->idToken; | ||
} | ||
|
||
public function getDriver(): string | ||
{ | ||
return $this->driver; | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace LaravelAuthPro\Model; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class UserAuthProvider extends Model | ||
{ | ||
protected $casts = [ | ||
'payload' => 'json' | ||
]; | ||
} |
This file was deleted.
Oops, something went wrong.
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 LaravelAuthPro\Providers; | ||
|
||
use Laravel\Socialite\Facades\Socialite; | ||
use LaravelAuthPro\Contracts\AuthenticatableInterface; | ||
use LaravelAuthPro\Contracts\Providers\OAuthProviderInterface; | ||
use LaravelAuthPro\Enums\AuthIdentifierType; | ||
use LaravelAuthPro\Enums\AuthProviderSignInMethod; | ||
use LaravelAuthPro\Enums\AuthProviderType; | ||
|
||
class OAuthProvider extends AuthProvider implements OAuthProviderInterface | ||
{ | ||
public const ID = 'oauth'; | ||
public const TYPE = AuthProviderType::OAUTH; | ||
public const IDENTIFIER_TYPE = AuthIdentifierType::EMAIL; | ||
public const SUPPORTED_SIGN_IN_METHODS = [ | ||
AuthProviderSignInMethod::OAUTH, | ||
]; | ||
|
||
public function createUserWithIdToken(string $driver, string $idToken): AuthenticatableInterface | ||
{ | ||
$user = Socialite::driver($driver) | ||
->userFromToken($idToken); | ||
|
||
$authenticatable = $this->createAuthenticatable($user->getEmail()); | ||
|
||
$authenticatable->authProviders() | ||
->create([ | ||
'provider_type' => static::TYPE, | ||
'provider_id' => static::ID . '.' . $driver, | ||
'payload' => [ | ||
'id' => $user->getId(), | ||
'extra' => $user->getRaw() | ||
] | ||
]); | ||
|
||
return $authenticatable; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.