forked from SocialConnect/auth
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
THis commit allows to authenticate against the meetup-API. Creating an OAuth-Consumer under https://www.meetup.com/meetup_api/oauth_consumers/ is necessary
- Loading branch information
1 parent
667f542
commit 109015f
Showing
3 changed files
with
127 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
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,108 @@ | ||
<?php | ||
/** | ||
* SocialConnect project | ||
* | ||
* @author: Andreas Heigl https://github.com/heiglandreas <[email protected]> | ||
*/ | ||
|
||
namespace SocialConnect\OAuth2\Provider; | ||
|
||
use SocialConnect\Common\Http\Client\Client; | ||
use SocialConnect\Provider\AccessTokenInterface; | ||
use SocialConnect\Provider\Exception\InvalidAccessToken; | ||
use SocialConnect\Provider\Exception\InvalidResponse; | ||
use SocialConnect\Common\Entity\User; | ||
use SocialConnect\Common\Hydrator\ObjectMap; | ||
use SocialConnect\OAuth2\AccessToken; | ||
|
||
class Meetup extends \SocialConnect\OAuth2\AbstractProvider | ||
{ | ||
const NAME = 'meetup'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBaseUri() | ||
{ | ||
return 'https://api.meetup.com/'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAuthorizeUri() | ||
{ | ||
return 'https://secure.meetup.com/oauth2/authorize'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRequestTokenUri() | ||
{ | ||
return 'https://secure.meetup.com/oauth2/access'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function parseToken($body) | ||
{ | ||
$result = json_decode($body, true); | ||
if ($result) { | ||
return new AccessToken($result); | ||
} | ||
|
||
throw new InvalidAccessToken('AccessToken is not a valid JSON'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIdentity(AccessTokenInterface $accessToken) | ||
{ | ||
$response = $this->httpClient->request( | ||
$this->getBaseUri() . '2/member/self?sign=true&photo-host=public&fields=gender', | ||
[ | ||
'format' => 'json' | ||
], | ||
Client::GET, | ||
[ | ||
'Authorization' => 'Bearer ' . $accessToken->getToken(), | ||
] | ||
); | ||
|
||
if (!$response->isSuccess()) { | ||
throw new InvalidResponse( | ||
'API response with error code', | ||
$response | ||
); | ||
} | ||
|
||
$result = $response->json(); | ||
if (!$result) { | ||
throw new InvalidResponse( | ||
'API response is not a valid JSON object', | ||
$response | ||
); | ||
} | ||
|
||
$user = new User(); | ||
|
||
$user->id = $result->id; | ||
$user->username = $result->name; | ||
$user->fullname = $result->name; | ||
$user->sex = $result->gender; | ||
$user->pictureURL = $result->photo->photo_link; | ||
|
||
return $user; | ||
} | ||
} |
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 | ||
/** | ||
* SocialConnect project | ||
* @author: Andreas Heigl https://github.com/heiglandreas <[email protected]> | ||
*/ | ||
|
||
namespace Test\OAuth2\Provider; | ||
|
||
class MeetupTest extends AbstractProviderTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getProviderClassName() | ||
{ | ||
return \SocialConnect\OAuth2\Provider\Meetup::class; | ||
} | ||
} |