All Projects → okayrunner → spring-security-passwordless

okayrunner / spring-security-passwordless

Licence: Apache-2.0 License
Passwordless authentication example application using Spring Boot and Spring Security

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects
Batchfile
5799 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to spring-security-passwordless

webauthn-demo
WebAuthn demo with Ionic/Angular and Spring Boot
Stars: ✭ 22 (-80.36%)
Mutual labels:  springboot, springsecurity, passwordless-login
SpringSecurity-JWT-Vue-Deom
A demonstration of stateless JWT authentication with Spring Security, Spring Boot and Vue js
Stars: ✭ 99 (-11.61%)
Mutual labels:  springboot, springsecurity
Shopizer
Shopizer java e-commerce software
Stars: ✭ 2,541 (+2168.75%)
Mutual labels:  springboot, apache2
Piper
piper - a distributed workflow engine
Stars: ✭ 374 (+233.93%)
Mutual labels:  springboot, apache2
HumanResources
Account Registration and Confirmation. Exception Handling. Caching with Redis.Mail sender by Apache Kafka.Notification send with RabbitMq.
Stars: ✭ 19 (-83.04%)
Mutual labels:  springboot, springsecurity
NBlog
🍓 Spring Boot + Vue 前后端分离博客系统 https://naccl.top
Stars: ✭ 700 (+525%)
Mutual labels:  springboot, springsecurity
coupons
淘宝客项目,支持App,微信小程序,QQ小程序
Stars: ✭ 392 (+250%)
Mutual labels:  springboot, springsecurity
springboot-chapter
🚀Spring Boot 2.0基础教程。主流框架整合,实践学习案例。
Stars: ✭ 23 (-79.46%)
Mutual labels:  springboot, springsecurity
NeusoftCloudHospital
东软云医院。爱与健康,连接你我。🏥
Stars: ✭ 37 (-66.96%)
Mutual labels:  springboot
agile-wroking-backend
AgileWorking 是一个团队协作的微信小程序,此工程为小程序的后台实现
Stars: ✭ 67 (-40.18%)
Mutual labels:  springboot
SpringBootExploit
项目是根据LandGrey/SpringBootVulExploit清单编写,目的hvv期间快速利用漏洞、降低漏洞利用门槛。
Stars: ✭ 1,060 (+846.43%)
Mutual labels:  springboot
file management sys
file_management_sys 是一个文件共享系统,包括前端文件展示系统和后台管理系统,基于SpringBoot + MyBatis实现。前端文件展示系统包括文件分类和展示界面,文件搜索和文件上传等模块。后台管理系统包含文件管理,权限管理等模块。
Stars: ✭ 60 (-46.43%)
Mutual labels:  springboot
mzt-biz-log
支持Springboot,基于注解的可使用变量、可以自定义函数的通用操作日志组件
Stars: ✭ 628 (+460.71%)
Mutual labels:  springboot
BookRecommenderSystem
基于大数据的图书推荐系统
Stars: ✭ 30 (-73.21%)
Mutual labels:  springboot
aliyun-sms
阿里云 SMS 短信 Java SDK 封装
Stars: ✭ 67 (-40.18%)
Mutual labels:  springboot
shield-ratelimter
基于Redis的分布式限流组件,注解支持
Stars: ✭ 123 (+9.82%)
Mutual labels:  springboot
seckill parent
基于springboot+springcloud的高并发和商品秒杀项目,通过redis,rabbitmq等技术实现秒杀的高并发。
Stars: ✭ 59 (-47.32%)
Mutual labels:  springboot
active4j
Active4j-boot是基于SpingBoot2.0轻量级的java快速开发框架。以Spring Framework为核心容器,Spring MVC为模型视图控制器,Mybatis Plus为数据访问层, Apache Shiro为权限授权层, Redis为分布式缓存,Quartz为分布式集群调度,layui作为前端框架并进行前后端分离的开源框架
Stars: ✭ 32 (-71.43%)
Mutual labels:  springboot
netty-learning
bio, nio到 netty各种使用案例, 包含基础使用案例,各api使用方法,零拷贝,websocket,群聊,私聊,编码,解码,自定义协议,protobuf等使用案例,rpc服务器,客户端等等学习
Stars: ✭ 49 (-56.25%)
Mutual labels:  springboot
learn-java-demo
java学习demo
Stars: ✭ 17 (-84.82%)
Mutual labels:  springboot

