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
1 parent
57bec25
commit ee01af4
Showing
4 changed files
with
73 additions
and
35 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,56 @@ | ||
<?php | ||
/** | ||
* AccessToken | ||
* | ||
* @package Modules\OAuth2 | ||
* @author Partydragen | ||
* @version 2.2.0 | ||
* @license MIT | ||
*/ | ||
class AccessToken { | ||
|
||
private $_data; | ||
private bool $_authorised = false; | ||
private User $_user; | ||
|
||
public function __construct(string $value, string $field = 'access_token') { | ||
$token = DB::getInstance()->get('oauth2_tokens', [$field, $value]); | ||
if ($token->count()) { | ||
$this->_data = $token->first(); | ||
|
||
if (hash_equals($value, $this->_data->access_token)) { | ||
$this->_authorised = true; | ||
} | ||
} | ||
} | ||
|
||
public function exists(): bool { | ||
return (!empty($this->_data)); | ||
} | ||
|
||
public function isAuthorised(): bool { | ||
return $this->_authorised; | ||
} | ||
|
||
public function hasScope(string $scope): bool { | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the NamelessMC User that belong to this access token. | ||
* | ||
* @return User NamelessMC User that belong to this access token | ||
*/ | ||
public function user(): User { | ||
return $this->_user ??= new User($this->data()->user_id); | ||
} | ||
|
||
/** | ||
* Get the access token data. | ||
* | ||
* @return object Get the access token data. | ||
*/ | ||
public function data(): object { | ||
return $this->_data; | ||
} | ||
} |
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