• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

GhazaliTajuddin.com

Another Kuantan Blogger

  • Home
  • Blog
    • Kuantan
    • Foods
    • Technology
    • Health
  • Stock Photography
    • Senarai Microstock Agency
    • Membuka akaun contributor Shutterstock.com
    • Tips untuk 10 keping gambar pertama Shutterstock.com
    • Mengapa Shutterstock.com reject gambar / submission
    • Model Release
    • Bagaimana withdraw earning daripada Fotolia
    • Bagaimana untuk mengisi keyword kepada imej dengan menggunakan Adobe Photoshop
You are here: Home / Technology / Laravel Passport: How to hide Client_Secret using GuzzleHttp

Laravel Passport: How to hide Client_Secret using GuzzleHttp

February 21, 2019 by ghazalitajuddin Leave a Comment

Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. … Middleware system allows you to augment and compose client behavior.Apr 22, 2018

How GuzzleHttp helps?

The idea is to create an endpoint at our back end, that we can make a request to the backend endpoint that contain those secret information that we need to keep secret. This way we can avoid to embed / hard coded all the important information on our javascript request each time..

Install the package on our Laravel.

composer require guzzlehttp/guzzle

Make a route on our api. Let say AuthController

Route::post('/login','Auth\AuthController@login');

Create a controller route. 

php artisan make:controller Auth/AuthController

Paste this on our controller

public function login(Request $request)
    {
        $http = new \GuzzleHttp\Client;

        try{
            $response = $http->post('http://localhost:8888/test/public/oauth/token',[
                'form_params' => [
                    'grant_type' => 'password',
                    'client_id' => 2,
                    'client_secret' => 'Fi7uzcm31Luf3LTz5ZevBVL',
                    'username' => $request->username ,
                    'password' => $request->password ,
                ]
            ]);

                    return $response->getBody();

        } catch (\GuzzleHttp\Exception\BadResponseException $e){

            if($e->getCode()==400){
                return response()->json('Invalid Request. Please enter a username or a password', $e->getCode());
            }else if($e->getCode()==401){
                return response()->json('Your credential is incorrect. Please try again.', $e->getCode());
            }

        return response()->json('Something wrong on the server.',$e->getCode());
        
        }


    }

 

Filed Under: Technology Tagged With: api, GuzzleHttp, kuantan web developer, kuantan webmaster, laravel, Laravel API, Passport, startup

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

“Solat. Sabar. Syukur. Senyum. Sedekah.”

For Collaboration, Events & Review, kindly contact me at +6016[-]9212092 or click Whatsapp button on this page.

Sponsor

Recent Posts

BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.

User Roles And Permissions Without Package Laravel 10

Laravel Many To Many Relationship

Makan malam bersama keluarga di Awangan Palace

Sarapan pagi di Warung Gulai Kawah

Recent Comments

  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Personal Tips Berhenti Merokok
  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • ghazalitajuddin on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!
  • Mal on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • Firdaus on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!

My Link

  • Takaful Insurance Web

JJCM

Makan malam bersama keluarga di Awangan Palace

Kopi Acah-acah Diet

Variasi Coconut Shake Hogoh De Coco

Singgah beli keropok di Keropok Warisan Losong Kuala Terengganu

7 Lokasi Nasi Dagang Terbaik di Kuantan

Tags

bebas rokok berhenti merokok breakfast Controller Framework Gezzeg Photography & Design health jalan-jalan cari makan jalan-jalan cari makan kuantan jjcm jjcm kuantan Jurufoto Kuantan Kuantan Kuantan Photographer kuantan programmer kuantan web developer kuantan webmaster laravel merokok merbahayakan kesihatan model MVC nikmat rokok OOP Pahang Pahangtourism pahang tourism Photo Manipulation PHP rajalanun retired smoking revisit pahang 2018 shutterstock stop smoking stop smoking tips stop smoking withdrawal symptom tips tips berhenti merokok View visit malaysia 2020 visit pahang visitpahang white wordpress yii Yii Framework

Recent Posts

  • BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.
  • User Roles And Permissions Without Package Laravel 10
  • Laravel Many To Many Relationship
  • Makan malam bersama keluarga di Awangan Palace
  • Sarapan pagi di Warung Gulai Kawah

Copyright © 2025 — Ghazali Tajuddin • All rights reserved. •