mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 20:50:19 +08:00
feat: revert "feat: Support metamask mobile login" (#2845)
This reverts commit bfa2ab63ad
.
This commit is contained in:
@ -1337,20 +1337,6 @@ class ProviderEditPage extends React.Component {
|
||||
</Row>
|
||||
) : null
|
||||
}
|
||||
{
|
||||
this.state.provider.type === "MetaMask" ? (
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
{Setting.getLabel(i18next.t("provider:Signature messages"), i18next.t("provider:Signature messages - Tooltip"))} :
|
||||
</Col>
|
||||
<Col span={22}>
|
||||
<Input value={this.state.provider.metadata} onChange={e => {
|
||||
this.updateProviderField("metadata", e.target.value);
|
||||
}} />
|
||||
</Col>
|
||||
</Row>
|
||||
) : null
|
||||
}
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
{Setting.getLabel(i18next.t("provider:Provider URL"), i18next.t("provider:Provider URL - Tooltip"))} :
|
||||
|
@ -1,107 +0,0 @@
|
||||
// Copyright 2024 The Casdoor Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import {getAuthUrl} from "./Provider";
|
||||
import {getProviderLogoURL, goToLink, showMessage} from "../Setting";
|
||||
import i18next from "i18next";
|
||||
import {
|
||||
generateNonce,
|
||||
getWeb3AuthTokenKey,
|
||||
setWeb3AuthToken
|
||||
} from "./Web3Auth";
|
||||
import {useSDK} from "@metamask/sdk-react";
|
||||
import React, {useEffect} from "react";
|
||||
|
||||
export function MetaMaskLoginButton(props) {
|
||||
const {application, web3Provider, method, width, margin} = props;
|
||||
const {sdk, chainId, account} = useSDK();
|
||||
const [typedData, setTypedData] = React.useState("");
|
||||
const [nonce, setNonce] = React.useState("");
|
||||
const [signature, setSignature] = React.useState();
|
||||
|
||||
useEffect(() => {
|
||||
if (account && signature) {
|
||||
const date = new Date();
|
||||
|
||||
const token = {
|
||||
address: account,
|
||||
nonce: nonce,
|
||||
createAt: Math.floor(date.getTime() / 1000),
|
||||
typedData: typedData,
|
||||
signature: signature,
|
||||
};
|
||||
setWeb3AuthToken(token);
|
||||
|
||||
const redirectUri = `${getAuthUrl(application, web3Provider, method)}&web3AuthTokenKey=${getWeb3AuthTokenKey(account)}`;
|
||||
goToLink(redirectUri);
|
||||
}
|
||||
}, [account, signature]);
|
||||
|
||||
const handleConnectAndSign = async() => {
|
||||
try {
|
||||
terminate();
|
||||
|
||||
const date = new Date();
|
||||
|
||||
const nonce = generateNonce();
|
||||
setNonce(nonce);
|
||||
|
||||
const prompt = web3Provider?.metadata === "" ? "Casdoor: In order to authenticate to this website, sign this request and your public address will be sent to the server in a verifiable way." : web3Provider.metadata;
|
||||
const typedData = JSON.stringify({
|
||||
domain: {
|
||||
chainId: chainId,
|
||||
name: "Casdoor",
|
||||
version: "1",
|
||||
},
|
||||
message: {
|
||||
prompt: `${prompt}`,
|
||||
nonce: nonce,
|
||||
createAt: `${date.toLocaleString()}`,
|
||||
},
|
||||
primaryType: "AuthRequest",
|
||||
types: {
|
||||
EIP712Domain: [
|
||||
{name: "name", type: "string"},
|
||||
{name: "version", type: "string"},
|
||||
{name: "chainId", type: "uint256"},
|
||||
],
|
||||
AuthRequest: [
|
||||
{name: "prompt", type: "string"},
|
||||
{name: "nonce", type: "string"},
|
||||
{name: "createAt", type: "string"},
|
||||
],
|
||||
},
|
||||
});
|
||||
setTypedData(typedData);
|
||||
|
||||
const sig = await sdk.connectAndSign({msg: typedData});
|
||||
setSignature(sig);
|
||||
} catch (err) {
|
||||
showMessage("error", `${i18next.t("login:Failed to obtain MetaMask authorization")}: ${err.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
const terminate = () => {
|
||||
sdk?.terminate();
|
||||
};
|
||||
|
||||
return (
|
||||
<a key={web3Provider.displayName} onClick={handleConnectAndSign}>
|
||||
<img width={width} height={width} src={getProviderLogoURL(web3Provider)} alt={web3Provider.displayName}
|
||||
className="provider-img" style={{margin: margin}} />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
export default MetaMaskLoginButton;
|
@ -43,8 +43,6 @@ import DouyinLoginButton from "./DouyinLoginButton";
|
||||
import LoginButton from "./LoginButton";
|
||||
import * as AuthBackend from "./AuthBackend";
|
||||
import {WechatOfficialAccountModal} from "./Util";
|
||||
import {MetaMaskProvider} from "@metamask/sdk-react";
|
||||
import MetaMaskLoginButton from "./MetaMaskLoginButton";
|
||||
|
||||
function getSigninButton(provider) {
|
||||
const text = i18next.t("login:Sign in with {type}").replace("{type}", provider.displayName !== "" ? provider.displayName : provider.type);
|
||||
@ -162,36 +160,11 @@ export function renderProviderLogo(provider, application, width, margin, size, l
|
||||
</a>
|
||||
);
|
||||
} else if (provider.category === "Web3") {
|
||||
if (provider.type === "MetaMask") {
|
||||
return (
|
||||
<MetaMaskProvider
|
||||
debug={false}
|
||||
sdkOptions={{
|
||||
communicationServerUrl: process.env.REACT_APP_COMM_SERVER_URL,
|
||||
checkInstallationImmediately: false, // This will automatically connect to MetaMask on page load
|
||||
dappMetadata: {
|
||||
name: "Casdoor",
|
||||
url: window.location.protocol + "//" + window.location.host,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<MetaMaskLoginButton
|
||||
application={application}
|
||||
web3Provider={provider}
|
||||
method={"signup"}
|
||||
width={width}
|
||||
margin={margin}
|
||||
/>
|
||||
</MetaMaskProvider>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<a key={provider.displayName} onClick={() => goToWeb3Url(application, provider, "signup")}>
|
||||
<img width={width} height={width} src={getProviderLogoURL(provider)} alt={provider.displayName}
|
||||
className="provider-img" style={{margin: margin}} />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<a key={provider.displayName} onClick={() => goToWeb3Url(application, provider, "signup")}>
|
||||
<img width={width} height={width} src={getProviderLogoURL(provider)} alt={provider.displayName} className="provider-img" style={{margin: margin}} />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
} else if (provider.type === "Custom") {
|
||||
// style definition
|
||||
|
Reference in New Issue
Block a user