Ejemplo n.º 1
0
 /**
  * Redirects the user to the auth provider
  *
  * @return void
  */
 public function getAuthenticationUrl()
 {
     $authConf = Config::$a['oauth']['providers'][$this->authProvider];
     $callback = sprintf(Config::$a['oauth']['callback'], $this->authProvider);
     $client = new \OAuth2\Client($authConf['clientId'], $authConf['clientSecret'], \OAuth2\Client::AUTH_TYPE_AUTHORIZATION_BASIC);
     return $client->getAuthenticationUrl('https://ssl.reddit.com/api/v1/authorize', $callback, array('scope' => 'identity', 'state' => md5(time() . 'eFdcSA_')));
 }
 public function loginAction()
 {
     $callback_url = Mage::getUrl('gomage_social/reddit/callback', array('_secure' => true));
     $client = new OAuth2\Client(Mage::getStoreConfig('gomage_social/reddit/id'), Mage::getStoreConfig('gomage_social/reddit/secret'), OAuth2\Client::AUTH_TYPE_AUTHORIZATION_BASIC);
     $authUrl = $client->getAuthenticationUrl($this->authorizeUrl, $callback_url, array("scope" => "identity", "state" => "SomeUnguessableValue"));
     return $this->_redirectUrl($authUrl);
 }
Ejemplo n.º 3
0
 /**
  * Redirects the user to the auth provider
  *
  * @return void
  */
 public function getAuthenticationUrl()
 {
     $authConf = Config::$a['oauth']['providers'][$this->authProvider];
     $callback = sprintf(Config::$a['oauth']['callback'], $this->authProvider);
     $client = new \OAuth2\Client($authConf['clientId'], $authConf['clientSecret']);
     $client->setAccessTokenType(\OAuth2\Client::ACCESS_TOKEN_OAUTH);
     return $client->getAuthenticationUrl('https://api.twitch.tv/kraken/oauth2/authorize', $callback, array('scope' => 'user_read'));
 }
Ejemplo n.º 4
0
 /**
  * Redirects the user to the auth provider
  *
  * @return void
  */
 public function getAuthenticationUrl()
 {
     $authConf = Config::$a['oauth']['providers'][$this->authProvider];
     $callback = sprintf(Config::$a['oauth']['callback'], $this->authProvider);
     $client = new \OAuth2\Client($authConf['clientId'], $authConf['clientSecret']);
     $client->setAccessTokenType(\OAuth2\Client::ACCESS_TOKEN_BEARER);
     return $client->getAuthenticationUrl('https://accounts.google.com/o/oauth2/auth', $callback, array('scope' => 'openid email', 'state' => 'security_token=' . Session::getSessionId()));
 }
Ejemplo n.º 5
0
 /**
  * approve method
  *
  * @return void
  */
 public function approve()
 {
     $client = new OAuth2\Client(Configure::read('LilCrm.googleApiClientId'), Configure::read('LilCrm.googleApiClientSecret'));
     $redirect_url = Router::url(array('prefix' => false, 'plugin' => 'lil_crm', 'controller' => 'oauth', 'action' => 'index'), true);
     $auth_url = $client->getAuthenticationUrl('https://accounts.google.com/o/oauth2/auth', $redirect_url, array('scope' => 'http://www.google.com/m8/feeds/', 'access_type' => 'offline'));
     header('Location: ' . $auth_url);
     die('Redirect');
 }
Ejemplo n.º 6
0
/**
 *	Get the URL to redirect a client to in order to get a GitHub authentication token
 *	@return string
 */
function github_get_auth($param = array())
{
    $redirect_uri = base_url();
    // add explicit route since GitHub prepends it with their own keys and values
    $redirect_uri .= 'github.php?auth_callback';
    unset($param[0]);
    $redirect_uri .= '&' . http_build_query($param);
    $client = new OAuth2\Client(config('github_client_id'), config('github_client_secret'));
    $auth_url = $client->getAuthenticationUrl('https://github.com/login/oauth/authorize', $redirect_uri, array('scope' => 'public_repo'));
    return $auth_url;
}
Ejemplo n.º 7
0
 public function account_button()
 {
     $this->init_oauth();
     if ($this->relay) {
         $time = time();
         $hmac = hash('sha1', $time . '_' . $this->eqdkp_appid . '_' . $this->eqdkp_appsecret);
         $redir_url = $this->RELAY_URL . '?_t=' . $time . '&_id=' . $this->eqdkp_appid . '&_hmac=' . $hmac . '&_s=ac';
     } else {
         $redir_url = $this->env->buildLink() . 'index.php/Settings/?mode=addauthacc&lmethod=battlenet&norelay=1';
     }
     $client = new OAuth2\Client($this->appid, $this->appsecret);
     $auth_url = $client->getAuthenticationUrl($this->AUTHORIZATION_ENDPOINT, $redir_url, array('scope' => 'wow.profile'));
     return '<button type="button" class="mainoption thirdpartylogin battlenet accountbtn" onclick="window.location=\'' . $auth_url . '\'"><i class="bi_battlenet"></i> Battle.net</button>';
 }
