Skip to content

Commit

Permalink
feat: add redirect support for social auth provider (#4063)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/area console
/kind feature
/milestone 2.7.x

#### What this PR does / why we need it:

三方登录时支持传入 `login_redirect_uri` 参数,以让三方登录提供方支持适配登录后重定向到具体页面的功能。

#### Which issue(s) this PR fixes:

Fixes #4029

#### Special notes for your reviewer:

测试方式:

1. 可以使用 halo-sigs/plugin-oauth2#33 进行测试。
2. 手动在登录页面构造如 https://127.0.0.1:8090/console/login?redirect_uri=/ 的地址,观察使用三方登录之后是否会跳转到指定页面。

#### Does this PR introduce a user-facing change?

```release-note
Console 端三方登录支持重定向参数。
```
  • Loading branch information
ruibaby authored Jun 26, 2023
1 parent c39691d commit e13beb4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion console/src/components/login/SocialAuthProviderItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts" setup>
import type { SocialAuthProvider } from "@/modules/system/actuator/types";
import { useRouteQuery } from "@vueuse/router";
import { inject, ref } from "vue";
import type { Ref } from "vue";
Expand All @@ -10,8 +11,11 @@ const props = withDefaults(
{}
);
const REDIRECT_URI_QUERY_PARAM = "login_redirect_uri";
const loading = ref(false);
const redirect_uri = useRouteQuery<string>("redirect_uri", "");
const disabled = inject<Ref<boolean>>("disabled");
function handleSocialLogin() {
Expand All @@ -20,7 +24,14 @@ function handleSocialLogin() {
}
loading.value = true;
window.location.href = props.authProvider.authenticationUrl;
let authenticationUrl = props.authProvider.authenticationUrl;
if (redirect_uri.value) {
authenticationUrl = `${authenticationUrl}?${REDIRECT_URI_QUERY_PARAM}=${redirect_uri.value}`;
}
window.location.href = authenticationUrl;
}
</script>

Expand Down

0 comments on commit e13beb4

Please sign in to comment.