# Xác thực

Rememberizer cung cấp một số điểm cuối xác thực để quản lý tài khoản người dùng và phiên làm việc. Tài liệu này phác thảo các API xác thực có sẵn.

## Đăng Ký

{% openapi src="<https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b>" path="/auth/signup/" method="post" %}
[rememberizer\_openapi.yml](https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b)
{% endopenapi %}

### Ví dụ Yêu cầu

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
  https://api.rememberizer.ai/api/v1/auth/signup/ \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "secure_password",
    "name": "John Doe",
    "captcha": "recaptcha_response"
  }'
```

{% hint style="info" %}
Thay thế `recaptcha_response` bằng một phản hồi reCAPTCHA thực tế.
{% endhint %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
const signUp = async () => {
  const response = await fetch('https://api.rememberizer.ai/api/v1/auth/signup/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      email: 'user@example.com',
      password: 'secure_password',
      name: 'John Doe',
      captcha: 'recaptcha_response'
    })
  });
  
  const data = await response.json();
  console.log(data);
};

signUp();
```

{% hint style="info" %}
Thay thế `recaptcha_response` bằng một phản hồi reCAPTCHA thực tế.
{% endhint %}
{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

def sign_up():
    headers = {
        "Content-Type": "application/json"
    }
    
    payload = {
        "email": "user@example.com",
        "password": "secure_password",
        "name": "John Doe",
        "captcha": "recaptcha_response"
    }
    
    response = requests.post(
        "https://api.rememberizer.ai/api/v1/auth/signup/",
        headers=headers,
        data=json.dumps(payload)
    )
    
    data = response.json()
    print(data)

sign_up()
```

{% hint style="info" %}
Thay thế `recaptcha_response` bằng một phản hồi reCAPTCHA thực tế.
{% endhint %}
{% endtab %}
{% endtabs %}

## Đăng Nhập

{% openapi src="<https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b>" path="/auth/signin/" method="post" %}
[rememberizer\_openapi.yml](https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b)
{% endopenapi %}

### Ví dụ Yêu cầu

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
  https://api.rememberizer.ai/api/v1/auth/signin/ \
  -H "Content-Type: application/json" \
  -d '{
    "login": "user@example.com",
    "password": "secure_password",
    "captcha": "recaptcha_response"
  }'
```

{% hint style="info" %}
Thay thế `recaptcha_response` bằng một phản hồi reCAPTCHA thực tế.
{% endhint %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
const signIn = async () => {
  const response = await fetch('https://api.rememberizer.ai/api/v1/auth/signin/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      login: 'user@example.com',
      password: 'secure_password',
      captcha: 'recaptcha_response'
    })
  });
  
  // Kiểm tra cookie xác thực trong phản hồi
  if (response.status === 204) {
    console.log("Đăng nhập thành công!");
  } else {
    console.error("Đăng nhập thất bại!");
  }
};

signIn();
```

{% hint style="info" %}
Thay thế `recaptcha_response` bằng một phản hồi reCAPTCHA thực tế.
{% endhint %}
{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

def sign_in():
    headers = {
        "Content-Type": "application/json"
    }
    
    payload = {
        "login": "user@example.com",
        "password": "secure_password",
        "captcha": "recaptcha_response"
    }
    
    response = requests.post(
        "https://api.rememberizer.ai/api/v1/auth/signin/",
        headers=headers,
        data=json.dumps(payload)
    )
    
    if response.status_code == 204:
        print("Đăng nhập thành công!")
    else:
        print("Đăng nhập thất bại!")

sign_in()
```

{% hint style="info" %}
Thay thế `recaptcha_response` bằng một phản hồi reCAPTCHA thực tế.
{% endhint %}
{% endtab %}
{% endtabs %}

## Xác minh Email

{% openapi src="<https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b>" path="/auth/verify-email/" method="post" %}
[rememberizer\_openapi.yml](https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b)
{% endopenapi %}

### Ví dụ Yêu cầu

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
  https://api.rememberizer.ai/api/v1/auth/verify-email/ \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "verification_code": "123456"
  }'
```

{% hint style="info" %}
Thay thế `YOUR_JWT_TOKEN` bằng mã JWT thực tế của bạn và sử dụng mã xác minh được gửi đến email của bạn.
{% endhint %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
const verifyEmail = async () => {
  const response = await fetch('https://api.rememberizer.ai/api/v1/auth/verify-email/', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_JWT_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      verification_code: '123456'
    })
  });
  
  if (response.status === 200) {
    console.log("Xác minh email thành công!");
  } else {
    console.error("Xác minh email thất bại!");
  }
};

verifyEmail();
```