Ejemplo n.º 8
0
    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);
    echo '</pre>';
}
/*******************************************************************************
 * IDENTIFICATION
 ******************************************************************************/
$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
$protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
$url = $protocol . $_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'];
//DECONNEXION
if (isset($_GET['reset'])) {
    unset($_SESSION['access_token']);
    header('Content-type: application/json');
    echo json_encode(array(DISCONNECT_PAGE));
} elseif (!empty($_SESSION['access_token'])) {
    $client->setAccessToken($_SESSION['access_token']);
    $profile = $client->fetch(PROFILE_PAGE);
} elseif (empty($_GET['code'])) {
    $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, $url);
    header('Location: ' . $auth_url);
    die('Redirect');
} else {
    $params = array('code' => $_GET['code'], 'redirect_uri' => $url);
    $response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params);
    if (isset($response['result']) && isset($response['result']['access_token'])) {
        $client->setAccessToken($response['result']['access_token']);
        $_SESSION['access_token'] = $response['result']['access_token'];
        $client->setAccessToken($_SESSION['access_token']);
        $profile = $client->fetch(PROFILE_PAGE);
    } else {
        die('Une erreur est survenue lors de l’identification');
    }
}
/*******************************************************************************
const SUBMIT_API = "https://www.deviantart.com/api/oauth2/stash/submit";
const FOLDER_API = "https://www.deviantart.com/api/oauth2/stash/folder";
const APPNAME = 'App.Name';
echo '<a href="' . REDIRECT_URI . '">Reload</a><br>';
/**
 * Oauth2 Process
 *
 * 1. Ask user to authorize by redirecting them to the authorization endpoint on DA
 * 2. Once user authorizes DA will send back an authoirzation code ($_GET['code'])
 * 3. We then use the code to get an access_token
 * 4. We use the access_token to access an API endpoint
 */
try {
    $client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET, OAuth2\Client::AUTH_TYPE_AUTHORIZATION_BASIC);
    if (!isset($_REQUEST['code'])) {
        $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
        header('Location: ' . $auth_url);
        die('Redirecting ...');
    } else {
        $params = array('code' => $_REQUEST['code'], 'redirect_uri' => REDIRECT_URI);
        $response = $client->getAccessToken(TOKEN_ENDPOINT, OAuth2\Client::GRANT_TYPE_AUTH_CODE, $params);
        $val = (object) $response['result'];
        if (!$val->access_token) {
            throw new Exception("No access token returned: " . $val->error_description);
        }
        $client->setAccessToken($val->access_token);
        $client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_OAUTH);
        // Submit a file first
        $response = $client->fetch(SUBMIT_API, array('title' => 'Fella Sample Image', 'artist_comments' => 'Fella Sample Image', 'keywords' => 'fella sample image', 'folder' => APPNAME, 'file' => "@fella.png"), OAuth2\Client::HTTP_METHOD_POST);
        $result = (object) $response['result'];
        if (!$result) {
Ejemplo n.º 11
0
<?php

include 'config.php';
$client = new OAuth2\Client($clientId, $clientSecret);
if (!isset($_GET['code'])) {
    $authUrl = $client->getAuthenticationUrl($authorizeUrl, $redirectUrl);
    header('Location: ' . $authUrl);
    die('Redirect');
} else {
    $params = array('code' => $_GET['code'], 'redirect_uri' => $redirectUrl);
    $response = $client->getAccessToken($accessTokenUrl, 'authorization_code', $params);
    $token = $response['result']['access_token'];
    $client->setAccessTokenType(1);
    $client->setAccessToken($token);
    $_SESSION['client'] = $client;
    $_SESSION['token'] = $token;
    header('Location: index.php');
}
Ejemplo n.º 12
0
<?php

require 'client.php';
require 'GrantType/IGrantType.php';
require 'GrantType/AuthorizationCode.php';
const CLIENT_ID = '379875764619-57lesbrrec02g9tf3r2d2gup6nvdl3p4.apps.googleusercontent.com';
const CLIENT_SECRET = 'KeHot5Ds76apeUcrE27xXYJH';
const REDIRECT_URI = 'http://localhost/oauth/test.php';
const AUTHORIZATION_ENDPOINT = 'https://accounts.google.com/o/oauth2/auth';
const TOKEN_ENDPOINT = 'https://accounts.google.com/o/oauth2/token';
//localhost/oauth/test.php
session_start();
$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
if (!isset($_GET['code'])) {
    $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI, array('scope' => 'http://www.google.com/m8/feeds/', 'access_type' => 'offline'));
    header('Location: ' . $auth_url);
    die('Redirect');
} else {
    if (empty($_SESSION['token'])) {
        $params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI);
        $response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params);
        if ($response['code'] == 200) {
            $_SESSION['token'] = $response['result']['access_token'];
        }
    }
    if (!empty($_SESSION['token'])) {
        $client->setAccessToken($_SESSION['token']);
        $response = $client->fetch('https://www.google.com/m8/feeds/contacts/default/full');
        if ($response['code'] == 200) {
            $response = json_encode(simplexml_load_string($response['result']));
            print "<pre>" . print_r(json_decode($response, true), true) . "</pre>";
Ejemplo n.º 13
0
<?php

require_once '../vendor/PHP-OAuth2/Client.php';
require_once '../vendor/PHP-OAuth2/GrantType/IGrantType.php';
require_once '../vendor/PHP-OAuth2/GrantType/AuthorizationCode.php';
require_once '../vendor/icalforce/oauth.inc.php';
$client = new OAuth2\Client($CLIENT_ID, $CLIENT_SECRET);
$keyInfo = ICalForce\cookieMakeCryptKey();
if (isset($_GET['code'])) {
    $params = array('code' => $_GET['code'], 'redirect_uri' => $REDIRECT_URI);
    $response = $client->getAccessToken(ICalForce\TOKEN_ENDPOINT, 'authorization_code', $params);
    $cookieEnc = ICalForce\cookieEncrypt($keyInfo, json_encode($response));
    setcookie('V_04660A06A99FEC845360DA2C6D2557A3', $cookieEnc, 0, '/', $_SERVER['HTTP_HOST'], true);
    header('Location: ' . $HOME_URI);
    die('Redirect');
} elseif (isset($_GET['error'])) {
    echo 'Error. Could not get Auth-Token. Please contact your system administrator.';
} else {
    $auth_url = $client->getAuthenticationUrl(ICalForce\AUTHORIZATION_ENDPOINT, $REDIRECT_URI);
    header('Location: ' . $auth_url);
    die('Redirect');
}
Ejemplo n.º 14
0
<?php

require_once 'vendor/autoload.php';
const CLIENT_ID = 'testclient';
const CLIENT_SECRET = 'testpass';
const REDIRECT_URI = 'http://localhost/oauth2/php_oauth_client/www/index.php';
const AUTHORIZATION_ENDPOINT = 'http://localhost:81/oauth/authorize';
const TOKEN_ENDPOINT = 'http://localhost:81/oauth/token';
$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
$get = (object) filter_input_array(INPUT_GET, ['code' => FILTER_SANITIZE_STRING, 'error' => FILTER_SANITIZE_STRING, 'error_description' => FILTER_SANITIZE_STRING, 'get_access' => FILTER_VALIDATE_BOOLEAN]);
if (@$get->error) {
    echo "<a href='{$_SERVER['PHP_SELF']}'>retry</a><br>";
    die("<b>{$get->error}</b><br>{$get->error_description}");
}
if (!@$get->code && @$get->get_access) {
    $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI, ['state' => uniqid()]);
    header('Location: ' . $auth_url);
    die('Redirect');
}
if (@$get->code) {
    $params = array('code' => $get->code, 'redirect_uri' => REDIRECT_URI);
    $response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params);
    echo "<b>Access token:</b> " . $response['result']['access_token'] . '<br>';
    echo "<a href='{$_SERVER['PHP_SELF']}'>back</a><br>";
} else {
}
echo "<a href='{$_SERVER['PHP_SELF']}?get_access=true'>get access</a><br>";
Ejemplo n.º 15
0
    echo '<a href="index.php">Retry</a></pre>';
    die;
}
$authorizeUrl = 'https://github.com/login/oauth/authorize';
$accessTokenUrl = 'https://github.com/login/oauth/access_token';
$clientId = $_SERVER['OAUTH2_CLIENT_ID'];
$clientSecret = $_SERVER['OAUTH2_CLIENT_SECRET'];
$userAgent = 'cwalk';
$redirectUrl = "http://www.cwalk.guru/login.php";
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);
if (!isset($_GET["code"])) {
    $authUrl = $client->getAuthenticationUrl($authorizeUrl, $redirectUrl, array("scope" => "user,user:email", "state" => "SomeUnguessableValue"));
    header("Location: " . $authUrl);
    die("Redirect");
} else {
    $params = array("code" => $_GET["code"], "redirect_uri" => $redirectUrl);
    $response = $client->getAccessToken($accessTokenUrl, "authorization_code", $params);
    $accessTokenResult = $response["result"];
    parse_str($accessTokenResult, $accessTokenResultArray);
    $accessTokenFirst = $accessTokenResultArray["access_token"];
    $accessToken = $accessTokenResultArray["access_token"];
    $client->setAccessToken($accessToken);
    $client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
    $response = $client->fetch("https://api.github.com/user");
    $responseArray = $response["result"];
    $login = $responseArray["login"];
    $email = $responseArray["email"];