private function login() { try { // Make the call $auth_response = $this->oauth_client->getAccessToken('password', ['username' => '*****@*****.**', 'password' => 'Asdw1234##']); // Parse it $access_token = null !== $auth_response->getToken() ? $auth_response->getToken() : false; if (!$access_token) { throw new ApiException('Invalid access_token - Retry login.'); } // Set it and persist it, if needed $this->setAccessToken($access_token); // get user info from resource owner $resourceOwner = $this->oauth_client->getResourceOwner($auth_response); $user = $resourceOwner->toArray(); $this->setUser($user); return true; } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) { // Failed to get the access token exit($e->getMessage()); } }