Beispiel #1
0
 /**
  * Performs the account linking for login_link
  *
  * @param	array	$link_data		The same variable given to {@see \phpbb\auth\provider\provider_interface::link_account}
  * @param	string	$service_name	The name of the service being used in
  *									linking.
  * @return	string|null	Returns a language constant (string) if an error is
  *						encountered, or null on success.
  */
 protected function link_account_login_link(array $link_data, $service_name)
 {
     $storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->auth_provider_oauth_token_storage_table, $this->auth_provider_oauth_state_table);
     // Check for an access token, they should have one
     if (!$storage->has_access_token_by_session($service_name)) {
         return 'LOGIN_LINK_ERROR_OAUTH_NO_ACCESS_TOKEN';
     }
     // Prepare the query string
     $query = 'mode=login_link&login_link_oauth_service=' . strtolower($link_data['oauth_service']);
     // Prepare for an authentication request
     $service_credentials = $this->service_providers[$service_name]->get_service_credentials();
     $scopes = $this->service_providers[$service_name]->get_auth_scope();
     $service = $this->get_service(strtolower($link_data['oauth_service']), $storage, $service_credentials, $query, $scopes);
     $this->service_providers[$service_name]->set_external_service_provider($service);
     // The user has already authenticated successfully, request to authenticate again
     $unique_id = $this->service_providers[$service_name]->perform_token_auth();
     // Insert into table, they will be able to log in after this
     $data = array('user_id' => $link_data['user_id'], 'provider' => strtolower($link_data['oauth_service']), 'oauth_provider_id' => $unique_id);
     $this->link_account_perform_link($data);
     // Update token storage to store the user_id
     $storage->set_user_id($link_data['user_id']);
 }