diff --git a/README.md b/README.md index 857fb53..cec6cba 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ - 登录 - 地址簿 - 群组 - - 授权登录,支持`github`和`google`登录,支持`web后台`授权登录 + - 授权登录,支持`github`, `google` 和 `OIDC` 登录,支持`web后台`授权登录 - i18n - Web Admin - 用户管理 @@ -92,7 +92,7 @@ #### 登录 -- 添加了`github`和`google`授权登录,需要在后台配置好就可以用了,具体可看后台OAuth配置 +- 添加了`github`, `google` 以及`OIDC`授权登录,需要在后台配置好就可以用了,具体可看后台OAuth配置 - 添加了web后台授权登录,点击后直接登录后台就自动登录客户端了 ![pc_login](docs/pc_login.png) @@ -124,8 +124,10 @@ 4. 可以直接打开webclient,方便使用;也可以分享给游客,游客可以直接通过webclient远程到设备 ![web_webclient](docs/admin_webclient.png) -5. Oauth,暂时只支持了`Github`和`Google`, 需要创建一个`OAuth App`,然后配置到后台 +5. Oauth,支持了`Github`, `Google` 以及 `OIDC`, 需要创建一个`OAuth App`,然后配置到后台 ![web_admin_oauth](docs/web_admin_oauth.png) + - 对于`Google` 和 `Github`, `Issuer` 和 `Scopes`不需要填写. + - 对于`OIDC`, `Issuer`是必须的。`Scopes`是可选的,默认为 `openid,profile,email`. 确保可以获取 `sub`,`email` 和`preferred_username` - `github oauth app`在`Settings`->`Developer settings`->`OAuth Apps`->`New OAuth App` 中创建,地址 [https://github.com/settings/developers](https://github.com/settings/developers) - `Authorization callback URL`填写`http:///api/oauth/callback` diff --git a/README_EN.md b/README_EN.md index c1a6e64..35d116e 100644 --- a/README_EN.md +++ b/README_EN.md @@ -18,7 +18,7 @@ desktop software that provides self-hosted solutions. - Login - Address Book - Groups - - Authorized login, supports `GitHub` and `Google` login, supports `web admin` authorized login + - Authorized login, supports `GitHub`, `Google` and `OIDC` login, supports `web admin` authorized login - i18n - Web Admin - User Management @@ -93,7 +93,7 @@ Basic implementation of the PC client's primary interfaces.Supports the Personal #### Login -- Added `GitHub` and `Google` login, which can be used after configuration in the admin panel. See the OAuth +- Added `GitHub`, `Google` and `OIDC` login, which can be used after configuration in the admin panel. See the OAuth configuration section for details. - Added authorization login for the web admin panel. @@ -128,9 +128,11 @@ installation are `admin` `admin`, please change the password immediately. 4. You can directly launch the client or open the web client for convenience; you can also share it with guests, who can remotely access the device via the web client. ![web_webclient](docs/en_img/admin_webclient.png) -5. OAuth support: Currently, `GitHub` and `Google` is supported. You need to create an `OAuth App` and configure it in +5. OAuth support: Currently, `GitHub`, `Google` and `OIDC` are supported. You need to create an `OAuth App` and configure it in the admin panel. ![web_admin_oauth](docs/en_img/web_admin_oauth.png) + - For `Google` and `Github`, you don't need to fill the `Issuer` and `Scpoes` + - For `OIDC`, you must set the `Issuer`. And `Scopes` is optional which default is `openid,email,profile`, please make sure this `Oauth App` can access `sub`, `email` and `preferred_username` - Create a `GitHub OAuth App` at `Settings` -> `Developer settings` -> `OAuth Apps` -> `New OAuth App` [here](https://github.com/settings/developers). - Set the `Authorization callback URL` to `http:///api/oauth/callback`, diff --git a/docs/en_img/web_admin_oauth.png b/docs/en_img/web_admin_oauth.png index 5591167..0419456 100644 Binary files a/docs/en_img/web_admin_oauth.png and b/docs/en_img/web_admin_oauth.png differ diff --git a/docs/web_admin_oauth.png b/docs/web_admin_oauth.png index 6c640dd..8f960ef 100644 Binary files a/docs/web_admin_oauth.png and b/docs/web_admin_oauth.png differ diff --git a/service/oauth.go b/service/oauth.go index 17a3120..e9f4fe7 100644 --- a/service/oauth.go +++ b/service/oauth.go @@ -441,6 +441,12 @@ func (os *OauthService) UnBindThird(thirdType string, userid uint) error { return global.DB.Where("user_id = ? and third_type = ?", userid, thirdType).Delete(&model.UserThird{}).Error } +// DeleteUserByUserId: When user is deleted, delete all third party bindings +func (os *OauthService) DeleteUserByUserId(userid uint) error { + return global.DB.Where("user_id = ?", userid).Delete(&model.UserThird{}).Error +} + + // InfoById 根据id取用户信息 func (os *OauthService) InfoById(id uint) *model.Oauth { u := &model.Oauth{} diff --git a/service/user.go b/service/user.go index 75fb653..6bb431f 100644 --- a/service/user.go +++ b/service/user.go @@ -148,8 +148,18 @@ func (us *UserService) Create(u *model.User) error { func (us *UserService) Logout(u *model.User, token string) error { return global.DB.Where("user_id = ? and token = ?", u.Id, token).Delete(&model.UserToken{}).Error } + +// Delete 删除用户和oauth信息 func (us *UserService) Delete(u *model.User) error { - return global.DB.Delete(u).Error + // 删除用户 + if err := global.DB.Delete(u).Error; err != nil { + return err + } + // 删除关联的 OAuth 信息 + if err := AllService.OauthService.DeleteUserByUserId(u.Id); err != nil { + return err + } + return nil } // Update 更新