Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [laravel] problem z logowaniem przez facebooka
tomi001
post 7.03.2018, 10:29:08
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.03.2018

Ostrzeżenie: (0%)
-----


Mam taki problem mam wpisaną domenę na facebooku w tym adresie https://developers.facebook.com/apps i to jest ustawione na on nawet ustawiłem Client OAuth Login na wyłączone i to nie dało rezultatu, ale do rzeczy jak klikma zaloguj przez facrbooka to dostaje komunikat

Adres URL zablokowany: To przekierowanie nie powiodło się, ponieważ identyfikator URI nie jest na liście dozwolonych identyfikatorów w ustawieniach aplikacji klienta OAuth. Upewnij się, że klient i sieciowy login OAuth są włączone i dodaj wszystkie swoje domeny aplikacji jako ważne adresy URI przekierowań OAuth.
Go to the top of the page
+Quote Post
r4xz
post 7.03.2018, 14:10:24
Post #2





Grupa: Zarejestrowani
Postów: 673
Pomógł: 106
Dołączył: 31.12.2008

Ostrzeżenie: (0%)
-----


Musiałbyś pokazać jak to robisz w kodzie, co zrobiłeś. Pokaż jak wygląda Twój redirect_uri, upewnij się czy masz pod takim adresem obsługę OAuth2, w Laravel w przykładzie jest to metoda handleProviderCallback.


--------------------
Go to the top of the page
+Quote Post
tomi001
post 7.03.2018, 19:35:52
Post #3





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.03.2018

Ostrzeżenie: (0%)
-----


  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Foundation\Bus\DispatchesJobs;
  6. use Illuminate\Routing\Controller as BaseController;
  7. use Illuminate\Foundation\Validation\ValidatesRequests;
  8. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  9. use Blog\Article;
  10. use Auth;
  11. use Illuminate\Http\Request;
  12. use Socialite;
  13. class AuthController extends Controller
  14. {
  15. // Some methods which were generated with the app
  16.  
  17. /**
  18.   * Redirect the user to the OAuth Provider.
  19.   *
  20.   * @return Response
  21.   */
  22.  
  23. public function redirectToProvider($provider)
  24. {
  25. return Socialite::driver($provider)->redirect();
  26. }
  27.  
  28. /**
  29.   * Obtain the user information from provider. Check if the user already exists in our
  30.   * database by looking up their provider_id in the database.
  31.   * If the user exists, log them in. Otherwise, create a new user then log them in. After that
  32.   * redirect them to the authenticated users homepage.
  33.   *
  34.   * @return Response
  35.   */
  36. public function handleProviderCallback($provider)
  37. {
  38. $user = Socialite::driver($provider)->user();
  39.  
  40. $authUser = $this->findOrCreateUser($user, $provider);
  41. Auth::login($authUser, true);
  42. return redirect($this->redirectTo);
  43. }
  44.  
  45. /**
  46.   * If a user has registered before using social auth, return the user
  47.   * else, create a new user object.
  48.   * @param $user Socialite user object
  49.   * @param $provider Social auth provider
  50.   * @return User
  51.   */
  52. public function findOrCreateUser($user, $provider)
  53. {
  54. $authUser = User::where('provider_id', $user->id)->first();
  55. if ($authUser) {
  56. return $authUser;
  57. }
  58. return User::create([
  59. 'name' => $user->name,
  60. 'email' => $user->email,
  61. 'provider' => $provider,
  62. 'provider_id' => $user->id
  63. ]);
  64. }
  65.  
  66. }
  67.  
  68.  
  69. ?>


I jeszcze routing

  1. Route::get('aut/{provider}', 'AuthController@redirectToProvider');
  2. Route::get('aut/{provider}/callback', 'AuthController@handleProviderCallback');


A jeszcze dodam, że jak wykonam routing http://domena/laravel/public/aut/facebook/callback

To pojawia się błąd laravela.
(1/1) InvalidStateException

in AbstractProvider.php (line 209)
Go to the top of the page
+Quote Post
Pilsener
post 7.03.2018, 19:51:32
Post #4





