Laravel Socialite Request Returns Null











up vote
0
down vote

favorite
1












I'm using Laravel Socialite 5.0.



<?php

use IlluminateHttpRequest;

public function login(AuthenticateUser $authenticateUser, Request $request){
return $authenticateUser->execute($request->has('code'));
}


$request->has('code') always returns null. Why is that?
Providing my AuthenticateUser class I see this as a redirect/request problem.



<?php 

namespace App;

use LaravelSocialiteContractsFactory as Socialite;
use IlluminateContractsAuthGuard as Guard;
use AppRepositoriesUserRepository as UserRepository;
use Log;

class AuthenticateUser {

private $users;
private $socialite;
private $auth;

public function __construct (UserRepository $users, Socialite $socialite, Guard $auth) {
$this->users = $users;
$this->socialite = $socialite;
$this->auth = $auth;
}

public function execute ($hasCode) {
if( ! $hasCode){
Log::info('1');
return $this->getAuthorizationFirst();
}
Log::info('2');
$user = $this->socialite->driver('github')->user();
}

public function getAuthorizationFirst(){
return $this->socialite->driver('github')->redirect();
}

}


Adding the AuthController Class for reference:



class AuthController extends Controller {

/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/

use AuthenticatesAndRegistersUsers;

/**
* Create a new authentication controller instance.
*
* @param IlluminateContractsAuthGuard $auth
* @param IlluminateContractsAuthRegistrar $registrar
* @return void
*/
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;

$this->middleware('guest', ['except' => 'getLogout']);
}

public function login(AuthenticateUser $authenticateUser, Request $request){
Log::info('_'.$request->has('code').'_');
return $authenticateUser->execute($request->has('code'));
}

}









share|improve this question
























  • I am following the laracast tutorial: laracasts.com/series/whats-new-in-laravel-5/episodes/9 But just not able to pass through this has('code').
    – Aditya Kappagantula
    Sep 11 '15 at 6:59










  • How does the form that triggers the function look like?
    – Szenis
    Sep 11 '15 at 7:07










  • Its not a form. I just trigger the route. <a class="btn btn-block btn-social btn-github" href={{ url('/github/auth') }}> <i class="fa fa-github"></i> Sign in with Github </a>
    – Aditya Kappagantula
    Sep 11 '15 at 7:12










  • can you post your authenticate user class?
    – Szenis
    Sep 11 '15 at 8:32










  • Done. posted code.
    – Aditya Kappagantula
    Sep 11 '15 at 8:35















up vote
0
down vote

favorite
1












I'm using Laravel Socialite 5.0.



<?php

use IlluminateHttpRequest;

public function login(AuthenticateUser $authenticateUser, Request $request){
return $authenticateUser->execute($request->has('code'));
}


$request->has('code') always returns null. Why is that?
Providing my AuthenticateUser class I see this as a redirect/request problem.



<?php 

namespace App;

use LaravelSocialiteContractsFactory as Socialite;
use IlluminateContractsAuthGuard as Guard;
use AppRepositoriesUserRepository as UserRepository;
use Log;

class AuthenticateUser {

private $users;
private $socialite;
private $auth;

public function __construct (UserRepository $users, Socialite $socialite, Guard $auth) {
$this->users = $users;
$this->socialite = $socialite;
$this->auth = $auth;
}

public function execute ($hasCode) {
if( ! $hasCode){
Log::info('1');
return $this->getAuthorizationFirst();
}
Log::info('2');
$user = $this->socialite->driver('github')->user();
}

public function getAuthorizationFirst(){
return $this->socialite->driver('github')->redirect();
}

}


Adding the AuthController Class for reference:



class AuthController extends Controller {

/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/

use AuthenticatesAndRegistersUsers;

/**
* Create a new authentication controller instance.
*
* @param IlluminateContractsAuthGuard $auth
* @param IlluminateContractsAuthRegistrar $registrar
* @return void
*/
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;

$this->middleware('guest', ['except' => 'getLogout']);
}

public function login(AuthenticateUser $authenticateUser, Request $request){
Log::info('_'.$request->has('code').'_');
return $authenticateUser->execute($request->has('code'));
}

}









share|improve this question
























  • I am following the laracast tutorial: laracasts.com/series/whats-new-in-laravel-5/episodes/9 But just not able to pass through this has('code').
    – Aditya Kappagantula
    Sep 11 '15 at 6:59










  • How does the form that triggers the function look like?
    – Szenis
    Sep 11 '15 at 7:07










  • Its not a form. I just trigger the route. <a class="btn btn-block btn-social btn-github" href={{ url('/github/auth') }}> <i class="fa fa-github"></i> Sign in with Github </a>
    – Aditya Kappagantula
    Sep 11 '15 at 7:12










  • can you post your authenticate user class?
    – Szenis
    Sep 11 '15 at 8:32










  • Done. posted code.
    – Aditya Kappagantula
    Sep 11 '15 at 8:35













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I'm using Laravel Socialite 5.0.



<?php

use IlluminateHttpRequest;

public function login(AuthenticateUser $authenticateUser, Request $request){
return $authenticateUser->execute($request->has('code'));
}


$request->has('code') always returns null. Why is that?
Providing my AuthenticateUser class I see this as a redirect/request problem.



<?php 

namespace App;

use LaravelSocialiteContractsFactory as Socialite;
use IlluminateContractsAuthGuard as Guard;
use AppRepositoriesUserRepository as UserRepository;
use Log;

class AuthenticateUser {

private $users;
private $socialite;
private $auth;

public function __construct (UserRepository $users, Socialite $socialite, Guard $auth) {
$this->users = $users;
$this->socialite = $socialite;
$this->auth = $auth;
}

public function execute ($hasCode) {
if( ! $hasCode){
Log::info('1');
return $this->getAuthorizationFirst();
}
Log::info('2');
$user = $this->socialite->driver('github')->user();
}

public function getAuthorizationFirst(){
return $this->socialite->driver('github')->redirect();
}

}


Adding the AuthController Class for reference:



class AuthController extends Controller {

/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/

use AuthenticatesAndRegistersUsers;

/**
* Create a new authentication controller instance.
*
* @param IlluminateContractsAuthGuard $auth
* @param IlluminateContractsAuthRegistrar $registrar
* @return void
*/
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;

$this->middleware('guest', ['except' => 'getLogout']);
}

public function login(AuthenticateUser $authenticateUser, Request $request){
Log::info('_'.$request->has('code').'_');
return $authenticateUser->execute($request->has('code'));
}

}









share|improve this question















I'm using Laravel Socialite 5.0.



<?php

use IlluminateHttpRequest;

public function login(AuthenticateUser $authenticateUser, Request $request){
return $authenticateUser->execute($request->has('code'));
}


$request->has('code') always returns null. Why is that?
Providing my AuthenticateUser class I see this as a redirect/request problem.



<?php 

namespace App;

use LaravelSocialiteContractsFactory as Socialite;
use IlluminateContractsAuthGuard as Guard;
use AppRepositoriesUserRepository as UserRepository;
use Log;

class AuthenticateUser {

private $users;
private $socialite;
private $auth;

public function __construct (UserRepository $users, Socialite $socialite, Guard $auth) {
$this->users = $users;
$this->socialite = $socialite;
$this->auth = $auth;
}

public function execute ($hasCode) {
if( ! $hasCode){
Log::info('1');
return $this->getAuthorizationFirst();
}
Log::info('2');
$user = $this->socialite->driver('github')->user();
}

public function getAuthorizationFirst(){
return $this->socialite->driver('github')->redirect();
}

}


Adding the AuthController Class for reference:



class AuthController extends Controller {

/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/

use AuthenticatesAndRegistersUsers;

/**
* Create a new authentication controller instance.
*
* @param IlluminateContractsAuthGuard $auth
* @param IlluminateContractsAuthRegistrar $registrar
* @return void
*/
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;

$this->middleware('guest', ['except' => 'getLogout']);
}

