<commit_before><?php

/*
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * ysfOAuthUser will use oauth for authentication management and openid for identity management.
 *
 * @package    ysfOpenPlugin
 * @subpackage user
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: ysfOAuthUser.class.php 11694 2008-09-21 08:26:37Z fabien $
 */
class ysfOAuthUser extends ysfOpenIDUser
{

  protected
    $clients = array();

  /**
   * Initializes this ysfOAuthUser.
   *
   * Available options:
   *
   *  * auto_shutdown:                   Whether to automatically save the changes to the session (true by default)
   *  * culture:                         The user culture
   *  * default_culture:                 The default user culture (en by default)
   *  * use_flash:                       Whether to enable flash usage (false by default)
   *  * logging:                         Whether to enable logging (false by default)
   *
   * @param sfEventDispatcher $dispatcher  An sfEventDispatcher instance.
   * @param sfStorage         $storage     An sfStorage instance.
   * @param array             $options     An associative array of options.
   *
   * @return Boolean          true, if initialization completes successfully, otherwise false.
   */
  public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
  {
    parent::initialize($dispatcher, $storage, $options);

    // handle yap users
    if(isset($_REQUEST['yap_appid'], $_REQUEST['yap_viewer_guid']))
    {
      $username = $_REQUEST['yap_viewer_guid'].'@<EMAIL>';
      $this->login($username, array());
      $this->addCredential('openid');
    }

    // user is logged in via open id
    if($this->isAuthenticated())
    {
      if($this->isYahoo()) // yahoo open id
      {
        if(isset($_REQUEST['yap_appid'], $_REQUEST['yap_viewer_access_token'], $_REQUEST['yap_viewer_access_token_secret'], $_REQUEST['oauth_signature']))
        {
          // yahoo yap application
          $this->setOAuthClient('yahoo', new ysfYahooOAuthClient($this->dispatcher, new OAuth($this->options['yahoo_yap_consumer_key'], $this->options['yahoo_yap_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION), array('logging' => $this->options['logging'])));
          $this->getOAuthClient('yahoo')->setToken($_REQUEST['yap_viewer_access_token'], $_REQUEST['yap_viewer_access_token_secret']);
          $this->addCredential('oauth-yahoo');

          if ($this->options['logging'])
          {
            $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('User is for Yahoo! open application id: %s, validated oauth token, adding credential oauth-yahoo', var_export($_REQUEST['yap_appid'], true)))));
          }
        }
        else
        {
          // yahoo oauth application
          $this->setOAuthClient('yahoo', new ysfYahooOAuthClient($this->dispatcher, new OAuth($this->options['yahoo_oauth_consumer_key'], $this->options['yahoo_oauth_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION), array('logging' => $this->options['logging'])));
          $oauthAccessToken = $this->getAttribute('yahoo_oauth_access_token');
          if(isset($oauthAccessToken['oauth_token'], $oauthAccessToken['oauth_token_secret']))
          {
            // set user oauth token
            $this->getOAuthClient('yahoo')->setToken($oauthAccessToken['oauth_token'], $oauthAccessToken['oauth_token_secret']);
            $this->addCredential('oauth-yahoo');

            if ($this->options['logging'])
            {
              $this->dispatcher->notify(new sfEvent($this, 'application.log', array('User is for Yahoo! OAuth standalone, validated oauth token, adding credential oauth-yahoo')));
            }

            // load profile if token is expired or expires in next minute than refresh access token
            $oauthAccessToken = $this->getAttribute('yahoo_oauth_access_token');
            try {
              $data = $this->getOAuthClient('yahoo')->getProfile($oauthAccessToken['xoauth_yahoo_guid']);
            }
            catch(OAuthException $e)
            {
              $this->getOAuthClient('yahoo')->getConsumer()->setAuthType(OAUTH_AUTH_TYPE_URI);
              $oauthAccessToken = $this->getOAuthClient('yahoo')->getAccessToken($oauthAccessToken['oauth_token'], $oauthAccessToken['oauth_token_secret'], $oauthAccessToken['oauth_session_handle']);
              $this->setAttribute('yahoo_oauth_access_token', $oauthAccessToken);

              if ($this->options['logging'])
              {
                $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Refreshing access token for scalable OAuthoken')));
              }

              $this->getOAuthClient('yahoo')->setToken($oauthAccessToken['oauth_token'], $oauthAccessToken['oauth_token_secret']);
              $this->getOAuthClient('yahoo')->getConsumer()->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
<commit_msg>ysfOpenPlugin [trunk]: ignore ssl errors in debug mode<commit_after><?php

/*
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

 /**
  User
   -> Profile (profile -> import from openid or oauth (profile endpoints = google, yahoo, twitter)
   -> Identity (openid)
   -> Authorization (oauth)
 **/

/**
 * ysfOAuthUser will use oauth for authentication management and openid for identity management.
 *
 * @package    ysfOpenPlugin
 * @subpackage user
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: ysfOAuthUser.class.php 11694 2008-09-21 08:26:37Z fabien $
 */
class ysfOAuthUser extends ysfOpenIDUser
{

  protected
    $clients = array();

  /**
   * Initializes this ysfOAuthUser.
   *
   * Available options:
   *
   *  * auto_shutdown:                   Whether to automatically save the changes to the session (true by default)
   *  * culture:                         The user culture
   *  * default_culture:                 The default user culture (en by default)
   *  * use_flash:                       Whether to enable flash usage (false by default)
   *  * logging:                         Whether to enable logging (false by default)
   *
   * @param sfEventDispatcher $dispatcher  An sfEventDispatcher instance.
   * @param sfStorage         $storage     An sfStorage instance.
   * @param array             $options     An associative array of options.
   *
   * @return Boolean          true, if initialization completes successfully, otherwise false.
   */
  public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
  {
    parent::initialize($dispatcher, $storage, $options);

    // addOAuthClient: google = oauth-google, twitter = oauth-twitter, yahoo = oauth-yahoo
    // add events for auth registration / check credentials

    // handle yap users
    if(isset($_REQUEST['yap_appid'], $_REQUEST['yap_viewer_guid']))
    {
      $username = $_REQUEST['yap_viewer_guid'].'<EMAIL>';
      $this->login($username, array());
      $this->addCredential('openid');
    }

    // user is logged in via open id
    if($this->isAuthenticated())
    {
      if($this->isYahoo()) // yahoo open id
      {
        if(isset($_REQUEST['yap_appid'], $_REQUEST['yap_viewer_access_token'], $_REQUEST['yap_viewer_access_token_secret'], $_REQUEST['oauth_signature']))
        {
          // yahoo yap application
          $this->setOAuthClient('yahoo', new ysfYahooOAuthClient($this->dispatcher, new OAuth($this->options['yahoo_yap_consumer_key'], $this->options['yahoo_yap_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION), array('logging' => $this->options['logging'])));
          $this->getOAuthClient('yahoo')->setToken($_REQUEST['yap_viewer_access_token'], $_REQUEST['yap_viewer_access_token_secret']);
          $this->addCredential('oauth-yahoo');

          if ($this->options['logging'])
          {
            $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('User is for Yahoo! open application id: %s, validated oauth token, adding credential oauth-yahoo', var_export($_REQUEST['yap_appid'], true)))));
          }
        }
        else
        {
          // yahoo oauth application
          $this->setOAuthClient('yahoo', new ysfYahooOAuthClient($this->dispatcher, new OAuth($this->options['yahoo_oauth_consumer_key'], $this->options['yahoo_oauth_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION), array('logging' => $this->options['logging'])));
          if(sfConfig::get('sf_debug'))
          {
            $this->getOAuthClient('yahoo')->getConsumer()->disableSSLChecks();
          }

          $oauthAccessToken = $this->getAttribute('yahoo_oauth_access_token');
          if(isset($oauthAccessToken['oauth_token'], $oauthAccessToken['oauth_token_secret']))
          {
            // set user oauth token
            $this->getOAuthClient('yahoo')->setToken($oauthAccessToken['oauth_token'], $oauthAccessToken['oauth_token_secret']);
            $this->addCredential('oauth-yahoo');

            if ($this->options['logging'])
            {
              $this->dispatcher->notify(new sfEvent($this, 'application.log', array('User is for Yahoo! OAuth standalone, validated oauth token, adding credential oauth-yahoo')));
            }

            // load profile if token is expired or expires in next minute than refresh access token
            $oauthAccessToken = $this->getAttribute('yahoo_oauth_access_token');
            try {
              $data = $this->getOAuthClient('yahoo')->getProfile($oauthAccessToken['xoauth_yahoo_guid']);
            }
            catch(OAuthException $e)
            {
              $this->getOAuthClient('yahoo')->getConsumer()->setAuthType(OAUTH_AUTH_TYPE_URI);
              $oauthAccessToken = $this->getOAuthClient('yahoo')->getAccessToken($oauthAccessToken['oauth_token'], $oauthAccessToken['oauth_token_secret'], $oauthAccessToken['oauth_session_handle']);
              $this->setAttribute('yahoo_oauth_access_token', $oauthAccessToken);

              if ($this->options['logging'])
              {
                $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Refreshing access token for scalable OAuthoken')));
              }

              $this->getOAuthClient('yahoo')->setToken($oauthAccessToken['oauth_token'], $oauthAccessToken['oauth_token_secret']);
              $this->getOAuthClient('yahoo')->getConsumer()->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);

{'fraction_non_alphanumeric': 0.13089545241443976, 'fraction_numerical': 0.003938115330520394, 'mean_word_length': 3.155044799376704, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 110, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4489038', 'n_tokens_mistral': 3117, 'n_tokens_neox': 2984, 'n_words': 618}