This is an OTP Auth package for GOLang.
⭐️ 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.
go get -u github.com/yahya077/otp-golang
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 |
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")
})
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 |