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

+ 1 - 1
cmd/apimain.go

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

+ 15 - 0
docs/admin/admin_docs.go

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

+ 15 - 0
docs/admin/admin_swagger.json

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

+ 10 - 0
docs/admin/admin_swagger.yaml

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

+ 1 - 1
docs/api/api_docs.go

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

+ 1 - 1
docs/api/api_swagger.json

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

+ 1 - 1
docs/api/api_swagger.yaml

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

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

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

+ 21 - 21
service/oauth.go

@@ -15,9 +15,9 @@ import (
15 15
 	"net/http"
16 16
 	"net/url"
17 17
 	"strconv"
18
+	"strings"
18 19
 	"sync"
19 20
 	"time"
20
-	"strings"
21 21
 )
22 22
 
23 23
 // Define a struct to parse the .well-known/openid-configuration response
@@ -88,10 +88,10 @@ type GoogleUserdata struct {
88 88
 	VerifiedEmail bool   `json:"verified_email"`
89 89
 }
90 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 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 157
 // Method to fetch OIDC configuration dynamically
158 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 182
 // GetOauthConfig retrieves the OAuth2 configuration based on the provider type