Просмотр исходного кода

fix: Oauth callback url is fixed to host+/api/oidc/callback (#314)

lejianwen месяцев назад: 6
Родитель
Сommit
1d2d1d4c98

+ 2 - 2
README.md

@@ -94,8 +94,8 @@
94
     - 对于`OIDC`, `Issuer`是必须的。`Scopes`是可选的,默认为 `openid,profile,email`. 确保可以获取 `sub`,`email` 和`preferred_username`
94
     - 对于`OIDC`, `Issuer`是必须的。`Scopes`是可选的,默认为 `openid,profile,email`. 确保可以获取 `sub`,`email` 和`preferred_username`
95
     - `github oauth app`在`Settings`->`Developer settings`->`OAuth Apps`->`New OAuth App`
95
     - `github oauth app`在`Settings`->`Developer settings`->`OAuth Apps`->`New OAuth App`
96
       中创建,地址 [https://github.com/settings/developers](https://github.com/settings/developers)
96
       中创建,地址 [https://github.com/settings/developers](https://github.com/settings/developers)
97
-    - `Authorization callback URL`填写`http://<your server[:port]>/api/oauth/callback`
98
-      ,比如`http://127.0.0.1:21114/api/oauth/callback`
97
+    - `Authorization callback URL`填写`http://<your server[:port]>/api/oidc/callback`
98
+      ,比如`http://127.0.0.1:21114/api/oidc/callback`
99
 7. 登录日志
99
 7. 登录日志
100
 8. 链接日志
100
 8. 链接日志
101
 9. 文件传输日志
101
 9. 文件传输日志

+ 2 - 2
README_EN.md

@@ -94,8 +94,8 @@ displaying data.Frontend code is available at [rustdesk-api-web](https://github.
94
     - 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`
94
     - 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`
95
     - Create a `GitHub OAuth App`
95
     - Create a `GitHub OAuth App`
96
       at `Settings` -> `Developer settings` -> `OAuth Apps` -> `New OAuth App` [here](https://github.com/settings/developers).
96
       at `Settings` -> `Developer settings` -> `OAuth Apps` -> `New OAuth App` [here](https://github.com/settings/developers).
97
-    - Set the `Authorization callback URL` to `http://<your server[:port]>/api/oauth/callback`,
98
-      e.g., `http://127.0.0.1:21114/api/oauth/callback`.
97
+    - Set the `Authorization callback URL` to `http://<your server[:port]>/api/oidc/callback`,
98
+      e.g., `http://127.0.0.1:21114/api/oidc/callback`.
99
    
99
    
100
 7. Login logs
100
 7. Login logs
101
 8. Connection logs
101
 8. Connection logs

+ 11 - 11
docs/api/api_docs.go

@@ -954,9 +954,9 @@ const docTemplateapi = `{
954
                 }
954
                 }
955
             }
955
             }
956
         },
956
         },
957
-        "/oauth/callback": {
958
-            "get": {
959
-                "description": "OauthCallback",
957
+        "/oidc/auth": {
958
+            "post": {
959
+                "description": "OidcAuth",
960
                 "consumes": [
960
                 "consumes": [
961
                     "application/json"
961
                     "application/json"
962
                 ],
962
                 ],
@@ -966,7 +966,7 @@ const docTemplateapi = `{
966
                 "tags": [
966
                 "tags": [
967
                     "Oauth"
967
                     "Oauth"
968
                 ],
968
                 ],
969
-                "summary": "OauthCallback",
969
+                "summary": "OidcAuth",
970
                 "responses": {
970
                 "responses": {
971
                     "200": {
971
                     "200": {
972
                         "description": "OK",
972
                         "description": "OK",
@@ -983,9 +983,9 @@ const docTemplateapi = `{
983
                 }
983
                 }
984
             }
984
             }
985
         },
985
         },
986
-        "/oidc/auth": {
987
-            "post": {
988
-                "description": "OidcAuth",
986
+        "/oidc/auth-query": {
987
+            "get": {
988
+                "description": "OidcAuthQuery",
989
                 "consumes": [
989
                 "consumes": [
990
                     "application/json"
990
                     "application/json"
991
                 ],
991
                 ],
@@ -995,7 +995,7 @@ const docTemplateapi = `{
995
                 "tags": [
995
                 "tags": [
996
                     "Oauth"
996
                     "Oauth"
997
                 ],
997
                 ],
998
-                "summary": "OidcAuth",
998
+                "summary": "OidcAuthQuery",
999
                 "responses": {
999
                 "responses": {
1000
                     "200": {
1000
                     "200": {
1001
                         "description": "OK",
1001
                         "description": "OK",
@@ -1012,9 +1012,9 @@ const docTemplateapi = `{
1012
                 }
1012
                 }
1013
             }
1013
             }
1014
         },
1014
         },
1015
-        "/oidc/auth-query": {
1015
+        "/oidc/callback": {
1016
             "get": {
1016
             "get": {
1017
-                "description": "OidcAuthQuery",
1017
+                "description": "OauthCallback",
1018
                 "consumes": [
1018
                 "consumes": [
1019
                     "application/json"
1019
                     "application/json"
1020
                 ],
1020
                 ],
@@ -1024,7 +1024,7 @@ const docTemplateapi = `{
1024
                 "tags": [
1024
                 "tags": [
1025
                     "Oauth"
1025
                     "Oauth"
1026
                 ],
1026
                 ],
1027
-                "summary": "OidcAuthQuery",
1027
+                "summary": "OauthCallback",
1028
                 "responses": {
1028
                 "responses": {
1029
                     "200": {
1029
                     "200": {
1030
                         "description": "OK",
1030
                         "description": "OK",

+ 11 - 11
docs/api/api_swagger.json

@@ -947,9 +947,9 @@
947
                 }
947
                 }
948
             }
948
             }
949
         },
949
         },
950
-        "/oauth/callback": {
951
-            "get": {
952
-                "description": "OauthCallback",
950
+        "/oidc/auth": {
951
+            "post": {
952
+                "description": "OidcAuth",
953
                 "consumes": [
953
                 "consumes": [
954
                     "application/json"
954
                     "application/json"
955
                 ],
955
                 ],
@@ -959,7 +959,7 @@
959
                 "tags": [
959
                 "tags": [
960
                     "Oauth"
960
                     "Oauth"
961
                 ],
961
                 ],
962
-                "summary": "OauthCallback",
962
+                "summary": "OidcAuth",
963
                 "responses": {
963
                 "responses": {
964
                     "200": {
964
                     "200": {
965
                         "description": "OK",
965
                         "description": "OK",
@@ -976,9 +976,9 @@
976
                 }
976
                 }
977
             }
977
             }
978
         },
978
         },
979
-        "/oidc/auth": {
980
-            "post": {
981
-                "description": "OidcAuth",
979
+        "/oidc/auth-query": {
980
+            "get": {
981
+                "description": "OidcAuthQuery",
982
                 "consumes": [
982
                 "consumes": [
983
                     "application/json"
983
                     "application/json"
984
                 ],
984
                 ],
@@ -988,7 +988,7 @@
988
                 "tags": [
988
                 "tags": [
989
                     "Oauth"
989
                     "Oauth"
990
                 ],
990
                 ],
991
-                "summary": "OidcAuth",
991
+                "summary": "OidcAuthQuery",
992
                 "responses": {
992
                 "responses": {
993
                     "200": {
993
                     "200": {
994
                         "description": "OK",
994
                         "description": "OK",
@@ -1005,9 +1005,9 @@
1005
                 }
1005
                 }
1006
             }
1006
             }
1007
         },
1007
         },
1008
-        "/oidc/auth-query": {
1008
+        "/oidc/callback": {
1009
             "get": {
1009
             "get": {
1010
-                "description": "OidcAuthQuery",
1010
+                "description": "OauthCallback",
1011
                 "consumes": [
1011
                 "consumes": [
1012
                     "application/json"
1012
                     "application/json"
1013
                 ],
1013
                 ],
@@ -1017,7 +1017,7 @@
1017
                 "tags": [
1017
                 "tags": [
1018
                     "Oauth"
1018
                     "Oauth"
1019
                 ],
1019
                 ],
1020
-                "summary": "OidcAuthQuery",
1020
+                "summary": "OauthCallback",
1021
                 "responses": {
1021
                 "responses": {
1022
                     "200": {
1022
                     "200": {
1023
                         "description": "OK",
1023
                         "description": "OK",

+ 11 - 11
docs/api/api_swagger.yaml

@@ -792,11 +792,11 @@ paths:
792
       summary: 登出
792
       summary: 登出
793
       tags:
793
       tags:
794
       - 登录
794
       - 登录
795
-  /oauth/callback:
796
-    get:
795
+  /oidc/auth:
796
+    post:
797
       consumes:
797
       consumes:
798
       - application/json
798
       - application/json
799
-      description: OauthCallback
799
+      description: OidcAuth
800
       produces:
800
       produces:
801
       - application/json
801
       - application/json
802
       responses:
802
       responses:
@@ -808,14 +808,14 @@ paths:
808
           description: Internal Server Error
808
           description: Internal Server Error
809
           schema:
809
           schema:
810
             $ref: '#/definitions/response.ErrorResponse'
810
             $ref: '#/definitions/response.ErrorResponse'
811
-      summary: OauthCallback
811
+      summary: OidcAuth
812
       tags:
812
       tags:
813
       - Oauth
813
       - Oauth
814
-  /oidc/auth:
815
-    post:
814
+  /oidc/auth-query:
815
+    get:
816
       consumes:
816
       consumes:
817
       - application/json
817
       - application/json
818
-      description: OidcAuth
818
+      description: OidcAuthQuery
819
       produces:
819
       produces:
820
       - application/json
820
       - application/json
821
       responses:
821
       responses:
@@ -827,14 +827,14 @@ paths:
827
           description: Internal Server Error
827
           description: Internal Server Error
828
           schema:
828
           schema:
829
             $ref: '#/definitions/response.ErrorResponse'
829
             $ref: '#/definitions/response.ErrorResponse'
830
-      summary: OidcAuth
830
+      summary: OidcAuthQuery
831
       tags:
831
       tags:
832
       - Oauth
832
       - Oauth
833
-  /oidc/auth-query:
833
+  /oidc/callback:
834
     get:
834
     get:
835
       consumes:
835
       consumes:
836
       - application/json
836
       - application/json
837
-      description: OidcAuthQuery
837
+      description: OauthCallback
838
       produces:
838
       produces:
839
       - application/json
839
       - application/json
840
       responses:
840
       responses:
@@ -846,7 +846,7 @@ paths:
846
           description: Internal Server Error
846
           description: Internal Server Error
847
           schema:
847
           schema:
848
             $ref: '#/definitions/response.ErrorResponse'
848
             $ref: '#/definitions/response.ErrorResponse'
849
-      summary: OidcAuthQuery
849
+      summary: OauthCallback
850
       tags:
850
       tags:
851
       - Oauth
851
       - Oauth
852
   /peers:
852
   /peers:

+ 1 - 1
http/controller/api/ouath.go

@@ -143,7 +143,7 @@ func (o *Oauth) OidcAuthQuery(c *gin.Context) {
143
 // @Produce  json
143
 // @Produce  json
144
 // @Success 200 {object} apiResp.LoginRes
144
 // @Success 200 {object} apiResp.LoginRes
145
 // @Failure 500 {object} response.ErrorResponse
145
 // @Failure 500 {object} response.ErrorResponse
146
-// @Router /oauth/callback [get]
146
+// @Router /oidc/callback [get]
147
 func (o *Oauth) OauthCallback(c *gin.Context) {
147
 func (o *Oauth) OauthCallback(c *gin.Context) {
148
 	state := c.Query("state")
148
 	state := c.Query("state")
149
 	if state == "" {
149
 	if state == "" {

+ 4 - 0
http/router/api.go

@@ -49,6 +49,10 @@ func ApiInit(g *gin.Engine) {
49
 		frg.GET("/oauth/callback", o.OauthCallback)
49
 		frg.GET("/oauth/callback", o.OauthCallback)
50
 		frg.GET("/oauth/login", o.OauthCallback)
50
 		frg.GET("/oauth/login", o.OauthCallback)
51
 		frg.GET("/oauth/msg", o.Message)
51
 		frg.GET("/oauth/msg", o.Message)
52
+
53
+		frg.GET("/oidc/callback", o.OauthCallback)
54
+		frg.GET("/oidc/login", o.OauthCallback)
55
+		frg.GET("/oidc/msg", o.Message)
52
 	}
56
 	}
53
 	{
57
 	{
54
 		pe := &api.Peer{}
58
 		pe := &api.Peer{}

+ 1 - 1
resources/templates/oauth_fail.html

@@ -62,7 +62,7 @@
62
         var title = 'OauthFailed'
62
         var title = 'OauthFailed'
63
         var msg = '{{.message}}'
63
         var msg = '{{.message}}'
64
         var btn = 'Close'
64
         var btn = 'Close'
65
-        document.writeln('<script src="/api/oauth/msg?lang=' + lang + '&msg=' + msg + '&title=OauthFailed"><\/script>');
65
+        document.writeln('<script src="/api/oidc/msg?lang=' + lang + '&msg=' + msg + '&title=OauthFailed"><\/script>');
66
     </script>
66
     </script>
67
 </head>
67
 </head>
68
 <body>
68
 <body>

+ 1 - 1
resources/templates/oauth_success.html

@@ -61,7 +61,7 @@
61
         var title = 'OauthSuccess'
61
         var title = 'OauthSuccess'
62
         var msg = '{{.message}}'
62
         var msg = '{{.message}}'
63
         var btn = 'Close'
63
         var btn = 'Close'
64
-        document.writeln('<script src="/api/oauth/msg?lang=' + lang + '&msg=' + msg + '&title=OauthSuccess"><\/script>');
64
+        document.writeln('<script src="/api/oidc/msg?lang=' + lang + '&msg=' + msg + '&title=OauthSuccess"><\/script>');
65
     </script>
65
     </script>
66
 </head>
66
 </head>
67
 <body>
67
 <body>