ccagml / leetcode-extension

Solved LeetCode problem in VS Code added some new features
https://marketplace.visualstudio.com/items?itemName=ccagml.vscode-leetcode-problem-rating
MIT License
246 stars 27 forks source link

为Github登录增加2FA或者Token登录 #258

Closed sgrtye closed 8 months ago

sgrtye commented 8 months ago

🐛 Bug Report(错误报告)

因Github在今年全面强制添加了Two-factor authentication,但现行的登录方法并不能很好的支持Github登录。

To Reproduce(重现)

选择Github登录,输入用户名和密码(配置了双重身份验证的账户)

Expected behavior(预期行为)

弹出第三个为Authentication code的prompt。 或者添加使用Tokens登录的选项。

Extension Output(扩展输出)

login: login: pass: pass: {"code":-5,"msg":"Login failed. Please make sure the credential is correct."} {"code":-5,"msg":"Login failed. Please make sure the credential is correct."}

Your Environment

sgrtye commented 8 months ago

我找到Github登录方法是在中leetcode-extension/src/rpc/actionChain/chainNode/leetcode.ts实现的 在githubLogin function中实现了有关Two-factor authentication的验证 但是仍然不可以正确登录 可能是api有所更改?

ccagml commented 8 months ago

我没用过github登录这个流程,原本有的Two-factor authentication 就是原来官方插件的登录流程, api有没有更改就不清楚了,官方的那个插件能用github登录吗?

sgrtye commented 8 months ago

官方的插件现在也不可以了 是否有渠道私聊一下?

现在官方插件也是 [ERROR] Login Failed. Please make sure the credential is correct.

我可能找到了问题 但是我不太用JS或者TS 是否能加个联系方式我把东西发给你

ccagml commented 8 months ago

找到什么问题吗?看起来这个错误是跳转的地址跟配置写死的地址对不上的样子

sgrtye commented 8 months ago

是的 现在默认的是github_tf_session_request: "https://github.com/sessions/two-factor"

但是新的会根据你Preferred 2FA method不同跳转 如果默认是Authenticator app 那么网址会是 https://github.com/sessions/two-factor/app 如果默认是SMS/Text message 那么网址是https://github.com/sessions/two-factor/sms/confirm 使用短信验证的网址是确认发送的页面 还需要确认发送先才能输入OTP 剩下的两种Security keys和GitHub Mobile不知道验证步骤

sgrtye commented 8 months ago

刚才试了下Github Mobile的链接是https://github.com/sessions/two-factor/mobile

然后会让用户在手机软件中输入验证码授权登陆

WX20231030-015540@2x

sgrtye commented 8 months ago

除掉Security keys需要实体密钥验证 暂时不知道如何使用 然后使用Recovery code登陆有点离谱可以忽略

剩下三种是可以通过三个链接分别打开的 所以可以直接match链接头部是否是 ’https://github.com/sessions/two-factor‘ 然后添加prompt让用户自选三种验证方法? 或者在网页中读取 网页下方会列出所有其余的可供验证的方法 然后汇总给用户选择

然后访问不能使用的验证链接会redirect到默认的认证方式。 比如我revoke了所有的github mobile session之后 如果我登陆时尝试访问 ’https://github.com/sessions/two-factor/mobile‘ ,会直接redirect到 ‘https://github.com/sessions/two-factor/app’ 也就是我的默认验证方式。

ccagml commented 8 months ago

昨天看了一下,看起来不仅是这个选择的4中方式变了,我试了/app的操作后续解析cookie也解不出来了,会缺少内容

sgrtye commented 8 months ago

昨天看了一下,看起来不仅是这个选择的4中方式变了,我试了/app的操作后续解析cookie也解不出来了,会缺少内容

我提交了一个PR, 我把==改成startswith了 这样不管默认是哪种2FA都能过上面对于github_tf_redirect的检查

但是如果默认不是Authenticator app的话后续操作会出问题

SMS和Github Mobile的支持也可以添加 但是比较复杂。 SMS只需要多点一步确认发送验证码就好了 Github Mobile需要读取验证码 然后返回给用户在手机操作 然后等待github自动跳转

ccagml commented 8 months ago

你那个提交,你可以登录了?我的还是不能登录,就是我上面说的,解析cookie会缺少字段

sgrtye commented 8 months ago

你那个提交,你可以登录了?我的还是不能登录,就是我上面说的,解析cookie会缺少字段

我可以登陆了。 在之前 连跳出2FA的页面都不会有 但是修改了之后可以正确跳出2FA的prompt 然后我可以正常登录了

另外我最后没有写死/app 直接是默认的 "https://github.com/sessions/two-factor" 让它自动跳转 这样肯定不会影响之前的functionality

ccagml commented 8 months ago

好的,感谢,3.1.4发布了

sgrtye commented 8 months ago

好的,感谢,3.1.4发布了

多谢 我刚才测试了最新的版本 已经可以正常通过Authenticator app的2FA登陆了。 我现在就把这个comment关闭了,同时你可以在readme里写一下现在Github login如果需要2FA的话只可以使用Authenticator app并且perferred 2FA必须是Authenticator app。