Ejemplo n.º 1
0
 /**
  * @return \OAuth2\Client|null
  */
 public function GoogleConnector()
 {
     $oGoogle = false;
     $oConfig = $this->oActions->Config();
     if ($oConfig->Get('social', 'google_enable', false) && '' !== \trim($oConfig->Get('social', 'google_client_id', '')) && '' !== \trim($oConfig->Get('social', 'google_client_secret', ''))) {
         include_once APP_VERSION_ROOT_PATH . 'app/libraries/PHP-OAuth2/Client.php';
         include_once APP_VERSION_ROOT_PATH . 'app/libraries/PHP-OAuth2/GrantType/IGrantType.php';
         include_once APP_VERSION_ROOT_PATH . 'app/libraries/PHP-OAuth2/GrantType/AuthorizationCode.php';
         include_once APP_VERSION_ROOT_PATH . 'app/libraries/PHP-OAuth2/GrantType/RefreshToken.php';
         try {
             $oGoogle = new \OAuth2\Client(\trim($oConfig->Get('social', 'google_client_id', '')), \trim($oConfig->Get('social', 'google_client_secret', '')));
             $sProxy = $this->oActions->Config()->Get('labs', 'curl_proxy', '');
             if (0 < \strlen($sProxy)) {
                 $oGoogle->setCurlOption(CURLOPT_PROXY, $sProxy);
                 $sProxyAuth = $this->oActions->Config()->Get('labs', 'curl_proxy_auth', '');
                 if (0 < \strlen($sProxyAuth)) {
                     $oGoogle->setCurlOption(CURLOPT_PROXYUSERPWD, $sProxyAuth);
                 }
             }
         } catch (\Exception $oException) {
             $this->oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
         }
     }
     return false === $oGoogle ? null : $oGoogle;
 }
Ejemplo n.º 2
0
    echo "<pre>OAuth Error: " . $_GET["error"] . "\n";
    echo '<a href="index.php">Retry</a></pre>';
    die;
    //?state=SomeUnguessableValue&code=ki4tr-_EAXNXVrhWMcQ5a5pLm0o
}
$authorizeUrl = 'https://ssl.reddit.com/api/v1/authorize';
$accessTokenUrl = 'https://ssl.reddit.com/api/v1/access_token';
$clientId = 'jJgLD5ebMOT9sw';
$clientSecret = 'muldwiysWI2ok2KWNmoiDK6FMKw';
$userAgent = 'ChangeMeClient/0.1 by YourUsername';
$redirectUrl = "http://brittanyannkos.com/reddit";
require "OAuth2/Client.php";
require "OAuth2/GrantType/IGrantType.php";
require "OAuth2/GrantType/AuthorizationCode.php";
$client = new OAuth2\Client($clientId, $clientSecret, OAuth2\Client::AUTH_TYPE_AUTHORIZATION_BASIC);
$client->setCurlOption(CURLOPT_USERAGENT, $userAgent);
$_GET["code"] = "ki4tr-_EAXNXVrhWMcQ5a5pLm0o";
if (!isset($_GET["code"])) {
    $authUrl = $client->getAuthenticationUrl($authorizeUrl, $redirectUrl, array("scope" => "identity", "state" => "SomeUnguessableValue", "duration" => "permanent"));
    header("Location: " . $authUrl);
    die("Redirect");
} else {
    $params = array("code" => $_GET["code"], "redirect_uri" => $redirectUrl);
    $response = $client->getAccessToken($accessTokenUrl, "authorization_code", $params);
    $accessTokenResult = $response["result"];
    print_r($accessTokenResult);
    $client->setAccessToken($accessTokenResult["access_token"]);
    $client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
    $response = $client->fetch("https://oauth.reddit.com/api/v1/me.json");
    echo '<strong>Response for fetch me.json:</strong><pre>';
    print_r($response);
Ejemplo n.º 3
0
/**
 *	Add the necessary webhooks for the Sausage Machine to function
 *	@param String $github_access_token see route_get_github_auth & route_get_github_auth_callback
 *	@param String $github_repo GitHub username, followed by a slash, followed by the name of the respository
 *	@return true if sucessful, false if not
 */
function github_add_webhook($github_access_token, $github_repo)
{
    $client = new OAuth2\Client(config('github_client_id'), config('github_client_secret'));
    $client->setAccessToken($github_access_token);
    $client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_TOKEN);
    $client->setCurlOption(CURLOPT_USERAGENT, config('github_useragent'));
    $param = array('name' => 'web', 'active' => true, 'events' => array('push'), 'config' => array('url' => base_url() . 'github.php?push', 'content_type' => 'form'));
    $response = $client->fetch('https://api.github.com/repos/' . $github_repo . '/hooks', json_encode($param), 'POST');
    if (!isset($response['code']) || $response['code'] !== 201) {
        return false;
    } else {
        return true;
    }
}