Skip to content

Commit c5ce41f

Browse files
perf(X-Pack): Optimize the OAuth2 Logout Flow
1 parent 7cfca5a commit c5ce41f

File tree

7 files changed

+23
-2
lines changed

7 files changed

+23
-2
lines changed

backend/common/core/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TokenPayload(BaseModel):
1414
class Token(SQLModel):
1515
access_token: str
1616
token_type: str = "bearer"
17+
platform_info: Optional[dict] = None
1718

1819
class XOAuth2PasswordBearer(OAuth2PasswordBearer):
1920
async def __call__(self, request: Request) -> Optional[str]:

frontend/src/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@
718718
"client_id": "Client ID",
719719
"client_secret": "Client Secret",
720720
"redirect_url": "Redirect URL",
721+
"logout_redirect_url": "Logout Redirect URL",
722+
"logout_redirect_url_placeholder": "By default, users will be redirected to the SQLBot login page after logout. You can customize the redirect address here.",
721723
"oauth2_settings": "OAuth2 Settings",
722724
"scope": "Scope",
723725
"userinfo_url": "User Info URL",

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@
718718
"client_id": "클라이언트 ID",
719719
"client_secret": "클라이언트 시크릿",
720720
"redirect_url": "리디렉션 URL",
721+
"logout_redirect_url": "로그아웃 후 리디렉션 URL",
722+
"logout_redirect_url_placeholder": "기본적으로 로그아웃 후 SQLBot 로그인 페이지로 이동합니다. 여기서 리디렉션 주소를 사용자 지정할 수 있습니다.",
721723
"oauth2_settings": "OAuth2 설정",
722724
"scope": "권한 범위",
723725
"userinfo_url": "사용자 정보 URL",

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@
718718
"client_id": "客户端 ID",
719719
"client_secret": "客户端密钥",
720720
"redirect_url": "回调地址",
721+
"logout_redirect_url": "注销回调地址",
722+
"logout_redirect_url_placeholder": "注销后默认跳转至 SQLBot 登录页面,可自定义设置注销后跳转地址",
721723
"oauth2_settings": "OAuth2 设置",
722724
"scope": "授权范围",
723725
"userinfo_url": "用户信息地址",

frontend/src/stores/user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AuthApi } from '@/api/login'
44
import { useCache } from '@/utils/useCache'
55
import { i18n } from '@/i18n'
66
import { store } from './index'
7+
import { getQueryString } from '@/utils/utils'
78

89
const { wsCache } = useCache()
910

@@ -91,6 +92,11 @@ export const UserStore = defineStore('user', {
9192
window.location.href = res
9293
window.open(res, '_self')
9394
}
95+
if (getQueryString('code') && getQueryString('state')?.includes('oauth2_state')) {
96+
const logout_url = location.origin + location.pathname + '#/login'
97+
window.location.href = logout_url
98+
window.open(res, logout_url)
99+
}
94100
},
95101

96102
async info() {

frontend/src/views/login/xpack/Handler.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ const oauth2Login = () => {
220220
.post('/system/authentication/sso/4', urlParams)
221221
.then((res: any) => {
222222
const token = res.access_token
223-
const id_token = res.id_token
223+
const platform_info = res.platform_info
224224
if (token && isPlatformClient()) {
225225
wsCache.set('de-platform-client', true)
226226
}
@@ -229,7 +229,7 @@ const oauth2Login = () => {
229229
userStore.setTime(Date.now())
230230
userStore.setPlatformInfo({
231231
flag: 'oauth2',
232-
data: id_token,
232+
data: platform_info ? JSON.stringify(platform_info) : '',
233233
origin: 4,
234234
})
235235
const queryRedirectPath = getCurLocation()

frontend/src/views/system/authentication/Oauth2Editor.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const state = reactive({
2727
client_id: '',
2828
client_secret: '',
2929
redirect_url: '',
30+
logout_redirect_url: '',
3031
mapping: '',
3132
}),
3233
})
@@ -345,6 +346,13 @@ onBeforeMount(() => {
345346
<el-input v-model="state.form.redirect_url" :placeholder="t('common.please_input')" />
346347
</el-form-item>
347348

349+
<el-form-item :label="t('authentication.logout_redirect_url')" prop="logout_redirect_url">
350+
<el-input
351+
v-model="state.form.logout_redirect_url"
352+
:placeholder="t('authentication.logout_redirect_url_placeholder')"
353+
/>
354+
</el-form-item>
355+
348356
<el-form-item :label="t('authentication.field_mapping')" prop="mapping">
349357
<el-input
350358
v-model="state.form.mapping"

0 commit comments

Comments
 (0)