Elantris
用 Docker 整合 Ory Kratos + Hydra 服務,並應用在 Gitea OAuth2 登入流程。
按照 README.md 將 docker container 裝起來:
這個 Docker File 包含的 Docker Image:
基本上設定都不需要調整,可以注意一下 kratos.yml
裡的 oauth2_provider
與 hydra.yml
裡 identity_provider
。預設用到的 Port:
Port | Description |
---|---|
4433 | Kratos public URL |
4434 | Kratos admin URL |
4444 | Hydra public URL |
4445 | Hydra admin URL |
4455 | Demo UI |
5555 | Hydra token user |
docker-compose -f quickstart.yml exec /hydra
redirect-uri
其中的 hydra-client 是等一下 Gitea 設定時需要對應的名稱透過套件管理器直接裝是最方便的方式,我是按照 Installation from package 用 Homebrew 安裝並啟用服務,相關的檔案會放在 /usr/local/var/gitea
。
第一次打開 http://127.0.0.1:3000 時會看到安裝設置頁面,為了方便我只有把資料庫改成 SQLite3 其他都預設即可。
在 Gitea 第一個註冊的使用者會是管理員,可以進到網站後台設定頁面,新增 OAuth2 Client http://127.0.0.1:3000/admin/auths/new
Name | Value |
---|---|
Authentication Type | OAuth2 |
Authentication Name | hydra-client(對應 redirect uri) |
OAuth2 Provider | OpenID Connect |
Client ID (Key) | 在 Step 2 建立的 CLIENT ID |
Client Secret | 在 Step 2 建立的 CLIENT SECRET |
OpenID Connect Auto Discovery URL | http://127.0.0.1:4444/.well-known/openid-configuration |
Additional Scopes | 其他 scope,例如 offline,profile,email |
雖然我有嘗試把 gitea 的 docker image 也包進 quickstart.yml
裡面隨著 kratos、hydra 一起安裝並啟動服務,但其實我沒有搞懂 docker network 的設定,導致在 Gitea 裡新增 OAuth2 Client 時設定 OpenID Connect Auto Discovery URL 後會遇到 dial tcp 127.0.0.1:4444: connect: connection refused
的問題無法啟用 OAuth2 登入,最後使用 Homebrew 將 Gitea 額外安裝起來才成功。