From 0ddfbdbd23e0fde0f045814b248a0c52da99b844 Mon Sep 17 00:00:00 2001 From: ljw <84855512@qq.com> Date: Wed, 30 Oct 2024 15:46:12 +0800 Subject: [PATCH] up v --- cmd/apimain.go | 2 +- docs/admin/admin_docs.go | 15 +++++++++++++ docs/admin/admin_swagger.json | 15 +++++++++++++ docs/admin/admin_swagger.yaml | 10 +++++++++ docs/api/api_docs.go | 2 +- docs/api/api_swagger.json | 2 +- docs/api/api_swagger.yaml | 2 +- http/controller/api/login.go | 2 +- service/oauth.go | 42 +++++++++++++++++------------------ 9 files changed, 66 insertions(+), 26 deletions(-) diff --git a/cmd/apimain.go b/cmd/apimain.go index ae66c10..2589964 100644 --- a/cmd/apimain.go +++ b/cmd/apimain.go @@ -101,7 +101,7 @@ func main() { } func DatabaseAutoUpdate() { - version := 242 + version := 243 db := global.DB diff --git a/docs/admin/admin_docs.go b/docs/admin/admin_docs.go index f4547ab..684818c 100644 --- a/docs/admin/admin_docs.go +++ b/docs/admin/admin_docs.go @@ -3164,11 +3164,17 @@ const docTemplateadmin = `{ "id": { "type": "integer" }, + "issuer": { + "type": "string" + }, "op": { "type": "string" }, "redirect_url": { "type": "string" + }, + "scopes": { + "type": "string" } } }, @@ -3749,12 +3755,18 @@ const docTemplateadmin = `{ "id": { "type": "integer" }, + "issuer": { + "type": "string" + }, "op": { "type": "string" }, "redirect_url": { "type": "string" }, + "scopes": { + "type": "string" + }, "updated_at": { "type": "string" } @@ -3795,6 +3807,9 @@ const docTemplateadmin = `{ "id": { "type": "string" }, + "last_online_ip": { + "type": "string" + }, "last_online_time": { "type": "integer" }, diff --git a/docs/admin/admin_swagger.json b/docs/admin/admin_swagger.json index 7e871e7..27961d3 100644 --- a/docs/admin/admin_swagger.json +++ b/docs/admin/admin_swagger.json @@ -3157,11 +3157,17 @@ "id": { "type": "integer" }, + "issuer": { + "type": "string" + }, "op": { "type": "string" }, "redirect_url": { "type": "string" + }, + "scopes": { + "type": "string" } } }, @@ -3742,12 +3748,18 @@ "id": { "type": "integer" }, + "issuer": { + "type": "string" + }, "op": { "type": "string" }, "redirect_url": { "type": "string" }, + "scopes": { + "type": "string" + }, "updated_at": { "type": "string" } @@ -3788,6 +3800,9 @@ "id": { "type": "string" }, + "last_online_ip": { + "type": "string" + }, "last_online_time": { "type": "integer" }, diff --git a/docs/admin/admin_swagger.yaml b/docs/admin/admin_swagger.yaml index ea9d4f9..1d6aeb2 100644 --- a/docs/admin/admin_swagger.yaml +++ b/docs/admin/admin_swagger.yaml @@ -105,10 +105,14 @@ definitions: type: string id: type: integer + issuer: + type: string op: type: string redirect_url: type: string + scopes: + type: string required: - client_id - client_secret @@ -500,10 +504,14 @@ definitions: type: string id: type: integer + issuer: + type: string op: type: string redirect_url: type: string + scopes: + type: string updated_at: type: string type: object @@ -530,6 +538,8 @@ definitions: type: string id: type: string + last_online_ip: + type: string last_online_time: type: integer memory: diff --git a/docs/api/api_docs.go b/docs/api/api_docs.go index b2fd617..5f3e535 100644 --- a/docs/api/api_docs.go +++ b/docs/api/api_docs.go @@ -834,7 +834,7 @@ const docTemplateapi = `{ } }, "/login-options": { - "post": { + "get": { "description": "登录选项", "consumes": [ "application/json" diff --git a/docs/api/api_swagger.json b/docs/api/api_swagger.json index 4a4ccc5..75feb4e 100644 --- a/docs/api/api_swagger.json +++ b/docs/api/api_swagger.json @@ -827,7 +827,7 @@ } }, "/login-options": { - "post": { + "get": { "description": "登录选项", "consumes": [ "application/json" diff --git a/docs/api/api_swagger.yaml b/docs/api/api_swagger.yaml index 2bd93b4..49c1c70 100644 --- a/docs/api/api_swagger.yaml +++ b/docs/api/api_swagger.yaml @@ -715,7 +715,7 @@ paths: tags: - 登录 /login-options: - post: + get: consumes: - application/json description: 登录选项 diff --git a/http/controller/api/login.go b/http/controller/api/login.go index bae13e1..703d792 100644 --- a/http/controller/api/login.go +++ b/http/controller/api/login.go @@ -81,7 +81,7 @@ func (l *Login) Login(c *gin.Context) { // @Produce json // @Success 200 {object} []string // @Failure 500 {object} response.ErrorResponse -// @Router /login-options [post] +// @Router /login-options [get] func (l *Login) LoginOptions(c *gin.Context) { oauthOks := []string{} err, _ := service.AllService.OauthService.GetOauthConfig(model.OauthTypeGithub) diff --git a/service/oauth.go b/service/oauth.go index ea97608..17a3120 100644 --- a/service/oauth.go +++ b/service/oauth.go @@ -15,9 +15,9 @@ import ( "net/http" "net/url" "strconv" + "strings" "sync" "time" - "strings" ) // Define a struct to parse the .well-known/openid-configuration response @@ -88,10 +88,10 @@ type GoogleUserdata struct { VerifiedEmail bool `json:"verified_email"` } type OidcUserdata struct { - Sub string `json:"sub"` - Email string `json:"email"` - VerifiedEmail bool `json:"email_verified"` - Name string `json:"name"` + Sub string `json:"sub"` + Email string `json:"email"` + VerifiedEmail bool `json:"email_verified"` + Name string `json:"name"` PreferredUsername string `json:"preferred_username"` } @@ -156,27 +156,27 @@ func (os *OauthService) BeginAuth(op string) (error error, code, url string) { // Method to fetch OIDC configuration dynamically func FetchOidcConfig(issuer string) (error, OidcEndpoint) { - configURL := strings.TrimSuffix(issuer, "/") + "/.well-known/openid-configuration" + configURL := strings.TrimSuffix(issuer, "/") + "/.well-known/openid-configuration" - // Get the HTTP client (with or without proxy based on configuration) - client := getHTTPClientWithProxy() + // Get the HTTP client (with or without proxy based on configuration) + client := getHTTPClientWithProxy() - resp, err := client.Get(configURL) - if err != nil { - return errors.New("failed to fetch OIDC configuration"), OidcEndpoint{} - } - defer resp.Body.Close() + resp, err := client.Get(configURL) + if err != nil { + return errors.New("failed to fetch OIDC configuration"), OidcEndpoint{} + } + defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - return errors.New("OIDC configuration not found, status code: %d"), OidcEndpoint{} - } + if resp.StatusCode != http.StatusOK { + return errors.New("OIDC configuration not found, status code: %d"), OidcEndpoint{} + } - var endpoint OidcEndpoint - if err := json.NewDecoder(resp.Body).Decode(&endpoint); err != nil { - return errors.New("failed to parse OIDC configuration"), OidcEndpoint{} - } + var endpoint OidcEndpoint + if err := json.NewDecoder(resp.Body).Decode(&endpoint); err != nil { + return errors.New("failed to parse OIDC configuration"), OidcEndpoint{} + } - return nil, endpoint + return nil, endpoint } // GetOauthConfig retrieves the OAuth2 configuration based on the provider type