diff --git a/.vscode/launch.json b/.vscode/launch.json index f56b972..c6b44ef 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "type": "go", "debugAdapter": "dlv-dap", "request": "launch", - "port": 44239, + "port": 2345, "host": "127.0.0.1", "mode": "exec", "program": "${workspaceFolder}/dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service" diff --git a/Makefile b/Makefile index fe83b58..d8e815c 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,17 @@ CUR_DIR=$(PWD) CUR_TAG ?= $(shell git describe --tags --match '*.*.*' | sort -V | tail -n1 | sed 's/-[0-9]*-g[0-9a-f]*//') PREV_TAG ?= $(shell git describe --tags --match '*.*.*' | sort -V | head -n2 | tail -n1 | sed 's/-[0-9]*-g[0-9a-f]*//') ARCHIVE_PATH=buildzip -PACKAGE_NAME=$(OS)-$(ARCHITECHTURE)-nextzenos-user-service-$(TAG) +ifeq ($(TAG),) +PACKAGE_NAME := $(OS)-$(ARCHITECHTURE)-nextzenos-user-service +else +PACKAGE_NAME := $(OS)-$(ARCHITECHTURE)-nextzenos-user-service-$(TAG) +endif COMMIT_MESSAGE ?="update" build_service: $(GORELEASERBUILD) --clean --snapshot -f .goreleaser.debug.yaml --id $(SERVICE)-$(ARCHITECHTURE) package: - cp -f $(CUR_DIR)/dist/$(SERVICE)-$(ARCHITECHTURE)_$(OS)_$(ARCHITECHTURE)_$(VERSION)/$(BIN_PATH)/$(SERVICE) $(CUR_DIR)/$(BIN_PATH) \ + cp $(CUR_DIR)/dist/$(SERVICE)-$(ARCHITECHTURE)_$(OS)_$(ARCHITECHTURE)_$(VERSION)/$(BIN_PATH)/$(SERVICE) $(CUR_DIR)/$(BIN_PATH) \ && tar -czvf $(PACKAGE_NAME).tar.gz $(CUR_DIR)/$(BUILD_PATH) archive_package: diff --git a/build/sysroot/usr/lib/systemd/system/casaos-user-servive.service b/build/sysroot/usr/lib/systemd/system/casaos-user-servive.service new file mode 100644 index 0000000..13d9347 --- /dev/null +++ b/build/sysroot/usr/lib/systemd/system/casaos-user-servive.service @@ -0,0 +1,13 @@ +[Unit] +After=casaos-message-bus.service +Description=CasaOS User Service + +[Service] +ExecStartPre=/usr/bin/casaos-user-service -v +ExecStart=/usr/bin/casaos-user-service -c /etc/casaos/user-service.conf +PIDFile=/var/run/casaos/user-service.pid +Restart=always +Type=notify + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/route/v1.go b/route/v1.go index e479413..f91d8f9 100644 --- a/route/v1.go +++ b/route/v1.go @@ -39,7 +39,7 @@ func InitRouter() *gin.Engine { r.POST("/v1/users/refresh", v1.PostUserRefreshToken) r.GET("/v1/users/image", v1.GetUserImage) r.GET("/v1/users/:username", v1.GetUserInfoByUsername) - r.GET("/v1/users/status", v1.GetUserStatus) // init/check + r.GET("/v1/users/status", v1.InitializedUser) //init r.POST("/v1/users/oidc/login", v1.OIDCLogin) r.GET("/v1/users/oidc/callback", v1.OIDCCallback) r.GET("/v1/users/oidc/profile", v1.OIDCProfile) diff --git a/route/v1/user.go b/route/v1/user.go index f7290e9..87497cb 100644 --- a/route/v1/user.go +++ b/route/v1/user.go @@ -14,7 +14,6 @@ import ( "io" "log" "net/http" - "net/url" url2 "net/url" "os" "path" @@ -47,16 +46,15 @@ import ( ) var ( - authServer = "http://accessmanager.local" - clientID = "6KwKSxLCtaQ4r6HoAn3gdNMbNOAf75j3SejLIAx7" - clientSecret = "PE05fcDP4qESUmyZ1TNYpZNBxRPq70VpFI81vehsoJ6WhGz5yPXMljrFrOdMRdRhrYmF03fHWTZHgO9ZdNENrLN13BzL8CAgtEkTsyjXfgx9GvISheIjYfpSfvo219fL" - authURL = "http://accessmanager.local/application/o/nextzenos-oidc/" - callbackURL = "http://nextzenos.local/v1/users/oidc/callback" - onePanelServer = "http://nextweb.local" + authServer = "https://account.nextzenvn.com" + clientID = "WzN5QB9e0LfCSAYTB542RLpIGKcAWNNZgVbeTLaz" + clientSecret = "D1mbEz1VHkPnhvMGPfj5aAmjOuZ1ZIYGm7qAReMCivdXwiQ60BJoa4cpdX5m9Z5aKgtR8d56xgmYAy7TR86MEV6zJXfjxy2lf0TTAPXc8ftEcst8fPi6B9IFe3aDBo8x" + authURL = "https://account.nextzenvn.com/application/o/nextzenos/" + callbackURL = "https://home.nextzenvn.com/v1/users/oidc/callback" + onePanelServer = "https://web.nextzenvn.com/" onePanelName = "nextzen" onePanelPassword = "Smartyourlife123@*" - onePanelEntranceCode = "nextweb" - //authentik_api_token = "jidFioAIXpgl8awyk2O17K8W7vZzlXhOO0QXGxEhMDJdn9g747EQjmaI0i3e" + onePanelEntranceCode = "" ) type OIDCSetting struct { @@ -884,7 +882,7 @@ func CheckOIDCInit() gin.HandlerFunc { return func(c *gin.Context) { if !oidcInit { log.Println("Provider is Offline") - c.JSON(http.StatusServiceUnavailable, model.Result{Success: common_err.OIDC_OFFLINE, Message: "Authentik Server is Offline"}) + //c.JSON(http.StatusServiceUnavailable, model.Result{Success: common_err.OIDC_OFFLINE, Message: "Authentik Server is Offline"}) return } c.Next() @@ -1049,18 +1047,17 @@ func OIDCValidateToken(c *gin.Context) { c.JSON(common_err.SUCCESS, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN)}) } func OIDCLogout(c *gin.Context) { - json := make(map[string]string) - c.ShouldBind(&json) - flow := "/if/flow/default-authentication-flow/" - next := "/application/o/authorize/" - - client := "client_id=" + clientID - redirect_uri := "&redirect_uri=" + url.QueryEscape(callbackURL) - response_type := "&response_type=code" - scope := "&scope=openid+profile+email+" + url.QueryEscape("goauthentik.io/api") - state := "&state=" + url.QueryEscape("/#/profile") - fullURL := authServer + flow + "?" + "next=" + url.QueryEscape(next+"?"+client+redirect_uri+response_type+scope+state) - + // json := make(map[string]string) + // c.ShouldBind(&json) + // flow := "/if/flow/default-authentication-flow/" + // next := "/application/o/authorize/" + // client := "client_id=" + clientID + // redirect_uri := "&redirect_uri=" + url.QueryEscape(callbackURL) + // response_type := "&response_type=code" + // scope := "&scope=openid+profile+email+" + url.QueryEscape("goauthentik.io/api") + // state := "&state=" + url.QueryEscape("/#/profile") + //fullURL := authServer + flow + "?" + "next=" + url.QueryEscape(next+"?"+client+redirect_uri+response_type+scope+state) + fullURL := "https://home.nextzenvn.com/outpost.goauthentik.io/sign_out" c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN), Data: fullURL}) } func OIDCProfile(c *gin.Context) { @@ -1943,7 +1940,7 @@ func DeleteUserAll(c *gin.Context) { // }) // } -func GetUserStatus(c *gin.Context) { +func InitializedUser(c *gin.Context) { data := make(map[string]interface{}, 2) key := uuid.NewV4().String() service.UserRegisterHash[key] = key