# 身份驗證

Rememberizer 提供幾個認證端點來管理用戶帳戶和會話。本文檔概述了可用的認證 API。

## 註冊

{% openapi src="/files/WF90zszaISusKGEBimez" path="/auth/signup/" method="post" %}
[rememberizer\_openapi.yml](https://2492455604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTVKmtXKPeA8gAZJsuGLA%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=3b4a9db2-4dd7-440f-b670-9555703d351d)
{% endopenapi %}

### 範例請求

{% 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" %}
將 `recaptcha_response` 替換為實際的 reCAPTCHA 回應。
{% 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" %}
將 `recaptcha_response` 替換為實際的 reCAPTCHA 回應。
{% 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" %}
將 `recaptcha_response` 替換為實際的 reCAPTCHA 回應。
{% endhint %}
{% endtab %}
{% endtabs %}

## 登入

{% openapi src="/files/WF90zszaISusKGEBimez" path="/auth/signin/" method="post" %}
[rememberizer\_openapi.yml](https://2492455604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTVKmtXKPeA8gAZJsuGLA%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=3b4a9db2-4dd7-440f-b670-9555703d351d)
{% endopenapi %}

### 範例請求

{% 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" %}
將 `recaptcha_response` 替換為實際的 reCAPTCHA 回應。
{% 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'
    })
  });
  
  // 檢查回應中的身份驗證 cookie
  if (response.status === 204) {
    console.log("登入成功！");
  } else {
    console.error("登入失敗！");
  }
};

signIn();
```

{% hint style="info" %}
將 `recaptcha_response` 替換為實際的 reCAPTCHA 回應。
{% 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("登入成功！")
    else:
        print("登入失敗！")

sign_in()
```

{% hint style="info" %}
將 `recaptcha_response` 替換為實際的 reCAPTCHA 回應。
{% endhint %}
{% endtab %}
{% endtabs %}

## 電子郵件驗證

{% openapi src="/files/WF90zszaISusKGEBimez" path="/auth/verify-email/" method="post" %}
[rememberizer\_openapi.yml](https://2492455604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTVKmtXKPeA8gAZJsuGLA%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=3b4a9db2-4dd7-440f-b670-9555703d351d)
{% endopenapi %}

### 範例請求

{% 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" %}
將 `YOUR_JWT_TOKEN` 替換為您的實際 JWT 令牌，並使用發送到您電子郵件的驗證碼。
{% 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("電子郵件驗證成功！");
  } else {
    console.error("電子郵件驗證失敗！");
  }
};

verifyEmail();
```

{% hint style="info" %}
將 `YOUR_JWT_TOKEN` 替換為您的實際 JWT 令牌，並使用發送到您電子郵件的驗證碼。
{% 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("電子郵件驗證成功！")
    else:
        print("電子郵件驗證失敗！")

verify_email()
```

{% hint style="info" %}
將 `YOUR_JWT_TOKEN` 替換為您的實際 JWT 令牌，並使用發送到您電子郵件的驗證碼。
{% endhint %}
{% endtab %}
{% endtabs %}

## 令牌管理

{% openapi src="/files/WF90zszaISusKGEBimez" path="/auth/custom-refresh/" method="post" %}
[rememberizer\_openapi.yml](https://2492455604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTVKmtXKPeA8gAZJsuGLA%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=3b4a9db2-4dd7-440f-b670-9555703d351d)
{% endopenapi %}

### 示例請求

{% 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" %}
此端點使用 cookies 進行身份驗證。刷新令牌應作為 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' // 這會在請求中包含 cookies
  });
  
  if (response.status === 204) {
    console.log("令牌成功刷新！");
  } else {
    console.error("令牌刷新失敗！");
  }
};

refreshToken();
```

{% hint style="info" %}
此端點使用 cookies 進行身份驗證。確保您的應用程序在請求中包含憑據。
{% 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("令牌成功刷新！")
    else:
        print("令牌刷新失敗！")

refresh_token()
```

{% hint style="info" %}
將 `YOUR_REFRESH_TOKEN` 替換為您的實際刷新令牌。
{% endhint %}
{% endtab %}
{% endtabs %}

## 登出

{% openapi src="/files/WF90zszaISusKGEBimez" path="/auth/custom-logout/" method="post" %}
[rememberizer\_openapi.yml](https://2492455604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTVKmtXKPeA8gAZJsuGLA%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=3b4a9db2-4dd7-440f-b670-9555703d351d)
{% endopenapi %}

### 範例請求

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

{% hint style="info" %}
此端點將清除身份驗證 cookie。
{% endhint %}

```javascript
const logout = async () => {
  const response = await fetch('https://api.rememberizer.ai/api/v1/auth/custom-logout/', {
    method: 'POST',
    credentials: 'include' // 這會在請求中包含 cookie
  });
  
  if (response.status === 204) {
    console.log("登出成功！");
  } else {
    console.error("登出失敗！");
  }
};

logout();
```

{% hint style="info" %}
此端點使用 cookie 進行身份驗證。請確保您的應用程序在請求中包含憑證。
{% 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("登出成功！")
    else:
        print("登出失敗！")

logout()
```

{% hint style="info" %}
此端點將清除身份驗證 cookie。
{% endhint %}

{% endtabs %


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rememberizer.ai/zh-hk/kai-fa-zhe-zi-yuan/api-docs/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
