mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-16 23:13:50 +08:00
feat: support google one tap signin (#2131)
* feat: add google one tap support * feat: gofumpt * feat: add google provider rule conf * feat: update i18n
This commit is contained in:
@ -14,6 +14,9 @@
|
||||
|
||||
import {createButton} from "react-social-login-buttons";
|
||||
import {StaticBaseUrl} from "../Setting";
|
||||
import {useGoogleOneTapLogin} from "react-google-one-tap-login";
|
||||
import * as Setting from "../Setting";
|
||||
import * as Provider from "./Provider";
|
||||
|
||||
function Icon({width = 24, height = 24, color}) {
|
||||
return <img src={`${StaticBaseUrl}/buttons/google.svg`} alt="Sign in with Google" />;
|
||||
@ -29,4 +32,29 @@ const config = {
|
||||
|
||||
const GoogleLoginButton = createButton(config);
|
||||
|
||||
export function GoogleOneTapLoginVirtualButton(prop) {
|
||||
const application = prop.application;
|
||||
const providerConf = prop.providerConf;
|
||||
// https://stackoverflow.com/questions/62281579/google-one-tap-sign-in-ui-not-displayed-after-clicking-the-close-button
|
||||
// document.cookie = "g_state=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT";
|
||||
useGoogleOneTapLogin({
|
||||
googleAccountConfigs: {
|
||||
client_id: providerConf.provider.clientId,
|
||||
},
|
||||
onError: (error) => {
|
||||
Setting.showMessage("error", error);
|
||||
},
|
||||
onSuccess: (response) => {
|
||||
const code = "GoogleIdToken-" + JSON.stringify(response);
|
||||
const authUrlParams = new URLSearchParams(Provider.getAuthUrl(application, providerConf.provider, "signup"));
|
||||
const state = authUrlParams.get("state");
|
||||
let redirectUri = authUrlParams.get("redirect_uri");
|
||||
redirectUri = `${redirectUri}?state=${state}&code=${encodeURIComponent(code)}`;
|
||||
Setting.goToLink(redirectUri);
|
||||
},
|
||||
disableCancelOnUnmount: true,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export default GoogleLoginButton;
|
||||
|
Reference in New Issue
Block a user