/** * Returns this user as a GenericUser * * @return UserLike * @throws OasysException * @throws \InvalidArgumentException */ public function getUserData() { $_response = parent::getUserData(); if (HttpResponse::Ok != ($_code = Option::get($_response, 'code', Curl::getLastHttpCode()))) { throw new OasysException('Unexpected response code', $_code, null, $_response); } $_profile = Option::get($_response, 'result'); if (empty($_profile)) { throw new \InvalidArgumentException('No profile available to convert.'); } $_profileId = Option::get($_profile, 'id'); $_nameGoogle = Option::get($_profile, 'name'); $_name = array('formatted' => Option::get($_profile, 'displayName'), 'familyName' => Option::get($_nameGoogle, 'familyName'), 'givenName' => Option::get($_nameGoogle, 'givenName')); $_email = null; // Get the account email. Google returns a list of emails. foreach (Option::get($_profile, 'emails') as $_emailIteration) { if (Option::get($_emailIteration, 'type') == 'account') { $_email = Option::get($_emailResult, 'value'); break; // ugly, but works } } return new GenericUser(array('user_id' => $_profileId, 'name' => $_name, 'gender' => Option::get($_profile, 'gender'), 'email_address' => $_email, 'urls' => array(Option::get($_profile, 'url')), 'thumbnail_url' => Option::getDeep($_profile, 'image', 'url'), 'user_data' => $_profile)); }
/** * Testing endpoint for events */ public function actionEventReceiver() { $_request = Pii::requestObject(); $_data = $_request->getContent(); if (is_string($_data)) { $_data = json_decode($_data, true); if (JSON_ERROR_NONE != json_last_error()) { Log::error(' * DSP event could not be converted from JSON.'); return; } } if (isset($_data['details'])) { $_eventName = Option::getDeep($_data, 'details', 'event_name'); Log::debug('DSP event "' . $_eventName . '" received'); return; } Log::error('Weird event received: ' . var_export($_data, true)); }
/** * Returns this user as a GenericUser * * @param \stdClass|array $profile * * @throws \DreamFactory\Oasys\Exceptions\ProviderException * @throws \InvalidArgumentException * @return UserLike */ public function getUserData($profile = null) { /** @noinspection PhpUndefinedMethodInspection */ if (null === ($_url = $this->getIdentityUrl())) { Log::notice('No salesforce identity url.'); return new GenericUser(); } $_profile = $this->fetch($_url); // Log::debug( 'Profile retrieved: ' . print_r( $_profile, true ) ); if (empty($_profile)) { throw new \InvalidArgumentException('No profile available to convert.'); } $_profileId = Option::get($_profile, 'user_id'); $_login = Option::get($_profile, 'username'); $_name = array('familyName' => Option::get($_profile, 'last_name', $_login), 'givenName' => Option::get($_profile, 'first_name', $_login), 'formatted' => Option::get($_profile, 'display_name', $_login)); return new GenericUser(array('provider_id' => $this->getProviderId(), 'user_id' => $_profileId, 'published' => Option::get($_profile, 'last_modified_date'), 'display_name' => $_name['formatted'], 'name' => $_name, 'email_address' => Option::get($_profile, 'email'), 'preferred_username' => $_login, 'urls' => (array) Option::get($_profile, 'urls', array()), 'thumbnail_url' => Option::getDeep($_profile, 'photos', 'thumbnail'), 'updated' => Option::get($_profile, 'last_modified_date'), 'relationships' => array(), 'user_data' => $_profile)); }