-
-
Save bwlng/2cb486c8d83001deae19 to your computer and use it in GitHub Desktop.
Moves API
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
<?php | |
namespace OAuth\Provider; | |
use \OAuth\OAuth2\Token\Access; | |
/** | |
* Moves OAuth2 Provider | |
* | |
* @package CodeIgniter/OAuth2 | |
* @category Provider | |
* @author Phil Sturgeon | |
* @copyright (c) 2012 HappyNinjas Ltd | |
* @license http://philsturgeon.co.uk/code/dbad-license | |
*/ | |
class Moves extends \OAuth\OAuth2\Provider | |
{ | |
public $method = 'POST'; | |
public $scope_seperator = ' '; | |
public function authorizeUrl() | |
{ | |
return 'https://api.moves-app.com/oauth/v1/authorize'; | |
} | |
public function accessTokenUrl() | |
{ | |
return 'https://api.moves-app.com/oauth/v1/access_token'; | |
} | |
public function __construct(array $options = array()) | |
{ | |
// Now make sure we have the default scope to get user data | |
empty($options['scope']) and $options['scope'] = array( | |
'activity', | |
'location' | |
); | |
// Array it if its string | |
$options['scope'] = (array) $options['scope']; | |
isset($options['access_type']) | |
and $this->access_type = $options['access_type']; | |
parent::__construct($options); | |
} | |
public function authorize($options = array()) | |
{ | |
$params = array( | |
'client_id' => $this->client_id, | |
'scope' => is_array($this->scope) ? implode($this->scope_seperator, $this->scope) : $this->scope, | |
'response_type' => 'code', | |
'approval_prompt' => 'force', // - google force-recheck | |
); | |
$params = array_merge($params, $this->params); | |
return $params; | |
} | |
/* | |
* Get access to the API | |
* | |
* @param string The access code | |
* @return object Success or failure along with the response details | |
*/ | |
public function access($code, $options = array()) | |
{ | |
if ($code === null) { | |
throw new Exception(array('message' => 'Expected Authorization Code from '.ucfirst($this->name).' is missing')); | |
} | |
return parent::access($code, $options); | |
} | |
public function getUserInfo() | |
{ | |
$url = 'https://api.moves-app.com/api/1.1/user/profile?'.http_build_query(array( | |
'access_token' => $this->token->access_token, | |
)); | |
$user = json_decode(file_get_contents($url), true); | |
return array( | |
'uid' => $user['userId'] | |
); | |
} | |
} | |
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
<?php | |
/** | |
* Craft OAuth by Dukt | |
* | |
* @package Craft OAuth | |
* @author Benjamin David | |
* @copyright Copyright (c) 2014, Dukt | |
* @license https://dukt.net/craft/oauth/docs/license | |
* @link https://dukt.net/craft/oauth/ | |
*/ | |
namespace OAuthProviderSources; | |
class MovesOAuthProviderSource extends BaseOAuthProviderSource { | |
public $consoleUrl = 'https://dev.moves-app.com/apps'; | |
public function getName() | |
{ | |
return 'Moves'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment