Esempio n. 1
0
 private static function getTokenFromGoogleAuthorizationCode($code)
 {
     $userInfoUrl = "https://www.googleapis.com/oauth2/v4/token";
     $parameters = ["code" => $code, "client_id" => Configuration::get("phidias.oauth.google.client_id"), "client_secret" => Configuration::get("phidias.oauth.google.client_secret"), "redirect_uri" => Configuration::get("phidias.oauth.google.redirect_uri"), "grant_type" => "authorization_code"];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $userInfoUrl);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, count($parameters));
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
     $response = curl_exec($ch);
     curl_close($ch);
     $responseData = json_decode($response);
     if (!isset($responseData->id_token)) {
         throw new Exception\InvalidRequest("google says: " . json_encode($responseData));
     }
     // Quick and dirty extraction of the token payload (following JWT specification)
     $tokenData = json_decode(base64_decode(explode(".", $responseData->id_token)[1]));
     if (!isset($tokenData->email)) {
         throw new Exception\InvalidRequest("could not obtain email from google token");
     }
     $payload = self::validateEmail($tokenData->email);
     return new Token("bearer", $payload);
 }
Esempio n. 2
0
<?php

use Phidias\Oauth\Token;
use Phidias\Utilities\Configuration;
Token::setSecret(Configuration::get("phidias.oauth.secret"));
Esempio n. 3
0
<?php

use Phidias\Utilities\Configuration;
use Phidias\Db\Db;
// Obtain DB connection identifiers from configuration
Db::configure(function ($identifier = null) {
    $base = $identifier === null ? "phidias.db" : "phidias.db.{$identifier}";
    if (!Configuration::get("{$base}.host")) {
        return null;
    }
    return array("host" => Configuration::get("{$base}.host"), "username" => Configuration::get("{$base}.username"), "password" => Configuration::get("{$base}.password"), "database" => Configuration::get("{$base}.database"), "charset" => Configuration::get("{$base}.charset"));
});