/** * Inject into the process of the base connection. * * @param Gdn_Controller $sender. * @param Gdn_Controller $args. */ public function base_connectData_handler($sender, $args) { if (val(0, $args) != $this->getProviderKey()) { return; } // Retrieve the profile that was saved to the session in the entry controller. $savedProfile = Gdn::session()->stash($this->getProviderKey(), '', false); if (Gdn::session()->stash($this->getProviderKey(), '', false)) { $this->log('Base Connect Data Profile Saved in Session', ['profile' => $savedProfile]); } $profile = val('Profile', $savedProfile); $accessToken = val('AccessToken', $savedProfile); trace($profile, 'Profile'); trace($accessToken, 'Access Token'); /* @var Gdn_Form $form */ $form = $sender->Form; //new Gdn_Form(); // Create a form and populate it with values from the profile. $originaFormValues = $form->formValues(); $formValues = array_replace($originaFormValues, $profile); $form->formValues($formValues); trace($formValues, 'Form Values'); // Save some original data in the attributes of the connection for later API calls. $attributes = []; $attributes[$this->getProviderKey()] = ['AccessToken' => $accessToken, 'Profile' => $profile]; $form->setFormValue('Attributes', $attributes); $sender->EventArguments['Profile'] = $profile; $sender->EventArguments['Form'] = $form; $this->log('Base Connect Data Before OAuth Event', ['profile' => $profile, 'form' => $form]); // Throw an event so that other plugins can add/remove stuff from the basic sso. $sender->fireEvent('OAuth'); SpamModel::disabled(true); $sender->setData('Trusted', true); $sender->setData('Verified', true); }