ljw 1 год назад
Родитель
Сommit
3c30ad145c

+ 1 - 1
cmd/apimain.go

@@ -101,7 +101,7 @@ func main() {
101
 }
101
 }
102
 
102
 
103
 func DatabaseAutoUpdate() {
103
 func DatabaseAutoUpdate() {
104
-	version := 242
104
+	version := 243
105
 
105
 
106
 	db := global.DB
106
 	db := global.DB
107
 
107
 

+ 15 - 0
docs/admin/admin_docs.go

@@ -3164,11 +3164,17 @@ const docTemplateadmin = `{
3164
                 "id": {
3164
                 "id": {
3165
                     "type": "integer"
3165
                     "type": "integer"
3166
                 },
3166
                 },
3167
+                "issuer": {
3168
+                    "type": "string"
3169
+                },
3167
                 "op": {
3170
                 "op": {
3168
                     "type": "string"
3171
                     "type": "string"
3169
                 },
3172
                 },
3170
                 "redirect_url": {
3173
                 "redirect_url": {
3171
                     "type": "string"
3174
                     "type": "string"
3175
+                },
3176
+                "scopes": {
3177
+                    "type": "string"
3172
                 }
3178
                 }
3173
             }
3179
             }
3174
         },
3180
         },
@@ -3749,12 +3755,18 @@ const docTemplateadmin = `{
3749
                 "id": {
3755
                 "id": {
3750
                     "type": "integer"
3756
                     "type": "integer"
3751
                 },
3757
                 },
3758
+                "issuer": {
3759
+                    "type": "string"
3760
+                },
3752
                 "op": {
3761
                 "op": {
3753
                     "type": "string"
3762
                     "type": "string"
3754
                 },
3763
                 },
3755
                 "redirect_url": {
3764
                 "redirect_url": {
3756
                     "type": "string"
3765
                     "type": "string"
3757
                 },
3766
                 },
3767
+                "scopes": {
3768
+                    "type": "string"
3769
+                },
3758
                 "updated_at": {
3770
                 "updated_at": {
3759
                     "type": "string"
3771
                     "type": "string"
3760
                 }
3772
                 }
@@ -3795,6 +3807,9 @@ const docTemplateadmin = `{
3795
                 "id": {
3807
                 "id": {
3796
                     "type": "string"
3808
                     "type": "string"
3797
                 },
3809
                 },
3810
+                "last_online_ip": {
3811
+                    "type": "string"
3812
+                },
3798
                 "last_online_time": {
3813
                 "last_online_time": {
3799
                     "type": "integer"
3814
                     "type": "integer"
3800
                 },
3815
                 },

+ 15 - 0
docs/admin/admin_swagger.json

@@ -3157,11 +3157,17 @@
3157
                 "id": {
3157
                 "id": {
3158
                     "type": "integer"
3158
                     "type": "integer"
3159
                 },
3159
                 },
3160
+                "issuer": {
3161
+                    "type": "string"
3162
+                },
3160
                 "op": {
3163
                 "op": {
3161
                     "type": "string"
3164
                     "type": "string"
3162
                 },
3165
                 },
3163
                 "redirect_url": {
3166
                 "redirect_url": {
3164
                     "type": "string"
3167
                     "type": "string"
3168
+                },
3169
+                "scopes": {
3170
+                    "type": "string"
3165
                 }
3171
                 }
3166
             }
3172
             }
3167
         },
3173
         },
@@ -3742,12 +3748,18 @@
3742
                 "id": {
3748
                 "id": {
3743
                     "type": "integer"
3749
                     "type": "integer"
3744
                 },
3750
                 },
3751
+                "issuer": {
3752
+                    "type": "string"
3753
+                },
3745
                 "op": {
3754
                 "op": {
3746
                     "type": "string"
3755
                     "type": "string"
3747
                 },
3756
                 },
3748
                 "redirect_url": {
3757
                 "redirect_url": {
3749
                     "type": "string"
3758
                     "type": "string"
3750
                 },
3759
                 },
3760
+                "scopes": {
3761
+                    "type": "string"
3762
+                },
3751
                 "updated_at": {
3763
                 "updated_at": {
3752
                     "type": "string"
3764
                     "type": "string"
3753
                 }
3765
                 }
@@ -3788,6 +3800,9 @@
3788
                 "id": {
3800
                 "id": {
3789
                     "type": "string"
3801
                     "type": "string"
3790
                 },
3802
                 },
3803
+                "last_online_ip": {
3804
+                    "type": "string"
3805
+                },
3791
                 "last_online_time": {
3806
                 "last_online_time": {
3792
                     "type": "integer"
3807
                     "type": "integer"
3793
                 },
3808
                 },

+ 10 - 0
docs/admin/admin_swagger.yaml

@@ -105,10 +105,14 @@ definitions:
105
         type: string
105
         type: string
106
       id:
106
       id:
107
         type: integer
107
         type: integer
108
+      issuer:
109
+        type: string
108
       op:
110
       op:
109
         type: string
111
         type: string
110
       redirect_url:
112
       redirect_url:
111
         type: string
113
         type: string
114
+      scopes:
115
+        type: string
112
     required:
116
     required:
113
     - client_id
117
     - client_id
114
     - client_secret
118
     - client_secret
@@ -500,10 +504,14 @@ definitions:
500
         type: string
504
         type: string
501
       id:
505
       id:
502
         type: integer
506
         type: integer
507
+      issuer:
508
+        type: string
503
       op:
509
       op:
504
         type: string
510
         type: string
505
       redirect_url:
511
       redirect_url:
506
         type: string
512
         type: string
513
+      scopes:
514
+        type: string
507
       updated_at:
515
       updated_at:
508
         type: string
516
         type: string
509
     type: object
517
     type: object
@@ -530,6 +538,8 @@ definitions:
530
         type: string
538
         type: string
531
       id:
539
       id:
532
         type: string
540
         type: string
541
+      last_online_ip:
542
+        type: string
533
       last_online_time:
543
       last_online_time:
534
         type: integer
544
         type: integer
535
       memory:
545
       memory:

+ 1 - 1
docs/api/api_docs.go

@@ -834,7 +834,7 @@ const docTemplateapi = `{
834
             }
834
             }
835
         },
835
         },
