-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: David Regimbal <dave@bitboss.org>
- Loading branch information
1 parent
cc913d2
commit 9f904a6
Showing
4 changed files
with
83 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace OpenXBL; | ||
|
||
use GuzzleHttp\Client as GuzzleClient; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use OpenXBL\Models\ClaimsResponse; | ||
|
||
class Auth extends GuzzleClient | ||
{ | ||
private string $publicKey; | ||
private string $baseUrl = 'https://xbl.io/app/'; | ||
|
||
public function __construct(string $publicKey) | ||
{ | ||
$this->publicKey = $publicKey; | ||
parent::__construct([ | ||
'base_uri' => $this->baseUrl, | ||
]); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
*/ | ||
public function claim(string $code): ClaimsResponse | ||
{ | ||
$options = [ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
], | ||
'json' => [ | ||
'code' => $code, | ||
'app_key' => $this->publicKey, | ||
], | ||
]; | ||
|
||
$request = $this->request('POST', 'claim', $options); | ||
|
||
return new ClaimsResponse((string) $request->getBody()); | ||
} | ||
|
||
public function getLoginUrl(): string | ||
{ | ||
return "https://xbl.io/app/auth/{$this->publicKey}"; | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace OpenXBL\Models; | ||
|
||
class ClaimsResponse | ||
{ | ||
public string $appKey; | ||
public string $xuid; | ||
public string $gamertag; | ||
public string $email; | ||
public ?string $avatar = null; | ||
|
||
public function __construct(string $json) { | ||
$json = json_decode($json, true); | ||
foreach ($json as $key => $value) { | ||
if (property_exists(__CLASS__, $key)) { | ||
$this->$key = $value; | ||
} | ||
} | ||
} | ||
} |