Skip to content

Instantly share code, notes, and snippets.

@bwlng

bwlng/Moves.php Secret

Last active Aug 29, 2015
Embed
What would you like to do?
Moves API
<?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']
);
}
}
<?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