# 認証エンドポイントについて

## 概要 <a href="#gai-yao" id="gai-yao"></a>

ユーザー認証をするための API として `GET|POST /endpoint/type/:serverType/user/:uid` を提供していますが、よりセキュアに利用いただくためには、ゲーム側の API サーバー等を経由して認証・認可処理などを挟んだ上で認証情報を返却していただくことをおすすめしております。

## シーケンス <a href="#shkensu" id="shkensu"></a>

以下に認証処理の一例を示します。ゲームサーバーを経由し、認証・認可処理などの前処理を行い、Diarkis サーバーの認証エンドポイントから認証情報を取得し、返却します。

{% @mermaid/diagram content="sequenceDiagram
actor Client
participant GameServer
participant DiarkisServer

```
Client->>GameServer: Request: /auth などゲーム認証 URL
GameServer->>GameServer: 前処理（認証・認可処理など）

alt 認証エラーの場合
    GameServer-->>Client: Response: 認証エラー
end

alt Diarkis 認証
    GameServer->>DiarkisServer: GET|POST /endpoint/type/:serverType/user/:uid
    DiarkisServer-->>GameServer: Response: 認証情報の返却

end
GameServer->>GameServer: 後処理（レスポンスの作成など）
GameServer-->>Client: Response: 認証情報

alt 直接アクセスはできないようにするのが望ましい
    Client->>DiarkisServer: GET|POST /endpoint/type/:serverType/user/:uid
    DiarkisServer-xClient: アクセス不可
end" %}
```

## エンドポイント仕様 <a href="#endopointo" id="endopointo"></a>

`GET|POST /endpoint/type/:serverType/user/:uid`

* `:serverType` は認証するサーバータイプ (UDP/TCP など) を指定します。
* `:uid` には userID を指定します。
* リクエストメソッドは `GET` `POST` のどちらでも可能です。

レスポンスは以下の様になります（Diarkis サーバーに接続できる環境で curl でも確認いただくことが可能です）

```
# 例) UDP サーバータイプに接続する場合 /endpoint/type/UDP/user/userID
% curl 127.0.0.1:7000/endpoint/type/UDP/user/user0001
{
  "encryptionIV": "3f78480272d6415c8a29ef7aafce3f61",
  "encryptionMacKey": "80cf921c367042a99f868b13b72a209d",
  "serverType": "UDP",
  "serverHost": "127.0.0.1",
  "serverPort": 7100,
  "sid": "8c63eaa3783e4bf2a4097823697b4551",
  "encryptionKey": "d08589d341fd4f1696f058c0c4fe21f5"
}
```

## 非推奨の認証エンドポイントについて <a href="#noendopointonitsuite" id="noendopointonitsuite"></a>

`GET /auth/:uid` エンドポイントは起動しているサーバータイプすべてに対してユーザー認証を行うため、例えば UDP と TCP サーバーが起動している場合は、双方に対してユーザーを作成します。

それによって利用しないサーバーに対してもユーザー生成するコストが発生し、サーバー負荷が高まる原因となります。

```
[2024/11/11 11:11:11.111]<HTTP>      WARNING HTTP|10.4.4.4:8100        GET /auth/:uid has been deprecated. Please use GET /endpoint/type/:serverType/user/:uid instead
```

上記のようなログがある場合は `GET /endpoint/type/:serverType/user/:uid` に切り替えをお願いいたします。

## 参考 <a href="#can-kao" id="can-kao"></a>

詳細は以下の API リファレンスをご覧ください。

<https://docs.diarkis.io/docs/server/v1.1.0-beta3/diarkis/server/http/index.html#hdr-Endpoint_API>


---

# 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://help.diarkis.io/support/faq/about-authentication-endpoint.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.
