# Authentication

Operations related to user authentication with PromptEasy.eu API.

## Login

`POST /v1/login`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKeyAuth": []
  }
]
```

- ApiKeyAuth: apiKey, header X-Api-Key

Request body: application/json (required)

Type: object

Schema: [LoginRequest](https://api.prompteasy.eu/docs/api/models/loginrequest/index.md)

- `email` (required)
  Type: string
  
  Example:
  
  ```json
  "foo@bar.invalid"
  ```

- `password` (required)
  Type: string
  
  Example:
  
  ```json
  "V3rys3cr3tP@ssw0rd"
  ```

- `remember` (optional)
  Type: boolean
  
  Example:
  
  ```json
  true
  ```

Responses:

- 200: Login successful

Content type: application/json

Type: object

Schema: [Auth](https://api.prompteasy.eu/docs/api/models/auth/index.md)

- `name` (optional)
  Type: string
  
  Example:
  
  ```json
  "John Doe"
  ```

- `token` (optional)
  Type: string
  
  access token

- `aup_missing` (optional)
  Type: boolean
  
  Indicates whether the user still needs to agree to the latest Acceptable Use Policy
  
  Example:
  
  ```json
  true
  ```

- `recovery_codes` (optional)
  Type: array
  
  If user has finalised 2FA setup, auth object contains recovery codes too
  
  Items:
    Reference: [RecoveryCode](https://api.prompteasy.eu/docs/api/models/recoverycode/index.md); Type: object

- 202: Login credentials correct, 2FA setup started

Content type: application/json

Type: object

Schema: [TwoFactorSetup](https://api.prompteasy.eu/docs/api/models/twofactorsetup/index.md)

- `message` (optional)
  Type: string
  
  Example:
  
  ```json
  "Two-factor authentication setup required"
  ```

- `qr_code` (optional)
  Type: string
  
  2FA setup QR code as SVG string

- `uri` (optional)
  Type: string
  
  2FA uri
  
  Example:
  
  ```json
  "otpauth://totp/PromptEasy.eu..."
  ```

- `string` (optional)
  Type: string
  
  2FA shared secret
  
  Example:
  
  ```json
  "J64LMYRKWG43ZW2MP..."
  ```

- 204: Login credentials correct, waiting 2FA code next. Make same request but with `2fa_code`

- 400: Login credentials were correct but `2fa_code` was wrong

- 401: Login credentials were incorrect

## Examples

### cURL

```bash
curl -X POST 'https://api.prompteasy.eu/v1/login' \
  -H 'X-Api-Key: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "email": "foo@bar.invalid",
  "password": "V3rys3cr3tP@ssw0rd",
  "remember": true
}'
```

### JavaScript

```javascript
const body = `{
  "email": "foo@bar.invalid",
  "password": "V3rys3cr3tP@ssw0rd",
  "remember": true
}`;

const response = await fetch('https://api.prompteasy.eu/v1/login', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "email": "foo@bar.invalid",
  "password": "V3rys3cr3tP@ssw0rd",
  "remember": true
}'''

response = requests.post(
    'https://api.prompteasy.eu/v1/login',
    data=body.encode('utf-8'),
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Request password reset link

`POST /v1/forgot-password`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKeyAuth": []
  }
]
```

- ApiKeyAuth: apiKey, header X-Api-Key

Request body: application/json (required)

Type: object

Schema: [ForgotPasswordRequest](https://api.prompteasy.eu/docs/api/models/forgotpasswordrequest/index.md)

- `email` (required)
  Type: string
  
  Example:
  
  ```json
  "foo@bar.invalid"
  ```

Responses:

- 200: Password reset link sent

Content type: application/json

Type: object

Schema: [ForgotPasswordResponse](https://api.prompteasy.eu/docs/api/models/forgotpasswordresponse/index.md)

- `status` (optional)
  Type: string
  
  Example:
  
  ```json
  "We have emailed your password reset link."
  ```

- 422: Unprocessable Entity

Content type: application/json

Type: object

Schema: [ValidationError](https://api.prompteasy.eu/docs/api/models/validationerror/index.md)

- `message` (optional)
  Type: string
  
  Example:
  
  ```json
  "Validation failed"
  ```

- `errors` (optional)
  Reference: [ValidationErrorErrors](https://api.prompteasy.eu/docs/api/models/validationerrorerrors/index.md); Type: object

## Examples

### cURL

```bash
curl -X POST 'https://api.prompteasy.eu/v1/forgot-password' \
  -H 'X-Api-Key: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "email": "foo@bar.invalid"
}'
```

### JavaScript

```javascript
const body = `{
  "email": "foo@bar.invalid"
}`;

const response = await fetch('https://api.prompteasy.eu/v1/forgot-password', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "email": "foo@bar.invalid"
}'''

