/**
  * Creates a signed JWT.
  * @param array $payload
  * @return string The signed JWT.
  */
 private function makeSignedJwt($payload)
 {
     $header = array('typ' => 'JWT', 'alg' => 'RS256');
     $segments = array(Google_Utils::urlSafeB64Encode(json_encode($header)), Google_Utils::urlSafeB64Encode(json_encode($payload)));
     $signingInput = implode('.', $segments);
     $signer = new Google_P12Signer($this->privateKey, $this->privateKeyPassword);
     $signature = $signer->sign($signingInput);
     $segments[] = Google_Utils::urlSafeB64Encode($signature);
     return implode(".", $segments);
 }
 private function makeSignedJwt($payload)
 {
     $header = array("typ" => "JWT", "alg" => "RS256");
     $segments = array();
     $segments[] = Google_Utils::urlSafeB64Encode(json_encode($header));
     $segments[] = Google_Utils::urlSafeB64Encode(json_encode($payload));
     $signing_input = implode(".", $segments);
     $signature = $this->signer->sign($signing_input);
     $segments[] = Google_Utils::urlSafeB64Encode($signature);
     return implode(".", $segments);
 }
Esempio n. 3
0
 /**
  * Creates a signed JWT.
  * @param array $payload
  * @return string The signed JWT.
  */
 private function makeSignedJwt($payload)
 {
     $header = array('typ' => 'JWT', 'alg' => 'RS256');
     $payload = json_encode($payload);
     // Handle some overzealous escaping in PHP json that seemed to cause some errors
     // with claimsets.
     $payload = str_replace('\\/', '/', $payload);
     $segments = array(Google_Utils::urlSafeB64Encode(json_encode($header)), Google_Utils::urlSafeB64Encode($payload));
     $signingInput = implode('.', $segments);
     $signer = new Google_Signer_P12($this->privateKey, $this->privateKeyPassword);
     $signature = $signer->sign($signingInput);
     $segments[] = Google_Utils::urlSafeB64Encode($signature);
     return implode(".", $segments);
 }
 /**
  * Invokes the UploadAccount API.
  *
  * @param string $hashAlgorithm password hash algorithm. See Gitkit doc for
  *                              supported names.
  * @param string $hashKey raw key for the algorithm
  * @param array $accounts array of account info to be uploaded
  * @param null|int $rounds Rounds of the hash function
  * @param null|int $memoryCost Memory cost of the hash function
  */
 public function uploadAccount($hashAlgorithm, $hashKey, $accounts, $rounds, $memoryCost)
 {
     $data = array('hashAlgorithm' => $hashAlgorithm, 'signerKey' => Google_Utils::urlSafeB64Encode($hashKey), 'users' => $accounts);
     if ($rounds) {
         $data['rounds'] = $rounds;
     }
     if ($memoryCost) {
         $data['memoryCost'] = $memoryCost;
     }
     $this->invokeGitkitApiWithServiceAccount('uploadAccount', $data);
 }
 /**
  * Converts Gitkit account array to json request.
  *
  * @param array $accounts Gitkit account array
  * @return array json request
  */
 private function toJsonRequest($accounts)
 {
     $jsonUsers = array();
     foreach ($accounts as $account) {
         $user = array('email' => $account->getEmail(), 'localId' => $account->getUserId(), 'passwordHash' => Google_Utils::urlSafeB64Encode($account->getPasswordHash()), 'salt' => Google_Utils::urlSafeB64Encode($account->getSalt()));
         array_push($jsonUsers, $user);
     }
     return $jsonUsers;
 }
 /**
  * Invokes the UploadAccount API.
  *
  * @param string $hashAlgorithm password hash algorithm. See Gitkit doc for
  *                              supported names.
  * @param string $hashKey raw key for the algorithm
  * @param array $accounts array of account info to be uploaded
  */
 public function uploadAccount($hashAlgorithm, $hashKey, $accounts)
 {
     $data = array('hashAlgorithm' => $hashAlgorithm, 'signerKey' => Google_Utils::urlSafeB64Encode($hashKey), 'users' => $accounts);
     $this->invokeGitkitApiWithServiceAccount('uploadAccount', $data);
 }
 public function makeSignedJwt($payload, $cred)
 {
     $header = array("typ" => "JWT", "alg" => "RS256");
     $segments = array();
     $segments[] = Google_Utils::urlSafeB64Encode(json_encode($header));
     $segments[] = Google_Utils::urlSafeB64Encode(json_encode($payload));
     $signing_input = implode(".", $segments);
     $signer = new Google_Signer_P12($cred->privateKey, $cred->privateKeyPassword);
     $signature = $signer->sign($signing_input);
     $segments[] = Google_Utils::urlSafeB64Encode($signature);
     return implode(".", $segments);
 }