示例#1
0
 public function testDefaultConfig()
 {
     $config = AwsClient::defaultConfig();
     $this->assertNotEmpty($config);
     $this->assertArrayHasKey('region', $config);
     $this->assertEquals($config['region'], Config::get('aws.region'));
 }
 public function getProfile($token)
 {
     if (empty($this->profile) === true) {
         $fb = new Facebook(['app_id' => Config::get('facebook.app.id'), 'app_secret' => Config::get('facebook.app.secret'), 'default_access_token' => $token]);
         $profile = $fb->get('/me')->getGraphUser();
         $this->profile = array('provider' => self::PROVIDER_NAME, 'id' => $profile->getField('id'), 'email' => $profile->getField('email'), 'firstName' => $profile->getFirstName(), 'lastName' => $profile->getLastName());
     }
     return $this->profile;
 }
示例#3
0
 public function __construct($config = array())
 {
     parent::__construct($config);
     $dynamoConfig = $this->config;
     $localPort = Config::get('dynamodb.local');
     if (empty($localPort) === false) {
         $dynamoConfig['endpoint'] = "http://localhost:{$localPort}";
     }
     $this->client = new DynamoDbClient($dynamoConfig);
 }
示例#4
0
 public function getProfile($token)
 {
     if (empty($this->profile) === true) {
         $emailProvider = Config::get('email.provider');
         if (empty($emailProvider) === false) {
             $profile = $emailProvider->get($token);
             $this->profile = array('provider' => self::PROVIDER_NAME, 'id' => $profile['id'], 'email' => $profile['email'], 'password' => $profile['password'], 'firstName' => $profile['firstName'], 'lastName' => $profile['lastName']);
         }
     }
     return $this->profile;
 }
示例#5
0
 public static function defaultConfig()
 {
     $config = array('version' => 'latest');
     if (APPLICATION_ENV == Environment::LOCAL) {
         $config['credentials'] = array();
         if (empty($config['key']) === true) {
             $config['credentials']['key'] = Config::get('aws.key');
         }
         if (empty($config['secret']) === true) {
             $config['credentials']['secret'] = Config::get('aws.secret');
         }
     }
     $region = Config::get('aws.region');
     $config['region'] = empty($region) ? 'us-east-1' : $region;
     return $config;
 }
示例#6
0
 public function getProfile($token)
 {
     if (empty($this->profile) === true) {
         $client = new Google_Client();
         $client->setClientId(Config::get('google.api.client.id.' . Utility::os()));
         $client->setClientSecret(Config::get('google.api.client.secret.' . Utility::os()));
         $client->addScope('https://www.googleapis.com/auth/userinfo.profile');
         $client->addScope('https://www.googleapis.com/auth/userinfo.email');
         $profile = null;
         if (is_array($token) === true) {
             if (empty($token['idToken']) === false) {
                 //this is a signed id token
                 $ticket = $client->verifyIdToken($token['idToken'])->getAttributes()['payload'];
                 if ($ticket['email'] === $token['email']) {
                     $profile = $token;
                     $profile['id'] = $ticket['sub'];
                 } else {
                     throw new NonFatalException('invalid token, emails dont match');
                 }
             } else {
                 if (empty($token['access_token']) === false) {
                     //regular access token
                     $client->setAccessToken(json_encode($token));
                 } else {
                     throw new NonFatalException('invalid token, no accpetable attribute');
                 }
             }
         } else {
             if (is_string($token) === true) {
                 //token is a CODE to exchange for access token
                 $client->authenticate($token);
             } else {
                 throw new NonFatalException('invalid token, invalid type');
             }
         }
         if (empty($profile) === true) {
             $oauth = new Google_Service_Oauth2($client);
             $profile = $oauth->userinfo->get();
         }
         $this->profile = array('provider' => self::PROVIDER_NAME, 'id' => $profile['id'], 'email' => $profile['email'], 'firstName' => isset($profile['givenName']) ? $profile['givenName'] : null, 'lastName' => isset($profile['familyName']) ? $profile['familyName'] : null);
     }
     return $this->profile;
 }
 public function verify($id, $receipt)
 {
     $data = $this->decodeReceipt($receipt);
     if (empty($data->receipt) === true || empty($data->signature) === true) {
         throw new NonFatalException('missing receipt or signature');
     }
     $signature = base64_decode(str_replace(' ', '+', $data->signature));
     $publicKey = Config::get('google.iab.key');
     $key = '-----BEGIN PUBLIC KEY-----' . PHP_EOL . chunk_split($publicKey, 64, PHP_EOL) . '-----END PUBLIC KEY-----';
     $key = openssl_get_publickey($key);
     $verified = openssl_verify($data->receipt, $signature, $key);
     //openssl_verify return 0 on invalid and -1 on error
     if ($verified < 1) {
         throw new NonFatalException('invalid receipt or signature');
     }
     $purchaseInfo = json_decode($data->receipt);
     $productId = empty($purchaseInfo->productId) ? null : $purchaseInfo->productId;
     return strtolower($id) === $productId;
 }
 public function verify($id, $receipt)
 {
     $data = $this->decodeReceipt($receipt);
     if (empty($data->receipt) === true || empty($data->userId) === true) {
         throw new NonFatalException('missing receipt or userId');
     }
     $secret = Config::get('amazon.iap.secret');
     $suffix = "/version/2.0/verify/developer/{$secret}/user/{$data->userId}/purchaseToken/{$data->receipt}";
     $url = (Environment::is(Environment::PRODUCTION) ? self::PRODUCTION_API : self::SANDBOX_API) . $suffix;
     $request = new URLRequest($url);
     $response = $request->getJSON(false);
     if (empty($response) === true) {
         throw new Exception('invalid receipt', 400);
     }
     if (empty($response->message) === false) {
         throw new NonFatalException($response->message, $request->lastResponseCode);
     }
     $productId = empty($response->sku) ? null : $response->sku;
     return $id === $productId;
 }
示例#9
0
 public static function sendEmail($to, $subject, $body, $from = null)
 {
     if (empty($from) === true) {
         $from = Config::get('email.system');
     }
     $email = new Email();
     $email->send($from, $to, $subject, $body);
 }
示例#10
0
 protected function email($exceptionInfo)
 {
     $subject = Config::get('env.prefix') . ' error - ' . APPLICATION_ENV;
     $body = array('Text' => array('Data' => json_encode($exceptionInfo, JSON_PRETTY_PRINT)));
     Utility::sendEmail(Config::get('email.admins'), $subject, $body, Config::get('email.system.error'));
 }
示例#11
0
 public function defaultConfig()
 {
     return array('adapter' => $this->adapter, 'dsn' => $this->dsn(), 'user' => Config::get('db.user'), 'password' => Config::get('db.password'));
 }
示例#12
0
 public function invalidate($distributionId, $keys)
 {
     $this->client->createInvalidation(array('DistributionId' => $distributionId, 'InvalidationBatch' => array('Paths' => array('Quantity' => count($keys), 'Items' => $keys), 'CallerReference' => Config::get('env.prefix') . '-' . time())));
 }
示例#13
0
<?php

use Kopper\Config;
$config = array('global' => array('aws.region' => 'us-east-1', 'env.prefix' => 'kopper'), 'local' => array('aws.key' => get_cfg_var('kopper.aws.key'), 'aws.secret' => get_cfg_var('kopper.aws.secret')));
Config::init($config);