jeudi 22 octobre 2015

Test post to create user from non-application

I am trying to test user creation from my frontend app to my Laravel API. I don't have a login created yet for my frontend, so I tried using DHC and command line cURL to create the user.

DHC:

my-api.localhost/1.0/auth/register

{
  "name": "testname",
  "email": "dt@dt.com",
  "password": "mypassword"
}

Response:

We are sorry, but Chrome API does not allow to get a response body for redirect.

cURL requests:

curl -H "Content-Type: application/json" -X POST --data '{"name":"testname", "email":"dt@dt.com", "password":"mypassword"' http://ift.tt/1hYTjLr

Response:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="1;url=http://my-api.localhost" />

        <title>Redirecting to http://ift.tt/1ky1jF1;
    </head>
    <body>
        Redirecting to <a href="http://my-api.localhost">http://ift.tt/1hYTjLt;.
    </body>
</html>


Laravel postRegister() snippet:

    Auth::login($this->create($request->all()));

    return new Response(Auth::user(), 200);

    //return redirect($this->redirectPath()); //no longer redirects

Routes:

Route::group(['middleware' => 'cors'], function(Router $router) {
        ...
        $router->controllers(
            [
                'auth'     => 'Auth\AuthController',
                'password' => 'Auth\PasswordController'
            ]
        );

Configurations:

CSRF has been turned off:

// \App\Http\Middleware\VerifyCsrfToken::class,

Laravel CORS config accepts all routes:

'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT',  'DELETE'],

You can see I am no longer redirecting, and pretty much have it open to make posts to. I don't quite understand these errors.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire