Skip to content

Commit

Permalink
Merge pull request #287 from sergeychernyshev/master
Browse files Browse the repository at this point in the history
Migrated Meetup to OAuth2
  • Loading branch information
Sergey Chernyshev committed Jan 9, 2018
2 parents 33c80e5 + 7ad75a0 commit 4327c3e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
11 changes: 10 additions & 1 deletion classes/OAuth2Module.php
Expand Up @@ -1014,7 +1014,7 @@ public function makeOAuth2Request($credentials, $url, $method = 'GET', $request_
{
$ch = curl_init();

$separator = strpos('?', $url) ? '&' : '?';
$separator = strpos($url, '?') ? '&' : '?';

if (!is_array($request_params)) {
$request_params = array();
Expand Down Expand Up @@ -1136,6 +1136,15 @@ public function __construct($oauth2_module, $oauth2_client_id, $userinfo,
$this->refresh_token = $refresh_token;
}

/**
* Returns an array of user information key-value pairs
*
* @return array Array of user-specific information
*/
public function getUserInfo() {
return $this->userinfo;
}

/**
* Returns a chunk of HTML to display user's credentials
*
Expand Down
62 changes: 32 additions & 30 deletions modules/meetup/index.php
@@ -1,5 +1,5 @@
<?php
require_once(dirname(dirname(__DIR__)).'/classes/OAuthModule.php');
require_once(dirname(dirname(__DIR__)).'/classes/OAuth2Module.php');

/**
* Meetup authentication module
Expand All @@ -9,39 +9,39 @@
* @package StartupAPI
* @subpackage Authentication\Meetup
*/
class MeetupAuthenticationModule extends OAuthAuthenticationModule
class MeetupAuthenticationModule extends OAuth2AuthenticationModule
{
protected $userCredentialsClass = 'MeetupUserCredentials';

/**
* Instantiates Meetup authentication module and registers it with the system
*
* @param string $oAuthConsumerKey OAuth Consumer Key
* @param string $oAuthConsumerSecret OAuth Consumer Secret
* @param string $oAuthScope Requested permission scopes (zero or more scope strings, usually URLs, separated by spaces)
* @param string $oAuth2ClientID OAuth2 Client ID
* @param string $oAuth2ClientSecret OAuth2 Client Secret
* @param string $oAuth2Scopes Requested permission scopes (zero or more scope strings, usually URLs, separated by spaces)
*/
public function __construct($oAuthConsumerKey, $oAuthConsumerSecret, $oAuthScope = 'basic')
public function __construct($oAuth2ClientID, $oAuth2ClientSecret, $oAuth2Scopes = 'basic')
{
parent::__construct(
'Meetup',
'http://api.meetup.com',
$oAuthConsumerKey,
$oAuthConsumerSecret,
'https://api.meetup.com/oauth/request/',
'https://api.meetup.com/oauth/access/',
'http://www.meetup.com/authenticate/',
array('HMAC-SHA1', 'PLAINTEXT'),
$oAuthScope,
UserConfig::$USERSROOTURL.'/modules/meetup/login-button.png',
UserConfig::$USERSROOTURL.'/modules/meetup/login-button.png',
'https://api.meetup.com',
$oAuth2ClientID,
$oAuth2ClientSecret,
'https://secure.meetup.com/oauth2/authorize',
'https://secure.meetup.com/oauth2/access',
$oAuth2Scopes,
UserConfig::$USERSROOTURL.'/modules/meetup/login-button.png', //signup-button.png',
UserConfig::$USERSROOTURL.'/modules/meetup/login-button.png',
UserConfig::$USERSROOTURL.'/modules/meetup/login-button.png', //connect-button.png',
array(
array(2001, "Logged in using Meetup account", 1),
array(2002, "Added Meetup account", 1),
array(2003, "Removed Meetup account", 0),
array(2004, "Registered using Meetup account", 1),
)
);

$this->oAuth2AccessTokenRequestFormURLencoded = TRUE;
}

public function getID()
Expand Down Expand Up @@ -74,23 +74,25 @@ public static function getModulesLogo($size = 100) {
}

public static function getSignupURL() {
return 'http://www.meetup.com/meetup_api/oauth_consumers/';
return 'https://www.meetup.com/meetup_api/oauth_consumers/';
}

public function getIdentity($oauth_user_id) {
// get meetup user id
$request = new OAuthRequester('https://api.meetup.com/members.json/?relation=self', 'GET');
$result = $request->doRequest($oauth_user_id);
public function getIdentity($oauth2_user_id) {
$credentials = $this->getOAuth2Credentials($oauth2_user_id);

try {
$result = $credentials->makeOAuth2Request('https://api.meetup.com/members.json/?relation=self');
} catch (OAuth2Exception $ex) {
return null;
}

if ($result['code'] == 200) {
$userdata = json_decode($result['body'], true);
$userdata = json_decode($result, true);

// array includes 'id' parameter which uniquely identifies a user
if (array_key_exists('id', $userdata['results'][0])
&& array_key_exists('name', $userdata['results'][0])
) {
return $userdata['results'][0];
}
// array includes 'id' parameter which uniquely identifies a user
if (array_key_exists('id', $userdata['results'][0])
&& array_key_exists('name', $userdata['results'][0])
) {
return $userdata['results'][0];
}

return null;
Expand All @@ -112,7 +114,7 @@ protected function renderUserInfo($serialized_userinfo) {
* @package StartupAPI
* @subpackage Authentication\Meetup
*/
class MeetupUserCredentials extends OAuthUserCredentials {
class MeetupUserCredentials extends OAuth2UserCredentials {
public function getHTML() {
return StartupAPI::$template->render("@startupapi/modules/meetup/credentials.html.twig", $this->userinfo);
}
Expand Down

0 comments on commit 4327c3e

Please sign in to comment.