-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
207 additions
and
0 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 |
---|---|---|
|
@@ -166,6 +166,7 @@ parameters: | |
src/Spotify: '[email protected]:SocialiteProviders/Spotify.git' | ||
src/StackExchange: '[email protected]:SocialiteProviders/StackExchange.git' | ||
src/Starling: '[email protected]:SocialiteProviders/Starling.git' | ||
src/StartGg: '[email protected]:SocialiteProviders/StartGg.git' | ||
src/Steam: '[email protected]:SocialiteProviders/Steam.git' | ||
src/Steem: '[email protected]:SocialiteProviders/Steem.git' | ||
src/StockTwits: '[email protected]:SocialiteProviders/StockTwits.git' | ||
|
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,99 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\StartGg; | ||
|
||
use GuzzleHttp\RequestOptions; | ||
use Illuminate\Support\Arr; | ||
use SocialiteProviders\Manager\OAuth2\AbstractProvider; | ||
use SocialiteProviders\Manager\OAuth2\User; | ||
|
||
/** | ||
* @see https://dev.start.gg/docs/oauth/oauth-overview | ||
*/ | ||
class Provider extends AbstractProvider | ||
{ | ||
public const IDENTIFIER = 'STARTGG'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopes = [ | ||
'user.identity', | ||
'user.email', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopeSeparator = ' '; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getAuthUrl($state): string | ||
{ | ||
return $this->buildAuthUrlFromBase( | ||
'https://start.gg/oauth/authorize', | ||
$state | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenUrl(): string | ||
{ | ||
return 'https://api.start.gg/oauth/access_token'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getUserByToken($token): array | ||
{ | ||
$response = $this->getHttpClient()->post( | ||
'https://api.start.gg/gql/alpha', | ||
[ | ||
RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => 'Bearer ' . $token, | ||
], | ||
RequestOptions::FORM_PARAMS => [ | ||
'query' => 'query { | ||
currentUser { | ||
discriminator | ||
id | ||
images (type: "profile") { | ||
url | ||
} | ||
name | ||
player { | ||
gamerTag | ||
} | ||
} | ||
}' | ||
], | ||
] | ||
); | ||
|
||
$response = json_decode((string) $response->getBody(), true); | ||
|
||
return $response['data']['currentUser']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function mapUserToObject(array $user): User | ||
{ | ||
return (new User())->setRaw($user)->map([ | ||
'id' => $user['id'], | ||
'nickname' => Arr::get($user, 'player.gamerTag'), | ||
'name' => Arr::get($user, 'name'), | ||
'email' => Arr::get($user, 'email'), | ||
'avatar' => Arr::get($user, 'images.0.url'), | ||
'discriminator' => $user['discriminator'], | ||
]); | ||
} | ||
} |
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,55 @@ | ||
# Start.gg | ||
|
||
```bash | ||
composer require socialiteproviders/startgg | ||
``` | ||
|
||
## Installation & Basic Usage | ||
|
||
Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below. | ||
|
||
### Add configuration to `config/services.php` | ||
|
||
```php | ||
'startgg' => [ | ||
'client_id' => env('STARTGG_CLIENT_ID'), | ||
'client_secret' => env('STARTGG_CLIENT_SECRET'), | ||
'redirect' => env('STARTGG_REDIRECT_URI') | ||
], | ||
``` | ||
|
||
### Add provider event listener | ||
|
||
Configure the package's listener to listen for `SocialiteWasCalled` events. | ||
|
||
Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions. | ||
|
||
```php | ||
protected $listen = [ | ||
\SocialiteProviders\Manager\SocialiteWasCalled::class => [ | ||
// ... other providers | ||
\SocialiteProviders\StartGg\StartGgExtendSocialite::class.'@handle', | ||
], | ||
]; | ||
``` | ||
|
||
### Usage | ||
|
||
You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed): | ||
|
||
```php | ||
return Socialite::driver('startgg')->redirect(); | ||
``` | ||
|
||
### Returned User fields | ||
|
||
- ``id`` | ||
- ``nickname`` | ||
- ``name`` | ||
- ``email`` | ||
- ``avatar`` | ||
- ``discriminator`` (Uniquely identifying token for user) | ||
|
||
### Reference | ||
|
||
- [Start.gg Developer Portal](https://dev.start.gg/docs/oauth/oauth-overview) |
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,18 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\StartGg; | ||
|
||
use SocialiteProviders\Manager\SocialiteWasCalled; | ||
|
||
class StartGgExtendSocialite | ||
{ | ||
/** | ||
* Register the provider. | ||
* | ||
* @param \SocialiteProviders\Manager\SocialiteWasCalled $socialiteWasCalled | ||
*/ | ||
public function handle(SocialiteWasCalled $socialiteWasCalled) | ||
{ | ||
$socialiteWasCalled->extendSocialite('startgg', Provider::class); | ||
} | ||
} |
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,34 @@ | ||
{ | ||
"name": "socialiteproviders/startgg", | ||
"description": "Start.gg OAuth2 Provider for Laravel Socialite", | ||
"license": "MIT", | ||
"keywords": [ | ||
"laravel", | ||
"oauth", | ||
"provider", | ||
"socialite", | ||
"start.gg" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Nick Been", | ||
"email": "[email protected]", | ||
"homepage": "https://nickbeen.nl" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/socialiteproviders/providers/issues", | ||
"source": "https://github.com/socialiteproviders/providers", | ||
"docs": "https://socialiteproviders.com/startgg" | ||
}, | ||
"require": { | ||
"php": "^8.0", | ||
"ext-json": "*", | ||
"socialiteproviders/manager": "^4.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SocialiteProviders\\StartGg\\": "" | ||
} | ||
} | ||
} |