Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [inny]Laravel 5.8 + passport
jarober77
post 9.06.2021, 20:34:36
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 8.04.2019

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


Wiatm mam problem z uruchomienie przykladowej aplikacji tworzacej REST
https://www.itsolutionstuff.com/post/build-...pleexample.html

a wiec

Passport Version: 7.5.1
Laravel Version: 5.8
PHP Version: 7.2.22
Database Driver & Version: 10.4.6-MariaDB




kroki wykonalem zgodnie z insgrukcja podana w liku wyzej
czyli:
laravel new project
composer require laravel/passport:7.5.1
php artisan migrate
php artisan passport:install

Dodawanie uzytkownika dziala prawidlowo (endpiont register)
ale juz oauth/token uruchamiany w Postmen:

(POST)
http://localhost:8000/oauth/token?grant_ty...234&scope=*

generuje błąd:

{
"error": "unsupported_grant_type",
"error_description": "The authorization grant type is not supported by the authorization server.",
"hint": "Check that all required parameters have been provided",
"message": "The authorization grant type is not supported by the authorization server."
}

cokolwiek bym nei zmienil w parametrach, nawet bzdury wpisywal lub wywalil wszytskie parametry błąd zawsze jest ten sam.
Podam jeszcze headers jak ustawiam w Postmen
User-Agent: PostmanRuntime/7.28.0
Content-Length: 0
Host: <calculated when request is sent>
Content-Type: application/x-www-form-urlencoded
Accept: application/json

W abzie danych powstaja rekordy
oauth_clients:
1 Laravel Personal Access Client U3UoVzL1pmSPDfnI0tbhQDSJE0eJSQyNFKtNVGJB http://localhost 1 0
2 Laravel Password Grant Client dkjAWgtHOhL8Pzg0hGLlJjHwoxM7j8FTFnQVK07z http://localhost 0 1

oauth_access_tokens:
47ab2bba2b9e23bcc896f022f98d10361b6627549e9f9db18e8e0f73ab28a4be0d2f6bc8d189b234 1 1 MyApp [] 0 2021-06-09 18:41:37 2021-06-09 18:41:37 2022-06-09 18:41:37


oauth_personal_access_clients:
1 1 2021-06-09 18:40:22 2021-06-09 18:40:22


users
1 user02@email.com user02@email.com $2y$10$qEsQ5edPvyIbQvdp1pEOPOzCkKfG9I6PDuZWPRqqs0rNlwDebMecK 2021-06-09 18:41:37 2021-06-09 18:41:37


Nie potrafie sobie z tym poradzic, pomoze ktos??
Go to the top of the page
+Quote Post
Pyton_000
post 10.06.2021, 19:46:57
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Spróbuj odpalić

php artisan passport:client --password

(nie mam laravela, ale znalazłem to w dokumentacji)
Go to the top of the page
+Quote Post
jarober77
post 11.06.2021, 14:21:54
Post #3





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 8.04.2019

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


Cytat(Pyton_000 @ 10.06.2021, 20:46:57 ) *
Spróbuj odpalić

php artisan passport:client --password

(nie mam laravela, ale znalazłem to w dokumentacji)


Dzieki bardzo. Zrobiłem tak i okazało sie ze do tabeli oauth_clients dodał sie rekord
'3', NULL, 'password', 'Bi8AFTtXsDWSvH26ZAJkTfBkabJCVolHetBlbx4g', 'http://rest-test.jar', '0', '1', '0', '2021-06-11 12:10:22', '2021-06-11 12:10:22'

az oczy mi sie zapaliły smile.gif
Czym predzej otworzyłem Postmena i wpisałem do client_id: 3 a do client_secret: Bi8AFTtXsDWSvH26ZAJkTfBkabJCVolHetBlbx4g
.... niestety wynik

{
"error": "unsupported_grant_type",
"error_description": "The authorization grant type is not supported by the authorization server.",
"hint": "Check that all required parameters have been provided",
"message": "The authorization grant type is not supported by the authorization server."
}

Podszedłem inaczej do tematu. Napisałęm swoja funkcje w kontrolerze

public function login(Request $request) {
$validator = Validator::make($request->all(), [
'user' => 'required|string|email',
'password' => 'required'
]);

if($validator->fails()){
return $this->sendError('Validation Error.', $validator->errors());
}

$credentials = request(['email', 'password']);
if(!Auth::attempt(['email' => $request->user, 'password' => $request->password])){
$error = "Unauthorized";
return $this->sendError($error, 401);
}
$user = $request->user();
$success['token'] = $user->createToken('token')->accessToken;
return $this->sendResponse($success, 'User loggined.');
}

do Routes/Api dodałem oczywiscie
Route::get('login', 'API\AuthController@login');

i działa, zwraca mi token, ktory pozniej działa z innym endpiontami.
Ale to i tak mnie nie cieszy....bo to chyba nie jest jak powinno byc z wykorzystaniem Aouth2 jak nalezy. Cos jest nie tak i nikt nie moze mi pomoc sad.gif((((((((((((((((((
Go to the top of the page
+Quote Post
viking
post 12.06.2021, 09:43:55
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


A przesyłasz w danych grant_type?


--------------------
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: 16.04.2024 - 15:44