{% hint style="info" %}
Thay thế `YOUR_JWT_TOKEN` bằng mã JWT thực tế của bạn và sử dụng mã xác minh được gửi đến email của bạn.
{% endhint %}
{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

def verify_email():
    headers = {
        "Authorization": "Bearer YOUR_JWT_TOKEN",
        "Content-Type": "application/json"
    }
    
    payload = {
        "verification_code": "123456"
    }
    
    response = requests.post(
        "https://api.rememberizer.ai/api/v1/auth/verify-email/",
        headers=headers,
        data=json.dumps(payload)
    )
    
    if response.status_code == 200:
        print("Xác minh email thành công!")
    else:
        print("Xác minh email thất bại!")

verify_email()
```

{% hint style="info" %}
Thay thế `YOUR_JWT_TOKEN` bằng mã JWT thực tế của bạn và sử dụng mã xác minh được gửi đến email của bạn.
{% endhint %}
{% endtab %}
{% endtabs %}

## Quản lý Token

{% openapi src="<https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b>" path="/auth/custom-refresh/" method="post" %}
[rememberizer\_openapi.yml](https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b)
{% endopenapi %}

### Ví dụ Yêu cầu

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
  https://api.rememberizer.ai/api/v1/auth/custom-refresh/ \
  -b "refresh_token=YOUR_REFRESH_TOKEN"
```

{% hint style="info" %}
Điểm cuối này sử dụng cookie để xác thực. Mã thông báo làm mới nên được gửi dưới dạng cookie.
{% endhint %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
const refreshToken = async () => {
  const response = await fetch('https://api.rememberizer.ai/api/v1/auth/custom-refresh/', {
    method: 'POST',
    credentials: 'include' // Điều này bao gồm cookie trong yêu cầu
  });
  
  if (response.status === 204) {
    console.log("Mã thông báo đã được làm mới thành công!");
  } else {
    console.error("Làm mới mã thông báo thất bại!");
  }
};

refreshToken();
```

{% hint style="info" %}
Điểm cuối này sử dụng cookie để xác thực. Đảm bảo ứng dụng của bạn bao gồm thông tin xác thực trong yêu cầu.
{% endhint %}
{% endtab %}

{% tab title="Python" %}

```python
import requests

def refresh_token():
    cookies = {
        "refresh_token": "YOUR_REFRESH_TOKEN"
    }
    
    response = requests.post(
        "https://api.rememberizer.ai/api/v1/auth/custom-refresh/",
        cookies=cookies
    )
    
    if response.status_code == 204:
        print("Mã thông báo đã được làm mới thành công!")
    else:
        print("Làm mới mã thông báo thất bại!")

refresh_token()
```

{% hint style="info" %}
Thay thế `YOUR_REFRESH_TOKEN` bằng mã thông báo làm mới thực tế của bạn.
{% endhint %}
{% endtab %}
{% endtabs %}

## Đăng xuất

{% openapi src="<https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b>" path="/auth/custom-logout/" method="post" %}
[rememberizer\_openapi.yml](https://4187618229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwbxu0T4faQnPtKbPzrD5%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=b77a395b-ed7b-4546-9ec7-182d4939fd1b)
{% endopenapi %}

### Ví dụ Yêu cầu

```bash
curl -X POST \
  https://api.rememberizer.ai/api/v1/auth/custom-logout/
```

{% hint style="info" %}
Điểm cuối này sẽ xóa các cookie xác thực.
{% endhint %}

```javascript
const logout = async () => {
  const response = await fetch('https://api.rememberizer.ai/api/v1/auth/custom-logout/', {
    method: 'POST',
    credentials: 'include' // Điều này bao gồm các cookie trong yêu cầu
  });
  
  if (response.status === 204) {
    console.log("Đăng xuất thành công!");
  } else {
    console.error("Đăng xuất thất bại!");
  }
};

logout();
```

{% hint style="info" %}
Điểm cuối này sử dụng cookie để xác thực. Đảm bảo ứng dụng của bạn bao gồm thông tin xác thực trong yêu cầu.
{% endhint %}

```python
import requests

def logout():
    session = requests.Session()
    
    response = session.post(
        "https://api.rememberizer.ai/api/v1/auth/custom-logout/"
    )
    
    if response.status_code == 204:
        print("Đăng xuất thành công!")
    else:
        print("Đăng xuất thất bại!")

logout()
```

{% hint style="info" %}
Điểm cuối này sẽ xóa các cookie xác thực.
{% endhint %}

{% endtabs %