Introduction

We all have a love/hate relationship with passwords. They protect our most valuable assets but they are so god damn hard to create and remember.

And just to make things even harder for us humans, more and more companies are now enforcing two factor authentication (you know, the little phone pincode thing) to make it even more complicated to login to our accounts.

Despite advances in biometric authentication (fingerprint, face recognition etc.), passwords still remain the most ubiqutous form of authentication.

So what can we do to help our fellow users to access our application in an easier manner but without compromising security?

This is where passwordless login comes in.

How does it work?

If you ever went to a website, realized you forgot your password and then used their "Forgot Password" then you know what passwordless login is.

After you entered your email address on the Reset Password page you were sent a "magic" link with a special code (a.k.a "token") embedded in it which provided you with the ability to reset your password.

That website piggy-backed on your already-password-protected email address to create a secure, one-time-password "magic" link to your account.

Well, if we can do all that in a presumably safe way when the user loses his password why can't we do it whenever a user wants to login? Sure we can.

Oh, and just in case you're wondering some big name (Slack, Medium.com, Twitter) companies are already using this method of authentication.

Alright, let's get down to business then.

The nitty gritty

  1. Create a sign-up/sign-in page. It basically needs only one field: email.
<input type="email" name="email" class="form-control" placeholder="Email address" required autofocus>
  1. Create an endpoint to handle the form submission:
  private final TokenStore tokenStore;
  private final Sender sender;

  @PostMapping("/signin")
  public String signin (@RequestParam("email") String aEmail) {
    
    // verify that the user is in the database.
    // ...
    
    // create a one-time login token
    String token = tokenStore.create(aEmail);
    
    // send the token to the user as a "magic" link
    sender.send(aEmail, token);
    
    return "login_link_sent";
  }
  1. Create an endpoint to authenticate the user based on the "magic" link:
  private final Authenticator authenticator;

  @GetMapping("/signin/{token}")
  public String signin (@RequestParam("uid") String aUid, @PathVariable("token") String aToken) {
    try {
      authenticator.authenticate(aUid, aToken);
      return "redirect:/";
    }
    catch (BadCredentialsException aBadCredentialsException) {
      return "invalid_login_link";
    }
  }

And that's about it.

Securing the "magic" link.

There are few precautions you should take to keep the "magic" link as secure as possible:

  1. When sending the link to the user communicate to your email server over SSL.

  2. Tokens should only be usable once.

  3. Tokens should not be easily guessable. Use a good, cryptographically strong random number generator. e.g:

    SecureRandom random = new SecureRandom();
    byte bytes[] = new byte[TOKEN_BYTE_SIZE];
    random.nextBytes(bytes);
    String token = String.valueOf(Hex.encode(bytes));
  1. Tokens should expire after a reasonable amount of time (say 15 minutes). In this example I use an in-memory TokenStore implementation backed by a SelfExpringHashMap which as its name suggests expires entries after a given amount of time. In a real-world scenario you will most likely use a database to store your generated tokens so your website can run on more than one machine and so these tokens survive a crash. But the principle is the same. You can have a created_at field which stamps the time the token was created so you can determine if it expired or not.

Running the demo

  1. Clone the repo:
git clone https://github.com/creactiviti/spring-security-passwordless.git
  1. Build
mvn clean spring-boot:run -Dspring.mail.host=<SMTP HOST> -Dspring.mail.username=<SMTP USERNAME> -Dspring.mail.password=<SMTP PASSWORD> -Dpasswordless.email.from=<SENDER EMAIL ADDRESS>
  1. Sign-in

Go to http://localhost:8080/signin

License

Apache License version 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].