1

Hi I am using the artdarek oauth for google login in laravel. I have written the route like the following: Route::get('usersgoogle','logingoogleController@loginwithGoogle'); I am using the same code shown in the oauth documentaion https://github.com/artdarek/oauth-4-laravel (the example for google consumer).

My controller:

class logingoogleController extends BaseController {

    public function loginWithGoogle() {

        // get data from input
        $code = Input::get( 'code' );

        // get google service
        $googleService = OAuth::consumer( 'Google' );
        //echo $googleService;
        // check if code is valid

        // if code is provided get user data and sign in
        if ( !empty( $code ) ) {

            // This was a callback request from google, get the token
            $token = $googleService->requestAccessToken( $code );

            // Send a request with it
            $result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );

            $message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
            echo $message. "<br/>";

            //Var_dump
            //display whole array().
            dd($result);

        }
        // if not ask for permission first
        else {
            // get googleService authorization
            $url = $googleService->getAuthorizationUri();

            // return to google login url
            return Redirect::to( (string)$url );
            //echo "Hi";
        }
    }

}

Now in the google developers I have created a project,created a client id and have specified the redirect uri like the following: http://domainname.com/usersgoogle I have tried with http://domainname.com/usersgoogle/ -'/' at the last but every time its showing me redirect_uri_mismatch error. Can any one tell me what is the right way to do it? what I am doing wrong here?

My google console is like the following: enter image description here

Please help. Thanks in advanced...

3
  • were you able to find a solution to your problem? you mentioned nothing about the config, maybe that's the problem. Commented Sep 12, 2014 at 4:35
  • config I have used the same as was mentioned in the documentation.....I have got the problem now...the url what was generating from laravel was not the same as was there defined in google developers console. I am using hybrid auth instead Commented Sep 13, 2014 at 13:49
  • try deleting your current client id then create a new one. Commented Sep 25, 2014 at 5:41

1 Answer 1

1

Replace

$googleService = OAuth::consumer( 'Google' );

with

$googleService = OAuth::consumer( 'Google',REDIRECT URIS );

REDIRECT URIS given from your clientID

Sign up to request clarification or add additional context in comments.

1 Comment

even use Artdarek\OAuth\Facade\OAuth::consumer('Google',REDIRECT URIS ) as mine OAuth::consumer() is not working

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.