/** * Creates a provider configuration from a template * * @param string $providerId * @param array|BaseProviderConfig $config Additional configuration options or overrides * @param string $fromTemplate The template to use if different from $providerId * * @throws \DreamFactory\Oasys\Exceptions\OasysConfigurationException * @return ProviderConfigLike */ public static function createFromTemplate($providerId, $config = null, $fromTemplate = null) { /** @var array $_defaults */ $_defaults = static::getTemplate($fromTemplate ?: $providerId); if (empty($_defaults)) { Log::notice('Auto-template for "' . $providerId . '" not found.'); $_defaults = array(); } // Merge in the template, stored stuff and user supplied stuff $_config = null !== $config ? array_merge($_defaults, Option::clean($config)) : $_defaults; Option::set($_config, 'provider_id', $providerId); if (null === ($_type = Option::get($_config, 'type'))) { throw new OasysConfigurationException('You must specify the "type" of provider when using auto-generated configurations.'); } $_typeName = ProviderConfigTypes::nameOf($_type); // Build the class name for the type of authentication of this provider $_class = str_ireplace('oauth', 'OAuth', BaseProvider::DEFAULT_CONFIG_NAMESPACE . ucfirst(Inflector::deneutralize(strtolower($_typeName) . '_provider_config'))); // Log::debug( 'Determined class of service to be: ' . $_typeName . '::' . $_class ); // Instantiate! return new $_class($_config); }
/** * 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)); }