From 1d2d1d4c981e65f4266689890c8b6fdd98105052 Mon Sep 17 00:00:00 2001 From: lejianwen <84855512@qq.com> Date: Fri, 11 Jul 2025 09:55:48 +0800 Subject: [PATCH] fix: Oauth callback url is fixed to host+/api/oidc/callback (#314) --- README.md | 4 +- README_EN.md | 4 +- docs/api/api_docs.go | 58 +++++++++++++------------- docs/api/api_swagger.json | 58 +++++++++++++------------- docs/api/api_swagger.yaml | 38 ++++++++--------- http/controller/api/ouath.go | 2 +- http/router/api.go | 4 ++ resources/templates/oauth_fail.html | 2 +- resources/templates/oauth_success.html | 2 +- 9 files changed, 88 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index cb8ac97..7ccf3c5 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,8 @@ - 对于`OIDC`, `Issuer`是必须的。`Scopes`是可选的,默认为 `openid,profile,email`. 确保可以获取 `sub`,`email` 和`preferred_username` - `github oauth app`在`Settings`->`Developer settings`->`OAuth Apps`->`New OAuth App` 中创建,地址 [https://github.com/settings/developers](https://github.com/settings/developers) - - `Authorization callback URL`填写`http:///api/oauth/callback` - ,比如`http://127.0.0.1:21114/api/oauth/callback` + - `Authorization callback URL`填写`http:///api/oidc/callback` + ,比如`http://127.0.0.1:21114/api/oidc/callback` 7. 登录日志 8. 链接日志 9. 文件传输日志 diff --git a/README_EN.md b/README_EN.md index a8446ed..c17bd44 100644 --- a/README_EN.md +++ b/README_EN.md @@ -94,8 +94,8 @@ displaying data.Frontend code is available at [rustdesk-api-web](https://github. - For `OIDC`, you must set the `Issuer`. And `Scopes` is optional which default is `openid,email,profile`, please make sure this `Oauth App` can access `sub`, `email` and `preferred_username` - Create a `GitHub OAuth App` at `Settings` -> `Developer settings` -> `OAuth Apps` -> `New OAuth App` [here](https://github.com/settings/developers). - - Set the `Authorization callback URL` to `http:///api/oauth/callback`, - e.g., `http://127.0.0.1:21114/api/oauth/callback`. + - Set the `Authorization callback URL` to `http:///api/oidc/callback`, + e.g., `http://127.0.0.1:21114/api/oidc/callback`. 7. Login logs 8. Connection logs diff --git a/docs/api/api_docs.go b/docs/api/api_docs.go index c7976e2..94d7706 100644 --- a/docs/api/api_docs.go +++ b/docs/api/api_docs.go @@ -954,35 +954,6 @@ const docTemplateapi = `{ } } }, - "/oauth/callback": { - "get": { - "description": "OauthCallback", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Oauth" - ], - "summary": "OauthCallback", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/api.LoginRes" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/response.ErrorResponse" - } - } - } - } - }, "/oidc/auth": { "post": { "description": "OidcAuth", @@ -1041,6 +1012,35 @@ const docTemplateapi = `{ } } }, + "/oidc/callback": { + "get": { + "description": "OauthCallback", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Oauth" + ], + "summary": "OauthCallback", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/api.LoginRes" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrorResponse" + } + } + } + } + }, "/peers": { "get": { "security": [ diff --git a/docs/api/api_swagger.json b/docs/api/api_swagger.json index 98c95a0..9b50955 100644 --- a/docs/api/api_swagger.json +++ b/docs/api/api_swagger.json @@ -947,35 +947,6 @@ } } }, - "/oauth/callback": { - "get": { - "description": "OauthCallback", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Oauth" - ], - "summary": "OauthCallback", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/api.LoginRes" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/response.ErrorResponse" - } - } - } - } - }, "/oidc/auth": { "post": { "description": "OidcAuth", @@ -1034,6 +1005,35 @@ } } }, + "/oidc/callback": { + "get": { + "description": "OauthCallback", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Oauth" + ], + "summary": "OauthCallback", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/api.LoginRes" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrorResponse" + } + } + } + } + }, "/peers": { "get": { "security": [ diff --git a/docs/api/api_swagger.yaml b/docs/api/api_swagger.yaml index 4bdcf82..a654e33 100644 --- a/docs/api/api_swagger.yaml +++ b/docs/api/api_swagger.yaml @@ -792,25 +792,6 @@ paths: summary: 登出 tags: - 登录 - /oauth/callback: - get: - consumes: - - application/json - description: OauthCallback - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/api.LoginRes' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/response.ErrorResponse' - summary: OauthCallback - tags: - - Oauth /oidc/auth: post: consumes: @@ -849,6 +830,25 @@ paths: summary: OidcAuthQuery tags: - Oauth + /oidc/callback: + get: + consumes: + - application/json + description: OauthCallback + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/api.LoginRes' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrorResponse' + summary: OauthCallback + tags: + - Oauth /peers: get: consumes: diff --git a/http/controller/api/ouath.go b/http/controller/api/ouath.go index 3ffb924..0ea2ebd 100644 --- a/http/controller/api/ouath.go +++ b/http/controller/api/ouath.go @@ -143,7 +143,7 @@ func (o *Oauth) OidcAuthQuery(c *gin.Context) { // @Produce json // @Success 200 {object} apiResp.LoginRes // @Failure 500 {object} response.ErrorResponse -// @Router /oauth/callback [get] +// @Router /oidc/callback [get] func (o *Oauth) OauthCallback(c *gin.Context) { state := c.Query("state") if state == "" { diff --git a/http/router/api.go b/http/router/api.go index 6691de9..52c7773 100644 --- a/http/router/api.go +++ b/http/router/api.go @@ -49,6 +49,10 @@ func ApiInit(g *gin.Engine) { frg.GET("/oauth/callback", o.OauthCallback) frg.GET("/oauth/login", o.OauthCallback) frg.GET("/oauth/msg", o.Message) + + frg.GET("/oidc/callback", o.OauthCallback) + frg.GET("/oidc/login", o.OauthCallback) + frg.GET("/oidc/msg", o.Message) } { pe := &api.Peer{} diff --git a/resources/templates/oauth_fail.html b/resources/templates/oauth_fail.html index a8a296f..2bfc7df 100644 --- a/resources/templates/oauth_fail.html +++ b/resources/templates/oauth_fail.html @@ -62,7 +62,7 @@ var title = 'OauthFailed' var msg = '{{.message}}' var btn = 'Close' - document.writeln(' diff --git a/resources/templates/oauth_success.html b/resources/templates/oauth_success.html index cfdffe9..7454567 100644 --- a/resources/templates/oauth_success.html +++ b/resources/templates/oauth_success.html @@ -61,7 +61,7 @@ var title = 'OauthSuccess' var msg = '{{.message}}' var btn = 'Close' - document.writeln('