Example #1
0
 /**
  * Processes BitID flow.
  * @param Client $client
  * @param string $uri bitid uri
  * @param callable $cb
  */
 protected function _processBitId(Client $client, $uri, callable $cb, $isBitId)
 {
     // sign payload
     $res = $cb($uri);
     if (!is_array($res) || !isset($res['address']) || !isset($res['signature'])) {
         throw new \InvalidArgumentException("Signing function must sign uri and return array with address and signature field set.");
     }
     // build post url
     $query = [];
     parse_str(parse_url($uri, PHP_URL_QUERY) ?: '', $query);
     $http = empty($query['u']) ? 'https' : 'http';
     // is http/https
     $postUrl = preg_replace('#bitid://#i', "{$http}://", $uri);
     // authorize
     $curl = $client->_prepareRequest('POST', $postUrl, null, json_encode(['address' => $res['address'], 'uri' => $uri, 'signature' => $res['signature']]));
     // store token/secret
     return $client->_executeRequest($curl, $isBitId);
 }