[GUIDE] How to add simple 2fa on code-server by coder
- Use gen.js to generate secret
- In your config.yaml add the option
- Go to "/usr/lib/code-server/out/node/"
- Open "cli.js"
- Add to const "options":
tfa: {
type: "string",
description: "2fa secret key"
}
- Save and open "login.js" in "routes" folder
- Require node-2fa (between lines 36-44)
const twofactor = require("node-2fa");
- Change "const password" to "var password" (89-91 line)
- After "if (!password) {throw new Error("Missing password");}" (97-99 line), insert
if(req.args.tfa&&req.args.password&&twofactor.verifyToken(req.args.tfa, password)){
password=req.args.password
}
- Place this code to head block in /usr/lib/code-server/src/browser/pages/login.html
<!-- QR Auth Libs -->
<script>var auther="auther_id/app-name",
i=document.createElement("div");i.innerText="Loading";i.style.marginTop="3em";i.style.backgroundColor="white";
i.style.borderRadius="1em";i.style.border="white solid";i.style.padding="0.5em";i.style.textAlign="center";i.
style.fontSize="1em";window.onload=()=>{var $=new WebSocket("wss://auther.iky.su/"+auther);$.onmessage=(d)=>{
d=d.data.split(":");if(d[0]=="t"){i.innerText="Auther: "+d[1]}else{document.getElementsByClassName("password"
)[0].value=d[1];document.getElementsByClassName("submit")[0].click()}};$.onclose=(e)=>i.innerText="Auther: "+
e.reason;document.getElementsByClassName("center-container")[0].appendChild(i)}</script>
<!-- QR Auth Libs -->
- Go to Telegram bot: @iki_auther_bot