예제 #1
0
 public static function generateSso(ContainerInterface $container, $displayName)
 {
     // https://developer.uservoice.com/docs/single-sign-on/single-sign-on/
     $supportedLocales = array('ar', 'bg', 'cn', 'cz', 'da', 'de', 'en', 'es', 'et', 'fi', 'fr', 'fr-CA', 'he', 'hr', 'it', 'ja', 'lv', 'nl', 'no_NB', 'pl', 'pt', 'pt_BR', 'ro', 'ru', 'sk', 'sl', 'sr', 'sr-Latn', 'sv-SE', 'tr', 'zh-TW');
     // Deduce the best locale according to UserVoice constraints
     $currentLocale = $container->get('request')->getLocale();
     $locale = Locale::lookup($supportedLocales, $currentLocale, true, 'en');
     // Read configuration
     $domain = UserVoiceHelper::getParameter($container, 'domain');
     $ssoKey = UserVoiceHelper::getParameter($container, 'sso_key');
     if (!$ssoKey || !$domain) {
         return null;
     }
     // Assume the user_id is email based
     $user = UserVoiceHelper::getUser($container);
     if (!$user) {
         return null;
     }
     $userId = $user->getUsername();
     $ssoToken = SSO::generate_token($domain, $ssoKey, array('guid' => $userId, 'display_name' => $displayName, 'email' => $userId, 'locale' => $locale));
     return $ssoToken;
 }
 /**
  * Decorate the given URL with an UserVoice SSO token
  *
  * @param string $url
  */
 public function getUserVoiceSso($userName)
 {
     return UserVoiceHelper::generateSso($this->container, $userName);
 }