Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Login Endpoint #1

Open
donny26utama opened this issue Dec 26, 2021 · 1 comment
Open

Error on Login Endpoint #1

donny26utama opened this issue Dec 26, 2021 · 1 comment

Comments

@donny26utama
Copy link

Hello, my friend. I've got an error when trying to access the login endpoint.
I'm trying using Postman and get log error "Error: Parse Error: Invalid character in chunk size"

after a while, I found the problem. On AuthController line 25-33: (see below)

return $client->post(config('service.passport.login_endpoint'), [
"form_params" => [
"client_secret" => config('service.passport.client_secret'),
"grant_type" => "password",
"client_id" => config('service.passport.client_id'),
"username" => $request->email,
"password" => $request->password
]
]);

I'm trying to change code like this:

           $response = $client->post(config('service.passport.login_endpoint'), [
                "form_params" => [
                    "client_secret" => config('service.passport.client_secret'),
                    "grant_type" => "password",
                    "client_id" => config('service.passport.client_id'),
                    "username" => $request->email,
                    "password" => $request->password
                ]
            ]);

            return response()->json(json_decode($response->getBody()->getContents()));

and now it's working!
but my code is still incomplete because I must handle it when json_decode failed.

@dadablaze2000
Copy link

you can handle it like below;

     try {
        $response = $client->post(config('service.passport.login_endpoint'), [
            "form_params" => [
                "client_secret" => config('service.passport.client_secret'),
                "grant_type" => "password",
                "client_id" => config('service.passport.client_id'),
                "username" => $request->email,
                "password" => $request->password
            ]
        ]);
        return response()->json(json_decode($response->getBody()->getContents()));
        
    } catch (BadResponseException $e) {
          return response()->json([ 
                'status' => '404',
                'title' => 'Bad Request',
                'message' => "User details incorrect"],
                404);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants