Skip to content

Commit 40f5ead

Browse files
committed
✨ Create GithubProvider
1 parent 93396f9 commit 40f5ead

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Auth\OAuth\League;
6+
7+
use Tempest\Auth\OAuth\DataObjects\OAuthUserData;
8+
9+
final class GithubProvider
10+
{
11+
use IsOauthProvider;
12+
13+
public function configure(
14+
string $clientId,
15+
string $clientSecret,
16+
string $redirectUri,
17+
?array $defaultScopes = null,
18+
string $stateSessionSlug = 'oauth-state'
19+
): self
20+
{
21+
$this->defaultScopes = $defaultScopes ??= ['user:email'];
22+
$this->authorizeEndpoint = 'https://github.com/login/oauth/authorize';
23+
$this->accessTokenEndpoint = 'https://github.com/login/oauth/access_token';
24+
$this->userDataEndpoint = 'https://api.github.com/user';
25+
26+
return $this->configureInternalProvider(
27+
clientId: $clientId,
28+
clientSecret: $clientSecret,
29+
defaultScopes: $defaultScopes,
30+
redirectUri: $redirectUri,
31+
authorizeEndpoint: $this->authorizeEndpoint,
32+
accessTokenEndpoint: $this->accessTokenEndpoint,
33+
userDataEndpoint: $this->userDataEndpoint,
34+
stateSessionSlug: $stateSessionSlug
35+
);
36+
}
37+
38+
/**
39+
* @inheritDoc
40+
*/
41+
protected function createUserDataFromResponse(array $userData): OAuthUserData
42+
{
43+
return new OAuthUserData(
44+
id: $userData['id'] ?? null,
45+
nickname: $userData['login'] ?? null,
46+
name: $userData['name'] ?? null,
47+
email: $userData['email'] ?? null,
48+
avatar: $userData['avatar_url'] ?? null,
49+
rawData: $userData
50+
);
51+
}
52+
}

0 commit comments

Comments
 (0)