Skip to content

hedza06/spring-boot-otp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot OTP (One time password authentication)

Spring Boot project with demonstration of OTP authentication technique.

Running the project

  1. Create database with name otp
  2. Open terminal and navigate to your project
  3. Type command mvn install
  4. Type command mvn spring-boot:run

Check application running state

Route: http://localhost:8080/

Available profiles

  • Development profile (dev)
  • Production profile (prod)

Authentication

Route: /auth/authenticate
Method: POST
Content-Type: application/json
Request payload: { username: "admin", password: "admin" }
Response: { id_token: "token_hash" }

OTP routes that you can called after getting access token

  1. Generate OTP and send it to e-mail
    Route: /api/otp/generate
    Method: POST
    Empty request body in this case.

  2. Validate OTP
    Route: /api/otp/validate
    Method: POST
    Example Request Payload: { "otp": "your otp number" }


Packaging for production

  1. mvn clean
  2. mvn -Pprod package

Changes - Important

15.07.2022.

  • Removed OTPResourceController. All Otp logic is processed in AuthenticationController
  • Added new column in user table -> is_otp_required
  • Modified TokenProvided to support logic that first check if otp is required. If OTP is not needed token will be generated instantly, but if OTP is required token will not be provided to end user (client), email will be sent with OTP code
  • OTP can be verified used /auth/verify route in AuthenticationController

Author

Heril Muratović
Software Engineer

Mobile: +38269657962
E-mail: hedzaprog@gmail.com
Skype: hedza06
Twitter: hedzakirk
LinkedIn: https://www.linkedin.com/in/heril-muratovi%C4%87-021097132/
StackOverflow: https://stackoverflow.com/users/4078505/heril-muratovic