Grupa: Zarejestrowani
Postów: 1 590
Pomógł: 185
Dołączył: 19.04.2006
Skąd: Gdańsk

Ostrzeżenie: (0%)
-----


Komunikat jest jasny, masz źle skonfigurowanego klienta OAUTH i/lub źle skonfigurowaną aplikację serwera OAUTH.
Kiedy wysyłasz request do serwera OAUTH musi on zawierać URL, na który serwer OAUTH zwróci odpowiedź (w tym wypadku kod służący do pobrania access tokena). Ten URL musi znajdować się na liście URLi w aplikacji, jeśli go nie ma lub jest zły to dostajesz taki właśnie komunikat.
Go to the top of the page
+Quote Post
tomi001
post 7.03.2018, 20:43:50
Post #5





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.03.2018

Ostrzeżenie: (0%)
-----


Czyli błąd jest w kodzie(laravel) czy w ustawieniach facebooka mógłbyś mi dokładnie opisać jak to się robi.
Go to the top of the page
+Quote Post
r4xz
post 7.03.2018, 23:04:30
Post #6





Grupa: Zarejestrowani
Postów: 673
Pomógł: 106
Dołączył: 31.12.2008

Ostrzeżenie: (0%)
-----


A w facebooku ustawiasz ten przykładowy adres http://domena/laravel/public/aut/facebook/callback? Musi być identyczny jak ten który przekazujesz w redirect_uri. Co do tego exception co napisałeś to wszystko jest ok, po prostu metoda callback musi otrzymać ten sam state który wysłał w metodzie redirectToProvider. Jeśli wywołujesz to ręcznie bez jego podania to nie ma szansa żeby był poprawny


--------------------
Go to the top of the page
+Quote Post
tomi001
post 8.03.2018, 08:25:49
Post #7





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.03.2018

Ostrzeżenie: (0%)
-----


Ale w tej metodzie nie ma, żadnego adresu i teraz pytanie ja muszę to zrobić przez http://demona/laravel/public/aut/facebook/ czy przez http://demona/laravel/public/aut/facebook/callback i jaki adres muszę mieć ustawiony na facebooku w polu Privacy Policy URL i polu Site URL bo jak w polu Policy URL dam inny np taki http://demena/laravel/public/aut/facebook to wyskakuje błąd muszę mieć taki http://demena/laravel/public/
Go to the top of the page
+Quote Post
r4xz
post 8.03.2018, 10:45:55
Post #8





Grupa: Zarejestrowani
Postów: 673
Pomógł: 106
Dołączył: 31.12.2008

Ostrzeżenie: (0%)
-----


Dawno nie robiłem tego z facebookiem, ale teoretycznie powinno Cię interesować tylko coś co może się kryć pod jedną z tych nazw: redirect_uri, fallback_url, callback_url (na githubie jest to pole "Authorization callback URL"). W tym polu musisz podać adres http://demona/laravel/public/aut/facebook/callback, to samo musisz zrobić po stronie Laravela, czyli redirect_uri musisz ustawić na ten właśnie adres.


--------------------
Go to the top of the page
+Quote Post
tomi001
post 8.03.2018, 11:45:09
Post #9





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.03.2018

Ostrzeżenie: (0%)
-----


W momencie kiedy próbuje dodać w pole faceboku Redirect URI to Check to jest takie pole i próbuje dodać nazwę http://domena.pl/aut/facebook/callback

To wyskakuje komunikat

This is an invalid redirect URI for this application
You can make this URI valid by adding it to the list of valid OAuth redirect URIs above
Go to the top of the page
+Quote Post
beelinde
post 18.06.2018, 08:33:00
Post #10





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 18.06.2018

Ostrzeżenie: (0%)
-----


Również walczę z tym problemem... Czy udało się ogarnąć temat? Jeżeli chodzi o poprawne URI to u mnie facebook przyjmuje tylko localhosta, wpisanie domeny z http i https powoduje ten sam komunikat :/ Any idea?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 20:52