Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dbnames's avatar

Authentication With Third Party API

So here is the flow:

  1. User login in 'Login' page,
  2. User input phone number and password,
  3. Request to API -> If 'Success', save data to Database,
  4. User Logged in.

I try to find some references but i still couldn't understand it.

Here is my Controller:

public function getAPI(){

	$client = new Client;
	$response = $client->post('http://example.com/api/login', [
	    	'form-data' => [
		       'login' => '0xxxxxxx', 
		       'password' => 'dxxxxxxxx'
		    ]
	    ]);

	    dd($response);
	}

And when i try to check if it got an success response or not, here is the result:

Client error: `POST http://example/api/login` resulted in a `401 Unauthorized` response: {"error":"invalid_credentials"}

Yes, it might be because of the invalid input but i check it via Postman and that's works just fine.

Here is the response:

{
    "success": true,
    "token": "eyJ0eXAiOiJKV1QiasdasdqweqfdsJ9.eyJzdWIiOjEwMCwiaXNzIjoiaHR0cDovL2Rldi50b2tvaGFqaS5jby5pZC9hcGkvbG9naW4iLCJpYXQiOjE1OTExOTasdwqeqweqwewqeMDM3OCwibmJmIjoxNTkxMTkwNzc4LCJqdGkiOiJoVEFEWExBYmMzUlR2elVQIn0.kaRaNgrfoboJiazLLO01V_1Gtgh7LJx0k4o918ZhYik"
}

So that's all, could you give me some suggestion to how to handle it?

Thank you.

0 likes
1 reply

Please or to participate in this conversation.