private function registerMwClient() { $key = Config::get('app.key'); $client = new \Guzzle\Service\Client('https://login.microweber.com/api/v1/client/'); $domain = site_url(); $domain = substr($domain, strpos($domain, '://') + 3); $domain = str_replace('/', '', $domain); $request = $client->createRequest('POST', "config/{$domain}"); //dd($request, $request); $request->setPostField('token', $key); $response = $client->send($request); if (200 == $response->getStatusCode()) { $body = (string) $response->getBody(); $body = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $body, MCRYPT_MODE_ECB); $body = trim($body); $body = (array) json_decode($body); Config::set('services.microweber', $body); Config::save(); save_option(['option_value' => 'y', 'option_key' => 'enable_user_microweber_registration', 'option_group' => 'users']); } else { // $reason = $response->getReasonPhrase(); // dd(__FILE__, $reason, $response->getStatusCode()); } }
// to the token service. $resource = $provider->getResource(); $tokenServiceUri = $provider->urlAccessToken(); $grant = new \League\OAuth2\Client\Grant\RefreshToken(); echo 'Getting ready to request an access token: ', '<br />', 'Resource: ', $resource, '<br />', 'Token service: ', $tokenServiceUri, '<p />'; $accessToken = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken, 'resource' => $resource]); // We have an access token. // In production scenarios, save the access token in an appropriate // storage mechanism so you can use it during the user's session. echo 'Access token: ', '<br />', $accessToken->accessToken, '<p />'; //This is the REST endpoint that we are sending our request to $apiUrl = $_POST['SPSiteUrl'] . '/_api/web/title'; // Using guzzle to create an http client // pass the access token in the Authorization header $client = new Guzzle\Service\Client(); $request = $client->createRequest('GET', $apiUrl); $request->setHeader('Authorization', 'Bearer ' . $accessToken->accessToken); $request->setHeader('Accept', 'application/json;odata=verbose'); $response = $client->send($request); //Decode the response using the JSON decoder $output = $response->getBody(true); $jsonResult = json_decode($output); if ($jsonResult->d != null) { // Print the result to the page echo '<p>Querying the REST endpoint ', $apiUrl, '<br/>'; echo 'Result: ', $jsonResult->d->Title, '</p>'; } else { // There was a problem with the request echo '<p>There was a problem querying the REST endpoint ' . $apiUrl . '<br/>'; echo 'Error code: ' . $jsonResult->error->code . '<br/>'; echo 'Error message: ' . $jsonResult->error->message->value . '</p>';