Artdarek\OAuth\OAuth::consumer PHP Method

consumer() public method

public consumer ( string $service, string $url = null, array $scope = null ) : OAuth\Common\Service\AbstractService
$service string
$url string
$scope array
return OAuth\Common\Service\AbstractService
    public function consumer($service, $url = null, $scope = null)
    {
        // get config
        $this->setConfig($service);
        // get storage object
        $storage = $this->createStorageInstance($this->_storageClass);
        // create credentials object
        $credentials = new Credentials($this->_client_id, $this->_client_secret, $url ?: URL::current());
        // check if scopes were provided
        if (is_null($scope)) {
            // get scope from config (default to empty array)
            $scope = $this->_scope;
        }
        // return the service consumer object
        return $this->_serviceFactory->createService($service, $credentials, $storage, $scope);
    }

Usage Example

Example #1
0
 /**
  * Gets all the google contacts of authenticated user
  * @param  Request $request
  * @return mixed
  */
 public function get($request)
 {
     $googleService = $this->oAuth->consumer('Google');
     $code = $request->code;
     if (!is_null($code)) {
         $token = $googleService->requestAccessToken($code);
         $result = json_decode($googleService->request("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=400"), true);
         $contacts = [];
         foreach ($result['feed']['entry'] as $contact) {
             if (isset($contact['gd$email'])) {
                 $contacts[] = ['email' => $contact['gd$email'][0]['address'], 'title' => $contact['title']['$t']];
             }
         }
         $contacts = $this->categorize($contacts);
         \Session::set('contacts', $contacts);
         return redirect()->route('contacts');
     } else {
         $url = $googleService->getAuthorizationUri();
         return redirect((string) $url);
     }
 }
All Usage Examples Of Artdarek\OAuth\OAuth::consumer