public function login(AuthenticateUser $authenticateUser, Request $request){
Log::info('_'.$request->has('code').'_');
return $authenticateUser->execute($request->has('code'));
}

}






php laravel laravel-5 laravel-socialite laravel-request






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 9:56









Karl Hill

1,9031736




1,9031736










asked Sep 11 '15 at 6:58









Aditya Kappagantula

3611416




3611416












  • I am following the laracast tutorial: laracasts.com/series/whats-new-in-laravel-5/episodes/9 But just not able to pass through this has('code').
    – Aditya Kappagantula
    Sep 11 '15 at 6:59










  • How does the form that triggers the function look like?
    – Szenis
    Sep 11 '15 at 7:07










  • Its not a form. I just trigger the route. <a class="btn btn-block btn-social btn-github" href={{ url('/github/auth') }}> <i class="fa fa-github"></i> Sign in with Github </a>
    – Aditya Kappagantula
    Sep 11 '15 at 7:12










  • can you post your authenticate user class?
    – Szenis
    Sep 11 '15 at 8:32










  • Done. posted code.
    – Aditya Kappagantula
    Sep 11 '15 at 8:35


















  • I am following the laracast tutorial: laracasts.com/series/whats-new-in-laravel-5/episodes/9 But just not able to pass through this has('code').
    – Aditya Kappagantula
    Sep 11 '15 at 6:59










  • How does the form that triggers the function look like?
    – Szenis
    Sep 11 '15 at 7:07










  • Its not a form. I just trigger the route. <a class="btn btn-block btn-social btn-github" href={{ url('/github/auth') }}> <i class="fa fa-github"></i> Sign in with Github </a>
    – Aditya Kappagantula
    Sep 11 '15 at 7:12










  • can you post your authenticate user class?
    – Szenis
    Sep 11 '15 at 8:32










  • Done. posted code.
    – Aditya Kappagantula
    Sep 11 '15 at 8:35
















I am following the laracast tutorial: laracasts.com/series/whats-new-in-laravel-5/episodes/9 But just not able to pass through this has('code').
– Aditya Kappagantula
Sep 11 '15 at 6:59




I am following the laracast tutorial: laracasts.com/series/whats-new-in-laravel-5/episodes/9 But just not able to pass through this has('code').
– Aditya Kappagantula
Sep 11 '15 at 6:59












How does the form that triggers the function look like?
– Szenis
Sep 11 '15 at 7:07




How does the form that triggers the function look like?
– Szenis
Sep 11 '15 at 7:07












Its not a form. I just trigger the route. <a class="btn btn-block btn-social btn-github" href={{ url('/github/auth') }}> <i class="fa fa-github"></i> Sign in with Github </a>
– Aditya Kappagantula
Sep 11 '15 at 7:12




Its not a form. I just trigger the route. <a class="btn btn-block btn-social btn-github" href={{ url('/github/auth') }}> <i class="fa fa-github"></i> Sign in with Github </a>
– Aditya Kappagantula
Sep 11 '15 at 7:12












can you post your authenticate user class?
– Szenis
Sep 11 '15 at 8:32




can you post your authenticate user class?
– Szenis
Sep 11 '15 at 8:32












Done. posted code.
– Aditya Kappagantula
Sep 11 '15 at 8:35




Done. posted code.
– Aditya Kappagantula
Sep 11 '15 at 8:35












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










The problem was with the return url route!
I was returning to a wrong route from the application.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32517421%2flaravel-socialite-request-returns-null%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    The problem was with the return url route!
    I was returning to a wrong route from the application.






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      The problem was with the return url route!
      I was returning to a wrong route from the application.






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        The problem was with the return url route!
        I was returning to a wrong route from the application.






        share|improve this answer












        The problem was with the return url route!
        I was returning to a wrong route from the application.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 12 '15 at 20:20









        Aditya Kappagantula

        3611416




        3611416






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32517421%2flaravel-socialite-request-returns-null%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine