diff --git a/src/Controller/MailruAuthController.php b/src/Controller/MailruAuthController.php index 04f3912..8764e24 100644 --- a/src/Controller/MailruAuthController.php +++ b/src/Controller/MailruAuthController.php @@ -118,7 +118,7 @@ class MailruAuthController extends ControllerBase { // If mailru client could not be obtained. if (!$mailru) { - drupal_set_message($this->t('Social Auth Mailru not configured properly. Contact site administrator.'), 'error'); + \Drupal\Core\Messenger\MessengerInterface::addMessage($this->t('Social Auth Mailru not configured properly. Contact site administrator.'), 'error'); return $this->redirect('user.login'); } @@ -146,7 +146,7 @@ class MailruAuthController extends ControllerBase { // Checks if user cancel login via Mailru. $error = $this->request->getCurrentRequest()->get('error'); if ($error == 'access_denied') { - drupal_set_message($this->t('You could not be authenticated.'), 'error'); + \Drupal\Core\Messenger\MessengerInterface::addMessage($this->t('You could not be authenticated.'), 'error'); return $this->redirect('user.login'); } @@ -155,7 +155,7 @@ class MailruAuthController extends ControllerBase { // If Mailru client could not be obtained. if (!$mailru) { - drupal_set_message($this->t('Social Auth Mailru not configured properly. Contact site administrator.'), 'error'); + \Drupal\Core\Messenger\MessengerInterface::addMessage($this->t('Social Auth Mailru not configured properly. Contact site administrator.'), 'error'); return $this->redirect('user.login'); } @@ -165,7 +165,7 @@ class MailruAuthController extends ControllerBase { $retrievedState = $this->request->getCurrentRequest()->query->get('state'); if (empty($retrievedState) || ($retrievedState !== $state)) { $this->userManager->nullifySessionKeys(); - drupal_set_message($this->t('Mailru login failed. Unvalid oAuth2 State.'), 'error'); + \Drupal\Core\Messenger\MessengerInterface::addMessage($this->t('Mailru login failed. Unvalid oAuth2 State.'), 'error'); return $this->redirect('user.login'); } @@ -176,7 +176,7 @@ class MailruAuthController extends ControllerBase { // Gets user's info from Mailru API. if (!$mailru_profile = $this->mailruManager->getUserInfo()) { - drupal_set_message($this->t('Mailru login failed, could not load Mailru profile. Contact site administrator.'), 'error'); + \Drupal\Core\Messenger\MessengerInterface::addMessage($this->t('Mailru login failed, could not load Mailru profile. Contact site administrator.'), 'error'); return $this->redirect('user.login'); } diff --git a/src/MailruAuthManager.php b/src/MailruAuthManager.php index 590efe3..3f48640 100644 --- a/src/MailruAuthManager.php +++ b/src/MailruAuthManager.php @@ -12,7 +12,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Contains all the logic for Mailru login integration. */ -class MailruAuthManager extends OAuth2Manager { +class MailruAuthManager extends OAuth2Manager{ /** * The logger channel. @@ -76,7 +76,6 @@ class MailruAuthManager extends OAuth2Manager { */ protected $settings; - /** * Constructor. * @@ -102,12 +101,13 @@ class MailruAuthManager extends OAuth2Manager { /** * Authenticates the users by using the access token. * - * @return $this + * @return this * The current object. */ public function authenticate() { $this->token = $this->client->getAccessToken('authorization_code', ['code' => $_GET['code']]); + return $this->token; } /** @@ -127,11 +127,11 @@ class MailruAuthManager extends OAuth2Manager { * @return string * Data returned by Making API Call. */ - public function getExtraDetails($url) { - if($url) { + public function getExtraDetails($method = 'GET', $domain = NULL) { + if ($url) { $httpRequest = $this->client->getAuthenticatedRequest('GET', $url, $this->token, []); $data = $this->client->getResponse($httpRequest); - return json_decode($data->getBody(), true); + return json_decode($data->getBody(), TRUE); } } @@ -144,7 +144,7 @@ class MailruAuthManager extends OAuth2Manager { public function getMailruLoginUrl() { $scopes = []; - $options = ['scope' => $scopes,]; + $options = ['scope' => $scopes]; $login_url = $this->client->getAuthorizationUrl($options); // Generate and return the URL where we should redirect the user. @@ -160,6 +160,7 @@ class MailruAuthManager extends OAuth2Manager { public function getAccessToken() { return $this->token; } + /** * Returns the Mailru login URL where user will be redirected. * @@ -173,5 +174,33 @@ class MailruAuthManager extends OAuth2Manager { return $state; } + /** + * Returns the authorization URL where user will be redirected. + * + * @return string|mixed + * Absolute authorization URL. + */ + public function getAuthorizationUrl(){ + + } + + /** + * Request and end point. + * + * @param string $method + * The HTTP method for the request. + * @param string $path + * The path to request. + * @param string|null $domain + * The domain to request. + * @param array $options + * Request options. + * + * @return array|mixed + * Data returned by provider. + */ + public function requestEndPoint($method, $path, $domain = NULL, array $options = []){ + return $option; + } } diff --git a/src/Plugin/Network/MailruAuth.php b/src/Plugin/Network/MailruAuth.php index 5d6ebd0..3aec8b8 100644 --- a/src/Plugin/Network/MailruAuth.php +++ b/src/Plugin/Network/MailruAuth.php @@ -125,7 +125,7 @@ class MailruAuth extends NetworkBase implements MailruAuthInterface { * @return \League\OAuth2\Client\Provider\Mailru * The initialized 3rd party library instance. * - * @throws SocialApiException + * @throws \Drupal\social_api\SocialApiException * If the SDK library does not exist. */ protected function initSdk() { @@ -156,7 +156,7 @@ class MailruAuth extends NetworkBase implements MailruAuthInterface { ]; } - return new \Aego\OAuth2\Client\Provider\Mailru($league_settings); + return new Mailru($league_settings); } return FALSE; }