gpt4 book ai didi

authentication - 在Grails应用程序中针对TOTP或其他多因素身份验证的完美解决方案?

转载 作者:行者123 更新时间:2023-12-02 14:41:30 32 4
gpt4 key购买 nike

我很惊讶地发现Grails中没有明显的插件或设置来启用任何类型的多因素身份验证。是否有一个优雅的解决方案?理想情况下,我想实现一个TOTP解决方案,以与Google Authenticator或独立的Fob等应用一起使用,但同时也会考虑基于文本消息的解决方案。

该解决方案必须能够很好地与内置的Spring Security身份验证配合使用并对其进行扩展。

最佳答案

我在构建的Web应用程序中做了类似的操作。我找不到比纯插件更干净的东西,但是我仍然能够将其与Spring Security集成在一起。

所以基本上我最终要做的是使用authy api(http://docs.authy.com/,我相信您可以找到与google auth类似的东西)来进行TOTP交付和验证。首次登录后,我向他们授予ROLE_PRE_AUTH的权限,然后将它们发送到 protected 页面以处理TOTP。然后我用

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(auth.getAuthorities());
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
Authentication newAuth = new UsernamePasswordAuthenticationToken(auth.getPrincipal(), auth.getCredentials(), authorities);
SecurityContextHolder.getContext().setAuthentication(newAuth);

一旦我确认(再次使用可用的api)用户具有有效的TOTP,即可更新用户的角色。因此,基本上,您想创建一个类来进行此验证,并且只有在该类运行后,您才需要导航到下一页(他们现在有权访问)

关于authentication - 在Grails应用程序中针对TOTP或其他多因素身份验证的完美解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32980042/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com