Updated docs to represent new refactored OAUth system
This commit is contained in:
parent
563ae10217
commit
63f5f923b0
1 changed files with 68 additions and 11 deletions
|
@ -81,6 +81,23 @@ class [PROVIDER NAME] extends OAuth2
|
||||||
*/
|
*/
|
||||||
private $endpoint = '[ENDPOINT API URL]';
|
private $endpoint = '[ENDPOINT API URL]';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $scopes = [
|
||||||
|
// [ARRAY_OF_REQUIRED_SCOPES]
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $user = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $tokens = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -103,12 +120,29 @@ class [PROVIDER NAME] extends OAuth2
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getTokens(string $code): array
|
protected function getTokens(string $code): array
|
||||||
{
|
{
|
||||||
// TODO: Fire request to oauth API to generate access_token
|
if(empty($this->tokens)) {
|
||||||
$accessToken = "[FETCHED ACCESS TOKEN]";
|
// TODO: Fire request to oauth API to generate access_token
|
||||||
|
// Make sure to use '$this->getScopes()' to include all scopes properly
|
||||||
return $accessToken;
|
$this->tokens = "[FETCH TOKEN RESPONSE]";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $refreshToken
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function refreshTokens(string $refreshToken):array
|
||||||
|
{
|
||||||
|
// TODO: Fire request to oauth API to generate access_token using refresh token
|
||||||
|
$this->tokens = "[FETCH TOKEN RESPONSE]";
|
||||||
|
|
||||||
|
return $this->tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,8 +152,10 @@ class [PROVIDER NAME] extends OAuth2
|
||||||
*/
|
*/
|
||||||
public function getUserID(string $accessToken): string
|
public function getUserID(string $accessToken): string
|
||||||
{
|
{
|
||||||
// TODO: Fetch user from oauth API and select the user ID
|
$user = $this->getUser($accessToken);
|
||||||
$userId = "[FETCHED USER ID]";
|
|
||||||
|
// TODO: Pick user ID from $user response
|
||||||
|
$userId = "[USER ID]";
|
||||||
|
|
||||||
return $userId;
|
return $userId;
|
||||||
}
|
}
|
||||||
|
@ -131,8 +167,10 @@ class [PROVIDER NAME] extends OAuth2
|
||||||
*/
|
*/
|
||||||
public function getUserEmail(string $accessToken): string
|
public function getUserEmail(string $accessToken): string
|
||||||
{
|
{
|
||||||
// TODO: Fetch user from oauth API and select the user's email
|
$user = $this->getUser($accessToken);
|
||||||
$userEmail = "[FETCHED USER EMAIL]";
|
|
||||||
|
// TODO: Pick user email from $user response
|
||||||
|
$userEmail = "[USER EMAIL]";
|
||||||
|
|
||||||
return $userEmail;
|
return $userEmail;
|
||||||
}
|
}
|
||||||
|
@ -144,16 +182,35 @@ class [PROVIDER NAME] extends OAuth2
|
||||||
*/
|
*/
|
||||||
public function getUserName(string $accessToken): string
|
public function getUserName(string $accessToken): string
|
||||||
{
|
{
|
||||||
// TODO: Fetch user from oauth API and select the username
|
$user = $this->getUser($accessToken);
|
||||||
$username = "[FETCHED USERNAME]";
|
|
||||||
|
// TODO: Pick username from $user response
|
||||||
|
$username = "[USERNAME]";
|
||||||
|
|
||||||
return $username;
|
return $username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accessToken
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getUser(string $accessToken)
|
||||||
|
{
|
||||||
|
if (empty($this->user)) {
|
||||||
|
// TODO: Fire request to oauth API to get information about users
|
||||||
|
$this->user = "[FETCH USER RESPONSE]";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> If you copy this template, make sure to replace all placeholders wrapped like `[THIS]` and to implement everything marked as `TODO:`.
|
> If you copy this template, make sure to replace all placeholders wrapped like `[THIS]` and to implement everything marked as `TODO:`.
|
||||||
|
|
||||||
|
> If your OAuth2 provider has different endpoints for getting username/email/id, you can fire specific requests from specific get-method, and stop using `getUser` method.
|
||||||
|
|
||||||
Please mention in your documentation what resources or API docs you used to implement the provider's OAuth2 protocol.
|
Please mention in your documentation what resources or API docs you used to implement the provider's OAuth2 protocol.
|
||||||
|
|
||||||
## 3. Test your provider
|
## 3. Test your provider
|
||||||
|
|
Loading…
Reference in a new issue