response = requests.post(
    'https://api.prompteasy.eu/v1/forgot-password',
    data=body.encode('utf-8'),
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Reset password with token

`POST /v1/reset-password/{token}`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKeyAuth": []
  }
]
```

- ApiKeyAuth: apiKey, header X-Api-Key

Parameters:

- `token` (path, string, required) - The password reset token.
  Type: string

Request body: application/json (required)

Type: object

Schema: [ResetPasswordRequest](https://api.prompteasy.eu/docs/api/models/resetpasswordrequest/index.md)

- `email` (required)
  Type: string, email
  
  Example:
  
  ```json
  "foo@bar.invalid"
  ```

- `password` (required)
  Type: string
  
  Example:
  
  ```json
  "V3rys3cr3tP@ssw0rdNew"
  ```

- `password_confirmation` (required)
  Type: string
  
  Example:
  
  ```json
  "V3rys3cr3tP@ssw0rdNew"
  ```

Responses:

- 200: Password reset successful

Content type: application/json

Type: object

- `status` (optional)
  Type: string
  
  Example:
  
  ```json
  "Password reset done"
  ```

- 400: Error while resetting password

Content type: application/json

Type: object

- `email` (optional)
  Type: string
  
  Example:
  
  ```json
  "Error while resetting password"
  ```

- 422: Unprocessable Entity

Content type: application/json

Type: object

Schema: [ValidationError](https://api.prompteasy.eu/docs/api/models/validationerror/index.md)

- `message` (optional)
  Type: string
  
  Example:
  
  ```json
  "Validation failed"
  ```

- `errors` (optional)
  Reference: [ValidationErrorErrors](https://api.prompteasy.eu/docs/api/models/validationerrorerrors/index.md); Type: object

## Examples

### cURL

```bash
curl -X POST 'https://api.prompteasy.eu/v1/reset-password/string' \
  -H 'X-Api-Key: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "email": "foo@bar.invalid",
  "password": "V3rys3cr3tP@ssw0rdNew",
  "password_confirmation": "V3rys3cr3tP@ssw0rdNew"
}'
```

### JavaScript

```javascript
const body = `{
  "email": "foo@bar.invalid",
  "password": "V3rys3cr3tP@ssw0rdNew",
  "password_confirmation": "V3rys3cr3tP@ssw0rdNew"
}`;

const response = await fetch('https://api.prompteasy.eu/v1/reset-password/string', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "email": "foo@bar.invalid",
  "password": "V3rys3cr3tP@ssw0rdNew",
  "password_confirmation": "V3rys3cr3tP@ssw0rdNew"
}'''

response = requests.post(
    'https://api.prompteasy.eu/v1/reset-password/string',
    data=body.encode('utf-8'),
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Logout

`POST /v1/logout`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKeyAuth": [],
    "BearerAuth": []
  }
]
```

- ApiKeyAuth: apiKey, header X-Api-Key
- BearerAuth: http (bearer)

Responses:

- 204: No Content

## Examples

### cURL

```bash
curl -X POST 'https://api.prompteasy.eu/v1/logout' \
  -H 'X-Api-Key: YOUR_TOKEN' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://api.prompteasy.eu/v1/logout', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_TOKEN',
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.post(
    'https://api.prompteasy.eu/v1/logout',
    headers={
        'X-Api-Key': 'YOUR_TOKEN',
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```