836
         "/login-options": {
836
         "/login-options": {
837
-            "post": {
837
+            "get": {
838
                 "description": "登录选项",
838
                 "description": "登录选项",
839
                 "consumes": [
839
                 "consumes": [
840
                     "application/json"
840
                     "application/json"

+ 1 - 1
docs/api/api_swagger.json

@@ -827,7 +827,7 @@
827
             }
827
             }
828
         },
828
         },
829
         "/login-options": {
829
         "/login-options": {
830
-            "post": {
830
+            "get": {
831
                 "description": "登录选项",
831
                 "description": "登录选项",
832
                 "consumes": [
832
                 "consumes": [
833
                     "application/json"
833
                     "application/json"

+ 1 - 1
docs/api/api_swagger.yaml

@@ -715,7 +715,7 @@ paths:
715
       tags:
715
       tags:
716
       - 登录
716
       - 登录
717
   /login-options:
717
   /login-options:
718
-    post:
718
+    get:
719
       consumes:
719
       consumes:
720
       - application/json
720
       - application/json
721
       description: 登录选项
721
       description: 登录选项

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

@@ -81,7 +81,7 @@ func (l *Login) Login(c *gin.Context) {
81
 // @Produce  json
81
 // @Produce  json
82
 // @Success 200 {object} []string
82
 // @Success 200 {object} []string
83
 // @Failure 500 {object} response.ErrorResponse
83
 // @Failure 500 {object} response.ErrorResponse
84
-// @Router /login-options [post]
84
+// @Router /login-options [get]
85
 func (l *Login) LoginOptions(c *gin.Context) {
85
 func (l *Login) LoginOptions(c *gin.Context) {
86
 	oauthOks := []string{}
86
 	oauthOks := []string{}
87
 	err, _ := service.AllService.OauthService.GetOauthConfig(model.OauthTypeGithub)
87
 	err, _ := service.AllService.OauthService.GetOauthConfig(model.OauthTypeGithub)

+ 21 - 21
service/oauth.go

@@ -15,9 +15,9 @@ import (
15
 	"net/http"
15
 	"net/http"
16
 	"net/url"
16
 	"net/url"
17
 	"strconv"
17
 	"strconv"
18
+	"strings"
18
 	"sync"
19
 	"sync"
19
 	"time"
20
 	"time"
20
-	"strings"
21
 )
21
 )
22
 
22
 
23
 // Define a struct to parse the .well-known/openid-configuration response
23
 // Define a struct to parse the .well-known/openid-configuration response
@@ -88,10 +88,10 @@ type GoogleUserdata struct {
88
 	VerifiedEmail bool   `json:"verified_email"`
88
 	VerifiedEmail bool   `json:"verified_email"`
89
 }
89
 }
90
 type OidcUserdata struct {
90
 type OidcUserdata struct {
91
-	Sub			  string `json:"sub"`
92
-	Email         string `json:"email"`
93
-	VerifiedEmail bool   `json:"email_verified"`
94
-	Name          string `json:"name"`
91
+	Sub               string `json:"sub"`
92
+	Email             string `json:"email"`
93
+	VerifiedEmail     bool   `json:"email_verified"`
94
+	Name              string `json:"name"`
95
 	PreferredUsername string `json:"preferred_username"`
95
 	PreferredUsername string `json:"preferred_username"`
96
 }
96
 }
97
 
97
 
@@ -156,27 +156,27 @@ func (os *OauthService) BeginAuth(op string) (error error, code, url string) {
156
 
156
 
157
 // Method to fetch OIDC configuration dynamically
157
 // Method to fetch OIDC configuration dynamically
158
 func FetchOidcConfig(issuer string) (error, OidcEndpoint) {
158
 func FetchOidcConfig(issuer string) (error, OidcEndpoint) {
159
-    configURL := strings.TrimSuffix(issuer, "/") + "/.well-known/openid-configuration"
159
+	configURL := strings.TrimSuffix(issuer, "/") + "/.well-known/openid-configuration"
160
 
160
 
161
-    // Get the HTTP client (with or without proxy based on configuration)
162
-    client := getHTTPClientWithProxy()
161
+	// Get the HTTP client (with or without proxy based on configuration)
162
+	client := getHTTPClientWithProxy()
163
 
163
 
164
-    resp, err := client.Get(configURL)
165
-    if err != nil {
166
-        return errors.New("failed to fetch OIDC configuration"), OidcEndpoint{}
167
-    }
168
-    defer resp.Body.Close()
164
+	resp, err := client.Get(configURL)
165
+	if err != nil {
166
+		return errors.New("failed to fetch OIDC configuration"), OidcEndpoint{}
167
+	}
168
+	defer resp.Body.Close()
169
 
169
 
170
-    if resp.StatusCode != http.StatusOK {
171
-        return errors.New("OIDC configuration not found, status code: %d"), OidcEndpoint{}
172
-    }
170
+	if resp.StatusCode != http.StatusOK {
171
+		return errors.New("OIDC configuration not found, status code: %d"), OidcEndpoint{}
172
+	}
173
 
173
 
174
-    var endpoint OidcEndpoint
175
-    if err := json.NewDecoder(resp.Body).Decode(&endpoint); err != nil {
176
-        return errors.New("failed to parse OIDC configuration"), OidcEndpoint{}
177
-    }
174
+	var endpoint OidcEndpoint
175
+	if err := json.NewDecoder(resp.Body).Decode(&endpoint); err != nil {
176
+		return errors.New("failed to parse OIDC configuration"), OidcEndpoint{}
177
+	}
178
 
178
 
179
-    return nil, endpoint
179
+	return nil, endpoint
180
 }
180
 }
181
 
181
 
182
 // GetOauthConfig retrieves the OAuth2 configuration based on the provider type
182
 // GetOauthConfig retrieves the OAuth2 configuration based on the provider type