0

I am trying to set up the oauth2 authentication system (for Facebook specifically) for Laravel 4 seen here: https://github.com/madewithlove/laravel-oauth2

I have a controller, Oauth2Controller.php, that controls this. I am trying to include the the necessary files in the package into my controller. Following the example for that repository, I use:

use OAuth2\OAuth2;
use OAuth2\Token_Access;
use OAuth2\Exception as OAuth2_Exception;

However, when I run the page, it is throwing an error for these lines. Saying:

Symfony \ Component \ Debug \ Exception \ FatalErrorException
syntax error, unexpected 'as' (T_AS), expecting ',' or ';' or '{'

It references directly the third line: use OAuth2\Exception as OAuth2_Exception;

I am not sure why it is throwing this error.

Here is the full code of my controller:

<?php 

class Oauth2Controller extends BaseController
{

    use OAuth2\OAuth2;
    use OAuth2\Token_Access;
    use OAuth2\Exception as OAuth2_Exception;

    public function getIndex($provider) {


        $provider = OAuth2::provider($provider, array(
        'id' => '**************',
        'secret' => '******************',
        ));

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

            return $provider->authorize();

        }

        else
    {
        // Howzit?
        try
        {
            $params = $provider->access($_GET['code']);

                $token = new Token_Access(array(
                    'access_token' => $params->access_token
                ));
                $user = $provider->get_user_info($token);

            // Here you should use this information to A) look for a user B) help a new user sign up with existing data.
            // If you store it all in a cookie and redirect to a registration page this is crazy-simple.
            echo "<pre>";
            var_dump($user);
        }

        catch (OAuth2_Exception $e)
        {
            show_error('That didnt work: '.$e);
        }
    }

    }


}

In my routes, to get to the page, I have:

Route::get('oauth/{provider}', 'Oauth2Controller@getIndex');

THank you for your help and insights!

1 Answer 1

1

I have never seen a use clause (in this context, at least) within a controller's definitions.

Try placing the three clauses above class. Those need to import the namespaces for use in your class:

use <class>;
use <class> as {a_class}
...

class <name> ... {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.