Category : laravel-passport

My database has below structure public function up() { Schema::create(‘users’, function (Blueprint $table) { $table->id(); $table->string(‘name’); $table->string(’email’)->unique()->nullable(); $table->string(‘phone’)->unique()->nullable(); $table->timestamp(’email_verified_at’)->nullable(); $table->timestamp(‘phone_verified_at’)->nullable(); $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); DB::statement(‘ALTER TABLE users ADD CONSTRAINT chk_phone_or_email CHECK (email IS NOT NULL OR email IS NOT NULL);’); } Basically I have two fields phone and email that can be null but both ..

Read more

I want to pass the token to the header to check if the endpoint works and reach null $clientRepository = new ClientRepository(); $client = $clientRepository->createPersonalAccessClient( null, ‘Test Personal Access Client’, ‘http://localhost’ ); DB::table(‘oauth_personal_access_clients’)->insert([ ‘client_id’ => $client->id, ‘created_at’ => new DateTime, ‘updated_at’ => new DateTime, ]); $token = $user->createToken(‘Personal Access Token’)->accessToken; $headers = [‘HTTP_AUTHORIZATION’ => "Bearer ..

Read more

While using the ‘auth:api’ middleware, using a freshly generated token, my request returns a typeError in the laravel code. Argument 1 passed to LaravelPassportPassportUserProvider::__construct() must implement interface IlluminateContractsAuthUserProvider, null given I tried some debugging and managed to find the causing code but i dont understand how to fix this. It is in this piece of ..

Read more

when I call Auth::check() retrun false. this my route of login $router->group(["namespace" => "LaravelPassportHttpControllers"], function ($router) { $router->post("login", [ "as" => "login", ‘middleware’ => [‘throttle’], "uses" => "[email protected]" ]); }); Request data of login and header the result of login route is ok I get 200 status but when I call Auth::check() after login return ..

Read more

I wrote APIs using Laravel and I used Laravel Passport for authentication, but sometimes when users log into the app it logs them into someone else’s account until they refresh (for web) or log out and log in again for the app. I’ve tried making the token expire after 12 hours but it seems not ..

Read more

I installed Laravel Passport and migrated the new tables just fine in my database. But when I try to run migrations for the testing database, ie. artisan migrate –database=testing I get: SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘oauth_auth_codes’ already exists The only table that exists in the testing database is the migrations ..

Read more

I am trying to create an API to use in conjunction with an Angular frontend. For this, I am using a Laravel API with Passport as the authentication method. The API works fine if I use Postman, but for request from the frontend always returns 401: Unauthorized The route is protected by auth:api middleware. Route::middleware(‘auth:api’)->get(‘/user’, ..

Read more

I have this logout method, user can login with two devices(mobile and web) but when logout, it revokes all user’s tokens . I want when user logout from web , can use mobile app and vice versa. public function logout(Request $request) { try { if (Auth::check()) { $token = $request->user()->token(); $token->revoke(); return $this->success(‘You have successfully ..

Read more

I am trying to create an access_token for my api but I have problem that show this message : "error": "invalid_client", "error_description": "Client authentication failed", "message": "Client authentication failed" and this my request data { "username":"[email protected]", "password":"test1234", "grant_type":"password", "client_id": "2", "client_secret":"jScq3DMMeZctypnYb7f1ClEHyzybwTK1Yisqo09E" } and this my oauth_clients table oauth_clients_table Sourc..

Read more

I’ve created an authentication controller using laravel passport, but the result is not what it usually is. variable $token = $user->createToken(‘TestApp’)->accessToken; does not generate tokens in the oauth_access_tokens table but instead creating token in the personal_access_token table My registration controller is public function register(Request $request) { $validator = Validator::make($request->all(), [ ‘name’ => ‘required’, ‘username’ => ..

Read more

I am trying to authenticate api calls in my laravel application. I have installed Passport following the documentation and I think I have not missed anything. but API call returns a 401 Unauthenticated. Auth.php ‘guards’ => [ ‘web’ => [ ‘driver’ => ‘session’, ‘provider’ => ‘users’, ], ‘api’ => [ ‘driver’ => ‘passport’, ‘provider’ => ..

Read more

all of configuration is right but does not work my controller code is: $appUser = User::create([ ‘name’ => $user->name, ’email’ => $user->email, ‘password’ => Hash::make(Str::random(8)), ]); return $passportToken = $appUser->createToken(‘Token Name’)->accessToken; and responce code // http://localhost:8000/api/authorize/github/callback?code=6ba82d59f00fdb1ad5c9 { "name": "Token Name", "abilities": [ "*" ], "tokenable_id": 1, "tokenable_type": "AppModelsUser", "updated_at": "2021-09-19T05:10:00.000000Z", "created_at": "2021-09-19T05:10:00.000000Z", "id": 3 } ..

Read more

So Basically I have two laravel apps. One is used as a server one is used as a client. I have integrated passport and I get an access token like so: {"token_type":"Bearer","expires_in":1296000,"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxMyIsImp0aSI6IjdmMGZkYmZlNGExMDY5YmYxNTU2MTA4MzRiMjY1NDMxZjFhYzYzM2U0ZGVlNTExMmE5YWQ2YzUyNzVjODkxYzZhZGQ0ZjNiNTFkMjI2NjgxIiwiaWF0IjoxNjMxOTcwMzIxLCJuYmYiOjE2MzE5NzAzMjEsImV4cCI6MTYzMzI2NjMyMSwic3ViIjoiMTEiLCJzY29wZXMiOltdfQ.DpC_sqhxYXLijpTDIq4NfnRm4aDEKzUKwUU4L0ZaVhyJcoUB4j22KURYXG1T3ODJ3g8Js3Ly61ExuRA0yrs-bEDbcNwrFIFoK4YeCYBH7a8SMO6MhRszvXhjyXzCfrAAtheIAkK1GHAU94hksG7IFxx0F8762jqS0Y3qbB7_L5aBHj8GotDP09-83waYU6zmThVBLG3FcVB7OswoeXna8HsxLSryNzVWex1aB1xhaJ6QB2vUryatXeyUUI9YK1Zw4JzazwQUADw2Ip35aTNXhBRsxkHo3o_4Iegqao6KFBqcJI-3wxHyF0d8OafQG5sskLVN55FPOJ2UIbugwh-8G7vOkgtE-42-xnrIxeB9uxM3bNME8JGhZ8Lx4Af4CR6nhmZiUcTCqG73Pw2xHjZJ9WvDssfBzltYKM537g0gJgtlw2G_2pArMrI2AVl0Om7FQD-CSitMj-sDkKmDPNXmYiRdpRDFoAWqfYFG6YlBDjdQu3QNdq_8NLXIliU8iInkXIc8hY2sB5DkolpMtAltHnWe1M3CoiWfuFJpQbVRdK1juzHwfPAFm9Swv2-NdAg4Pz9K6aCisdIJbtayANWUYl9aXvwKDFMaHveU8U4sXGooYbirxJ6S6VUIGAbE127Inr_ZT98WQhWhKxekmSur0rpoat0HOILGJlLtq1xcIUI","refresh_token":"def50200f490beb568a3238567479d5a01e5ad8735144b6a369e686206f4895855259253842f1d58c776078843ac58704499c1477dafd6e979aa8142e4ac673097f99b1991b8aaa1151aa6f181e755c66ab2e4fbe54c576585b6b93fbc4ddd2acdb13abe3c986cbbc67f90779c7179f5eeee30bde0569c90f12eb74682213d1141a70e029f1fa797beae8cc5a133d62e548a2f4c1a760cafee5b5001e8dd1c11869d78e9c5df35ef7f55c1b83a80d740ada6d63208c17f3a6a1f715bb2337cee07f64d89f43d25701266ec9f71d242db07ad0c08786b1423906e9dbfb3259d5dc80b2c989f3333ee21128c510df802271ea6b4485e6513f3029158c662427219424a73103eb94798826a02b41aba5151774eb7382a6bbcbbf3e468cd663b0c7d02a75617a9c39d978a822b156e1b4c052637ee7955344d88d9761b10f2192374d233425c8ce3cf38a01b3fb870f5d9423dbb01a825a02061de5d07ffac667545ade492"} Than from the client using this access token I can make an request to the server app api to /api/user that is identified ..

Read more

I am using fresh install of Laravel 8 and passport to create oauth2 server. To test with the client I use Postman. Following this guide https://laravel.com/docs/8.x/passport#introduction here are all the changes I’ve made: AuthServiceProvider.php: <?php namespace AppProviders; use IlluminateFoundationSupportProvidersAuthServiceProvider as ServiceProvider; use IlluminateSupportFacadesGate; use LaravelPassportPassport; class AuthServiceProvider extends ServiceProvider { /** * The policy mappings ..

Read more

Following a tutorial: https://www.twilio.com/blog/build-secure-api-php-laravel-passport I manAged to get Laravel/Passport installed formy Laravel Api and Vue application. I managed to create attoken with: localhost:8000/oauth/token get the login working in Postman: localhost:8000/api/[email protected]&password=password Now when I try to register a user I get returned to the home-page. I do get some "undefined method" errors from VS Code, but ..

Read more

I have two laravel apps both have passport installed. Client running at port 8000 and server app running at port 9000. On the client this is the code I use to initiate the oauth2 login procedure. public function auth(Request $request) { $request->session()->put(‘state’, $state = Str::random(40)); $query = http_build_query([ ‘client_id’ => ‘2’, ‘redirect_uri’ => ‘http://127.0.0.1:8000/authorize/response’, ‘response_type’ ..

Read more

I have two laravel apps both have passport installed. Client running at port 8000 and server app running at port 9000. On the client this is the code I use to initiate the oauth2 login procedure. public function auth(Request $request) { $request->session()->put(‘state’, $state = Str::random(40)); $query = http_build_query([ ‘client_id’ => ‘2’, ‘redirect_uri’ => ‘http://127.0.0.1:8000/authorize/response’, ‘response_type’ ..

Read more

I’m using tenancy on Laravel v8 with Passport and PostgreSQL using the Multi-Schema model. On my old server and with MySQL everything was fine, but after moving to the new setup, I’m facing an error on tenant creation: PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "oauth_clients" does not exist and this happens after running $clientRepository->createPersonalAccessClient(…) ..

Read more

I currently working on a MIS using nextjs for frontend ,Laravel for backend and laravel passport for authentication. I have problem implementing remember me and login with api. I want a to write a code that if a user does’nt check remember me while logging in the info of the user is deleted when browser ..

Read more