O'Reilly logo

Magento 2 Developer's Guide by Branko Ajzele

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hands-on with token-based authentication

The crux of token-based authentication is as follows:

  • Client requests access with a username and password
  • Application validates credentials
  • Application provides a signed token to the client

The following code example demonstrates the console cURL REST-like request for the customer user:

curl -X POST "http://magento2.ce/rest/V1/integration/customer/token"\
    -H "Content-Type:application/json"\
    -d '{"username":"john@change.me", "password":"abc123"}'

The following code example demonstrates the PHP cURL REST-like request for the customer user:

$data = array('username' => 'john@change.me', 'password' => 'abc123'); $data_string = json_encode($data); $ch = curl_init('http://magento2.ce/rest/V1/integration /customer/token'); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required