Permalink
Browse files

Merge pull request #287 from sergeychernyshev/master

Migrated Meetup to OAuth2
  • Loading branch information...
sergeychernyshev committed Jan 9, 2018
2 parents 33c80e5 + 7ad75a0 commit 4327c3ea0f419325d071c4fa6634a57e01d93864
Showing with 42 additions and 31 deletions.
  1. +10 −1 classes/OAuth2Module.php
  2. +32 −30 modules/meetup/index.php
View
@@ -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();
@@ -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
*
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(dirname(__DIR__)).'/classes/OAuthModule.php');
require_once(dirname(dirname(__DIR__)).'/classes/OAuth2Module.php');
/**
* Meetup authentication module
@@ -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()
@@ -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;
@@ -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);
}

0 comments on commit 4327c3e

Please sign in to comment.