-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 633d0b2
Showing
6 changed files
with
233 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
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,31 @@ | ||
{ | ||
"name": "tjarksaul/oauth2-dlrg", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Tjark Saul" | ||
} | ||
], | ||
"keywords": [ | ||
"oauth", | ||
"oauth2", | ||
"client", | ||
"authorization", | ||
"authentication", | ||
"dlrg.net" | ||
], | ||
"require": { | ||
"php": "^5.6 || ^7.0", | ||
"league/oauth2-client": "^2.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"League\\OAuth2\\Client\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"League\\OAuth2\\Client\\Test\\": "tests/src/" | ||
} | ||
} | ||
} |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,19 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Client\Provider; | ||
|
||
class AppSecretProof | ||
{ | ||
/** | ||
* The app secret proof to sign requests made to the Graph API | ||
* @see https://developers.facebook.com/docs/graph-api/securing-requests#appsecret_proof | ||
* | ||
* @param string $appSecret | ||
* @param string $accessToken | ||
* @return string | ||
*/ | ||
public static function create($appSecret, $accessToken) | ||
{ | ||
return hash_hmac('sha256', $accessToken, $appSecret); | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Client\Provider; | ||
|
||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; | ||
use League\OAuth2\Client\Token\AccessToken; | ||
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class Dlrg extends AbstractProvider { | ||
use BearerAuthorizationTrait; | ||
|
||
/** | ||
* @const string | ||
*/ | ||
const BASE_DLRG_URL = 'https://dlrg.net/oauth2'; | ||
|
||
const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'sub'; | ||
|
||
/** | ||
* @param array $options | ||
* @param array $collaborators | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function __construct($options = [], array $collaborators = []) { | ||
parent::__construct($options, $collaborators); | ||
} | ||
|
||
public function getBaseAuthorizationUrl() { | ||
return static::BASE_DLRG_URL . '/authorize'; | ||
} | ||
|
||
public function getBaseAccessTokenUrl(array $params) { | ||
return static::BASE_DLRG_URL . '/token'; | ||
} | ||
|
||
public function getDefaultScopes() { | ||
return ['profile', 'email']; | ||
} | ||
|
||
public function getScopeSeparator() { | ||
return ' '; | ||
} | ||
|
||
public function getResourceOwnerDetailsUrl(AccessToken $token) { | ||
return static::BASE_DLRG_URL . '/userinfo'; | ||
} | ||
|
||
protected function createResourceOwner(array $response, AccessToken $token) { | ||
return new DlrgUser($response); | ||
} | ||
|
||
protected function checkResponse(ResponseInterface $response, $data) { | ||
var_dump($data); | ||
if (!empty($data['error'])) { | ||
$message = $data['error'] . ': ' . $data['error_description']; | ||
throw new IdentityProviderException($message, 42, $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Client\Provider; | ||
|
||
class DlrgUser implements ResourceOwnerInterface { | ||
/** | ||
* @var array | ||
*/ | ||
protected $data; | ||
|
||
/** | ||
* @param array $response | ||
*/ | ||
public function __construct(array $response) { | ||
$this->data = $response; | ||
} | ||
|
||
/** | ||
* Returns the ID for the user as a string if present. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getId() { | ||
return $this->getField('sub'); | ||
} | ||
|
||
/** | ||
* Returns the name for the user as a string if present. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getName() { | ||
return $this->getField('name'); | ||
} | ||
|
||
/** | ||
* Returns the first name for the user as a string if present. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getFirstName() { | ||
return $this->getField('given_name'); | ||
} | ||
|
||
/** | ||
* Returns the last name for the user as a string if present. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getLastName() { | ||
return $this->getField('family_name'); | ||
} | ||
|
||
/** | ||
* Returns the email for the user as a string if present. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getEmail() { | ||
return $this->getField('email'); | ||
} | ||
|
||
/** | ||
* Returns if the user's email has been verified | ||
* | ||
* @return boolean | ||
*/ | ||
public function isEmailVerified() { | ||
return !!$this->getField('email_verified'); | ||
} | ||
|
||
/** | ||
* Returns the preferred username for the user as a string if present. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getPreferredUsername() { | ||
return $this->getField('preferred_username'); | ||
} | ||
|
||
/** | ||
* Returns all the data obtained about the user. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() { | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* Returns a field from the Graph node data. | ||
* | ||
* @param string $key | ||
* | ||
* @return mixed|null | ||
*/ | ||
private function getField($key) { | ||
return isset($this->data[$key]) ? $this->data[$key] : null; | ||
} | ||
} |