PR #11883 - changes from review
Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
This commit is contained in:
parent
2f668353ac
commit
44286feae6
|
@ -313,8 +313,6 @@ public abstract class SecurityHandler extends Handler.Wrapper implements Configu
|
||||||
protected void doStart()
|
protected void doStart()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Context context1 = ContextHandler.getCurrentContext();
|
|
||||||
|
|
||||||
// complicated resolution of login and identity service to handle
|
// complicated resolution of login and identity service to handle
|
||||||
// many different ways these can be constructed and injected.
|
// many different ways these can be constructed and injected.
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,15 @@
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import org.eclipse.jetty.security.Authenticator;
|
||||||
|
import org.eclipse.jetty.security.siwe.EthereumAuthenticatorFactory;
|
||||||
|
|
||||||
module org.eclipse.jetty.siwe
|
module org.eclipse.jetty.siwe
|
||||||
{
|
{
|
||||||
requires transitive org.eclipse.jetty.security;
|
requires transitive org.eclipse.jetty.security;
|
||||||
requires org.bouncycastle.provider;
|
requires org.bouncycastle.provider;
|
||||||
|
|
||||||
exports org.eclipse.jetty.security.siwe;
|
exports org.eclipse.jetty.security.siwe;
|
||||||
|
|
||||||
|
provides Authenticator.Factory with EthereumAuthenticatorFactory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -559,8 +559,6 @@ public class EthereumAuthenticator extends LoginAuthenticator implements Dumpabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: verify the sessionID is obtained from a cookie.
|
|
||||||
|
|
||||||
if (isNonceRequest(uri))
|
if (isNonceRequest(uri))
|
||||||
return handleNonceRequest(request, response, callback);
|
return handleNonceRequest(request, response, callback);
|
||||||
if (isAuthenticationRequest(uri))
|
if (isAuthenticationRequest(uri))
|
||||||
|
|
|
@ -89,7 +89,6 @@ public class SignInWithEthereumEmbeddedExample
|
||||||
|
|
||||||
server.setHandler(contextHandler);
|
server.setHandler(contextHandler);
|
||||||
server.start();
|
server.start();
|
||||||
System.err.println(resourceHandler.getBaseResource());
|
|
||||||
server.join();
|
server.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Sign-In with Ethereum</title>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/web3@1.6.1/dist/web3.min.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h4>Sign-In with Ethereum</h4>
|
|
||||||
<button id="siwe">Sign-In with Ethereum</button>
|
|
||||||
<form id="loginForm" action="/auth/login" method="POST" style="display: none;">
|
|
||||||
<input type="hidden" id="signatureField" name="signature">
|
|
||||||
<input type="hidden" id="messageField" name="message">
|
|
||||||
</form>
|
|
||||||
<p class="alert" style="display: none;">Result: <span id="siweResult"></span></p>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
let provider = window.ethereum;
|
|
||||||
let accounts;
|
|
||||||
|
|
||||||
if (!provider) {
|
|
||||||
document.getElementById('siweResult').innerText = 'MetaMask is not installed. Please install MetaMask to use this feature.';
|
|
||||||
} else {
|
|
||||||
document.getElementById('siwe').addEventListener('click', async () => {
|
|
||||||
try {
|
|
||||||
// Request account access if needed
|
|
||||||
accounts = await provider.request({ method: 'eth_requestAccounts' });
|
|
||||||
const domain = window.location.host;
|
|
||||||
const from = accounts[0];
|
|
||||||
|
|
||||||
// Fetch nonce from the server
|
|
||||||
const nonceResponse = await fetch('/auth/nonce');
|
|
||||||
const nonceData = await nonceResponse.json();
|
|
||||||
const nonce = nonceData.nonce;
|
|
||||||
|
|
||||||
const siweMessage = `${domain} wants you to sign in with your Ethereum account:\n${from}\n\nI accept the MetaMask Terms of Service: https://community.metamask.io/tos\n\nURI: https://${domain}\nVersion: 1\nChain ID: 1\nNonce: ${nonce}\nIssued At: ${new Date().toISOString()}`;
|
|
||||||
const signature = await provider.request({
|
|
||||||
method: 'personal_sign',
|
|
||||||
params: [siweMessage, from]
|
|
||||||
});
|
|
||||||
console.log("signature: " + signature)
|
|
||||||
console.log("nonce: " + nonce)
|
|
||||||
console.log("length: " + length)
|
|
||||||
console.log("siweMessage: " + siweMessage)
|
|
||||||
|
|
||||||
document.getElementById('signatureField').value = signature;
|
|
||||||
document.getElementById('messageField').value = siweMessage;
|
|
||||||
document.getElementById('loginForm').submit();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error during login:', error);
|
|
||||||
document.getElementById('siweResult').innerText = `Error: ${error.message}`;
|
|
||||||
document.getElementById('siweResult').parentElement.style.display = 'block';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue