Bläddra i källkod

feat: oauth2对接

tuon 1 år sedan
förälder
incheckning
123bb45a95

+ 8 - 8
conf/app.conf

@@ -25,11 +25,11 @@ thirdsessionname =
 thirdsessioncheckurl =
 
 
-oauth2_client_id =
-oauth2_client_secret =
-oauth2_authorize_endpoint =
-oauth2_token_endpoint =
-oauth2_redirect_uri =
-oauth2_scopes = ""
-oauth2_userinfo =
-oauth2_enable = false
+oauth2_client_id = XVlBzgbaiCMRAjWw111
+oauth2_client_secret = XVlBzgbaiCMRAjWw123
+oauth2_authorize_endpoint = https://www.tonyandmoney.cn/oauth/authorize
+oauth2_token_endpoint = https://www.tonyandmoney.cn/oauth/token
+oauth2_redirect_uri = http://127.0.0.1:5173/
+oauth2_scopes = "userinfo"
+oauth2_userinfo = https://api.tonyandmoney.cn/user/info
+oauth2_enable = true

BIN
data/db/sqlite.db


+ 13 - 0
frontend/src/pages/error/index.tsx

@@ -0,0 +1,13 @@
+/**
+ * @author tuonian
+ * @date 2023/12/18
+ */
+import './less.less'
+
+
+export const ErrorPage = () => {
+
+  return (<div className="error-page">
+
+  </div>)
+}

+ 3 - 0
frontend/src/pages/error/less.less

@@ -0,0 +1,3 @@
+.error-page{
+
+}

+ 2 - 0
frontend/src/routes/index.tsx

@@ -23,6 +23,7 @@ import {SignupPage} from "../pages/signup";
 import {UserActions} from "../store/slice/user.ts";
 import dayjs from "dayjs";
 import {SSOWrapper} from "../pages/login/sso.tsx";
+import {ErrorPage} from "../pages/error";
 
 /**
  * @author tuonian
@@ -155,6 +156,7 @@ export const MyRouter = () => {
                            )
                        })
                    }
+                   <Route path="/error" Component={ErrorPage} />
                    <Route path="/login" Component={LoginPage} />
                    <Route path="/signup" Component={SignupPage} />
                </Routes>

+ 2 - 2
frontend/vite.config.ts

@@ -53,8 +53,8 @@ export default defineConfig(({command, mode})=>{
           }
         } : {
           "/api":{
-            target: 'http://10.10.0.1:8080',
-            // target: 'http://127.0.0.1:8080',
+            // target: 'http://10.10.0.1:8080',
+            target: 'http://127.0.0.1:8080',
             rewrite: path => path.replace(/^\/api/,"")
           }
         }

+ 5 - 3
server/config/config.go

@@ -38,9 +38,11 @@ var OauthConfig = &CompleteOauth2Config{
 	Config: &oauth2.Config{
 		ClientID:     "",
 		ClientSecret: "",
-		Endpoint:     oauth2.Endpoint{},
-		RedirectURL:  "",
-		Scopes:       []string{},
+		Endpoint: oauth2.Endpoint{
+			AuthStyle: oauth2.AuthStyleInParams,
+		},
+		RedirectURL: "",
+		Scopes:      []string{},
 	},
 }
 

+ 1 - 1
server/middleware/auth.go

@@ -55,7 +55,7 @@ func checkThirdSession(ctx *context.Context, sess session.Store) {
 }
 
 func AuthFilter(ctx *context.Context) {
-	path := ctx.Request.RequestURI
+	path := ctx.Request.URL.Path
 	path = strings.TrimSuffix(path, "/")
 	path = strings.TrimPrefix(path, config.Config.BaseApi)
 	if whitelist[path] {

+ 2 - 0
server/routers/router.go

@@ -26,6 +26,8 @@ func init() {
 
 	userController := controllers.NewUserController()
 
+	logs.Info("baseApi", config.BaseApi)
+
 	ns := beego.NewNamespace(config.BaseApi,
 		beego.NSRouter(NginxR, &controllers.NginxController{}),
 		beego.NSRouter(NginxGetR, &controllers.NginxController{}, "post:Update"),