2015-09-11 4 views
0

Я использую Larave 5.0 Socialite.Laravel Socialite Запрос на возврат

Вот мой код:

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

$ request-> имеет ('код') всегда возвращает нуль. Зачем? Предоставление класса AuthenticateUser. Я рассматриваю это как проблему с перенаправлением/запросом.

<?php namespace App; 

use Laravel\Socialite\Contracts\Factory as Socialite; 
use Illuminate\Contracts\Auth\Guard as Guard; 
use App\Repositories\UserRepository 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(); 
    } 

} 

Добавление AuthController класса для справки:

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 \Illuminate\Contracts\Auth\Guard $auth 
    * @param \Illuminate\Contracts\Auth\Registrar $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')); 
    } 

} 
+0

Я следую руководству по laracast: https://laracasts.com/series/whats-new-in-laravel-5/episodes/9 Но просто не смог пройти через это ('code'). –

+0

Как выглядит форма, вызывающая функцию? – Szenis

+0

Его не форма. Я просто запускаю маршрут. \t \t \t \t \t \t \t \t \t \t \t \t Sign in with Github \t \t \t \t \t \t

ответ

0

Проблема была с маршрутом возвратного URL! Я возвращался к неправильному маршруту из приложения.

Смежные вопросы