bramus / router

A lightweight and simple object oriented PHP Router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow $_GET REQUEST

aouniradouan opened this issue · comments

Hi, i'm trying to integrate OAuth2 in my application, and when i try to get the call back from Google it's show me error state and code (GET Method) Undefined index
my code look like that
$OxRouting->get('/google/callback', function() { $google = new OAuth; // Run Google API $google->OAuth_Run("Google", true); });
function look like that
`
public function OAuth_Run($ProviderName, $IsCallback = false){

	$provider = $this->ServiceProvider($ProviderName);

    if (! isset ( $_GET['code'] ) ) {

        // If we don't have an authorization code then get one
        $authUrl = $provider->getAuthorizationUrl();
        $_SESSION['oauth2state'] = $provider->getState();
        header('Location: '.$authUrl);
        exit;

    // Check given state against previously stored one to mitigate CSRF attack
    }elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
        unset($_SESSION['oauth2state']);
        exit('Invalid state');
    }else{
        // Try to get an access token (using the authorization code grant)
        $token = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);
	}

	if ($IsCallback == true) {
        // Optional: Now you have a token you can look up a users profile data
        try {

            // We got an access token, let's now get the user's details
            $user = $provider->getResourceOwner($token);

            // Use these details to create a new profile
            printf('Hello %s!', $user->getNickname());

        } catch (Exception $e) {

            // Failed to get user details
            exit('Oh dear...');
        }

	}


    // Use this to interact with an API on the users behalf
    return $user->getNickname();

}

`

commented

Are you running nginx web server? This might help https://serverfault.com/a/998607

No i'm running it on apache server

commented

Can you post here your .htaccess?

`

Tell PHP that the mod_rewrite module is ENABLED.

SetEnv HTTP_MOD_REWRITE On

Options FollowSymLinks

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

The rest of your rewrite rules here

RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]

RewriteRule ([^/]+)/?$ index.php?id=$1 [NC,L]

#RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ index.php?c=$1&d=$2 [NC,L]

Handle product requests

`

YEAH, it's really work thank you very much sir

commented