Skip to content

yahya077/otp-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

otp-golang

This is an OTP Auth package for GOLang.

Screen Shot 2022-11-08 at 22 44 13

⭐️ This package is still in development. I welcome suggestions for changes that will bring it closer to compliance without overly complicating the code, or useful test cases to add to the test suite.

⚡️ Quick Start

go get -u github.com/yahya077/otp-golang

📖 Prebuild Handlers

Note: There is an available documentation with Postman API Documentation

Title Route Method Handler Middleware Customizable Description
OTP /auth/otp POST OtpHandler none Sends OTP to user
Login /auth/login POST LoginHandler none Returns Bearer token
Register /auth/register POST RegisterHandler AuthMiddleware Registers user by User Repository
Get User Model /auth/user GET GetUserHandler AuthMiddleware Gets user by User Repository

💡 Usage

Note: Example usage on otp-golang-example

// create instance off Auth
authApp := auth.New(app, database.Postgresql.DB, auth.Config{})

// set sms provider for sending otp code to phone number
authApp.SetSmsProvider(smsProvider.MockedSmsSenderProviderClient{})

// set your custom user model as a subject for verify, insert and register
authApp.SetUserRepository(repository.UserRepository{})

// finally initialize the auth app
authApp.Initialize()

// You can use middleware as shown below
app.Get("/test-auth", authApp.Config.AuthMiddleware, func(ctx *fiber.Ctx) error {
		return ctx.JSON("authorized")
})
  

🧬 Auth Middleware

This middleware will be ready after initialization of Auth. You can override Middleware if you want to

Middleware Description
authApp.Config.AuthMiddleware Looks for Bearer token

📫  Have a question? Want to chat? Ran into a problem?

LinkedIn Account

About

This is an OTP package for GOLang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages