Sha256: 459835d79b788c5ced8498fa48297e02cf32539d4678fed3fc5e8cf04bf372ee

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

# Authentication

```shell
# Specifying the token as a header.
curl "https://example.com/api/v1/endpoint"
  -H "X-Spree-Token: abc123"

# Specifying the token as a param.
curl "/api/v1/endpoint"
  -d token=abc123
```

> Make sure to replace `abc123` with your API key.

Spree uses API keys to allow access to the API.
To obtain a token, you must either create a new user, or, via token authentication, "log" the user in.

Spree does not expect every request to require an API key (such as reading public product data).

## Authenticate a User (Login)

```shell
curl "https://example.com/api/v1/account/signin"
  -X POST
  -d user[email]=spree@example.com
  -d user[password]=spree123
```

```json
{
  "data": {
    "id": "1",
    "type": "spree_users",
    "attributes": {
      "email": "spree@example.com",
      "first_name": "John",
      "last_name": "Doe",
      "job_title": null,
      "based_city": null,
      "experience": null,
      "avatar": "default/avatar-placeholder.jpg",
      "role": "user",
      "biography": null,
      "client_budget": null,
      "license_number": null,
      "certification_authority": null,
      "is_newsletter_subscribed": null,
      "is_designer_available": true
    },
    "relationships": {
      "store": {
        "data": null
      }
    }
  }
}
```

To login users, you will need to supply the `email` and `password`.
The response will be a user data object with the token in the body.
The response's headers will include a `X-Spree-Token` which is what you will use as the token.

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
spree_api_v2-0.2.2 docs/source/includes/_authentication.md
solidus_api_v2-0.2.2 docs/source/includes/_authentication.md