<commit_before><?php

/**
 * Fuel is a fast, lightweight, community driven PHP5 framework.
 *
 * @package    Fuel
 * @version    1.0
 * @author     Fuel Development Team
 * @license    MIT License
 * @copyright  2010 - 2011 Fuel Development Team
 * @link       http://fuelphp.com
 */

namespace Hybrid;

/**
 * Hybrid 
 * 
 * A set of class that extends the functionality of FuelPHP without 
 * affecting the standard workflow when the application doesn't actually 
 * utilize Hybrid feature.
 *
 * Authentication Class
 * 
 * Why another class? FuelPHP does have it's own Auth package but what Hybrid does 
 * it not defining how you structure your database but instead try to be as generic 
 * as possible so that we can support the most basic structure available
 * 
 * 
 * @package     Fuel
 * @subpackage  Hybrid
 * @category    Auth_Strategy_OAuth2
 * @author      <NAME> <https://github.com/philsturgeon>
 */

class Auth_Strategy_OAuth2 extends Auth_Strategy 
{
	public $provider;
	
	public function authenticate()
	{
		// Load the provider
		$provider = \OAuth2\Provider::factory($this->provider, $this->config);

		// Grab a callback from the config

		if ($provider->callback === null)
		{
			$provider->callback = \Uri::create(\Config::get('autho.urls.callback', \Request::active()->route->segments[0].'/callback'));
			$provider->callback = rtrim($provider->callback, '/').'/'.$this->provider;
		}
		
		$provider->authorize(array(
			'redirect_uri' => $provider->callback,
		));
	}
	
	public function callback()
	{
		// Load the provider
		$this->provider = \OAuth2\Provider::factory($this->provider, $this->config);
		
		try
		{
			$params = $this->provider->access(\Input::get('code'));<commit_msg>Avoid error when missing code<commit_after><?php

/**
 * Fuel is a fast, lightweight, community driven PHP5 framework.
 *
 * @package    Fuel
 * @version    1.0
 * @author     Fuel Development Team
 * @license    MIT License
 * @copyright  2010 - 2011 Fuel Development Team
 * @link       http://fuelphp.com
 */

namespace Hybrid;

/**
 * Hybrid 
 * 
 * A set of class that extends the functionality of FuelPHP without 
 * affecting the standard workflow when the application doesn't actually 
 * utilize Hybrid feature.
 *
 * Authentication Class
 * 
 * Why another class? FuelPHP does have it's own Auth package but what Hybrid does 
 * it not defining how you structure your database but instead try to be as generic 
 * as possible so that we can support the most basic structure available
 * 
 * 
 * @package     Fuel
 * @subpackage  Hybrid
 * @category    Auth_Strategy_OAuth2
 * @author      <NAME> <https://github.com/philsturgeon>
 */

class Auth_Strategy_OAuth2 extends Auth_Strategy 
{
	public $provider;
	
	public function authenticate()
	{
		// Load the provider
		$provider = \OAuth2\Provider::factory($this->provider, $this->config);

		// Grab a callback from the config

		if ($provider->callback === null)
		{
			$provider->callback = \Uri::create(\Config::get('autho.urls.callback', \Request::active()->route->segments[0].'/callback'));
			$provider->callback = rtrim($provider->callback, '/').'/'.$this->provider;
		}
		
		$provider->authorize(array(
			'redirect_uri' => $provider->callback,
		));
	}
	
	public function callback()
	{
		// Load the provider
		$this->provider = \OAuth2\Provider::factory($this->provider, $this->config);
		
		try
		{
			$code = \Input::get('code');

			if (null === $code)
			{
				throw new Exception("Expected Authorization Code not available");
			}
			
			$params = $this->provider->access();
{'fraction_non_alphanumeric': 0.13030047739399045, 'fraction_numerical': 0.008986239820275204, 'mean_word_length': 3.4413965087281797, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7566634', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1008, 'n_words': 319}