The OTPLess Go SDK is a simple, easy-to-use client for interacting with OTPLess API for authentication. This SDK allows you to integrate OTP (One-Time Password), Magic Link, OAuth, and other authentication methods into your Go applications. You can easily send OTPs to phone numbers, email addresses, or handle phone call approvals, among other features.
To install the OTPLess Go SDK, you can use the following Go command:
go get github.com/kisshan13/otplessgo
To initialize a new OTPLess client, you can use the NewOTPLessClient
function.
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
payload := &otplessgo.PhoneMagicLinkPayload{
RedirectURI: "https://yourapp.com/redirect",
Expiry: 600,
PhoneNumber: "1234567890",
Channels: []otplessgo.Channel{otplessgo.ChannelSMS},
}
response, err := client.SendPhoneMagicLink(payload)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
payload := &otplessgo.EmailMagicLinkPayload{
RedirectURI: "https://yourapp.com/redirect",
Expiry: 600,
Email: "example@email.com"
}
response, err := client.SendEmailMagicLink(payload)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
payload := &otplessgo.PhoneOTPPayload{
Phone: "",
OtpLength: otplessgo.DigitFour,
Expiry: 600,
Channels: []otplessgo.Channel{otplessgo.ChannelSMS}
}
response, err := client.SendPhoneOTP(payload)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
payload := &otplessgo.EmailOTPPayload{
Email: "",
OtpLength: otplessgo.DigitFour,
Expiry: 600,
}
response, err := client.SendEmailOTP(payload)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
payload := &otplessgo.VerifyOTPPayload{
RequestId: "<request-id>",
Otp : "1234",
}
response, err := client.VerifyOTP(payload)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
payload := &otplessgo.PhoneOTPLinkPayload{
Phone: "",
RedirectURI: "http://localhost:8080/handle",
OtpLength: otplessgo.DigitFour,
Expiry: 600,
Channels: []otplessgo.Channel{otplessgo.ChannelSMS}
}
response, err := client.SendPhoneOTPLink(payload)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
payload := &otplessgo.EmailOTPLinkPayload{
Email: "example@email.com",
OtpLength: otplessgo.DigitFour
Expiry: 600,
RedirectURI: "http://localhost:8080",
Channel: []otplessgo.Channel{otplessgo.ChannelEmail}
}
response, err := client.SendEmailOTPLink(payload)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
payload := &otplessgo.OAuthPayload{
Channel: otplessgo.OAuthGoogle,
RedirectURI: "http://localhost:8080/callback/google"
}
response, err := client.InitiateOAuth(payload)
}
import (
"github.com/kisshan13/otplessgo"
)
func main() {
client := otplessgo.NewOTPLessClient("<client-id>", "<client-secret>", otplessgo.VersionOne)
response, err := client.VerifyCode("<code from oauth redirect or magic links>")
}
All responses are returned in a generic ApiResponse[T]
structure, which contains the following fields:
Response
: The response data of type T.
ErrorResponse
: In case of an error, contains the error details.
RawResponse
: The raw HTTP response object.
Example :
type ApiResponse[T any] struct {
Response *T
ErrorResponse *ApiErrorResponse
RawResponse *http.Response
}
In case of an error, you can access the error details through the ErrorResponse
field of the ApiResponse
structure.
Example :
type ApiErrorResponse struct {
Message string `json:"message,omitempty"`
Description string `json:"description,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
}
The SDK defines several constants for authentication channels and OTP lengths:
const (
ChannelWhatsapp = Channel("WHATSAPP")
ChannelSMS = Channel("SMS")
ChannelVoiceCall = Channel("VOICE_CALL")
ChannelViber = Channel("VIBER")
ChannelEmail = Channel("EMAIL")
)
const (
OAuthWhatsapp = OAuthChannel("WHATSAPP")
OAuthTwitter = OAuthChannel("TWITTER")
OAuthGoogle = OAuthChannel("GOOGLE")
OAuthApple = OAuthChannel("APPLE")
OAuthLinkedin = OAuthChannel("LINKEDIN")
OAuthMicrosoft = OAuthChannel("MICROSOFT")
OAuthFacebook = OAuthChannel("FACEBOOK")
OAuthInstagram = OAuthChannel("INSTAGRAM")
OAuthLine = OAuthChannel("LINE")
OAuthSlack = OAuthChannel("SLACK")
OAuthDropbox = OAuthChannel("DROPBOX")
OAuthGithub = OAuthChannel("GITHUB")
OAuthBitbucket = OAuthChannel("BITBUCKET")
OAuthAtlassian = OAuthChannel("ATLASSIAN")
OAuthLinear = OAuthChannel("LINEAR")
OAuthGitlab = OAuthChannel("GITLAB")
OAuthTitktok = OAuthChannel("TIKTOK")
OAuthTwitch = OAuthChannel("TWITCH")
OAuthTelegram = OAuthChannel("TELEGRAM")
OAuthHubspot = OAuthChannel("HUBSPOT")
OAuthNotion = OAuthChannel("NOTION")
OAuthBox = OAuthChannel("BOX")
OAuthXero = OAuthChannel("XERO")
)
const (
DigitFour = OtpLength(4)
DigitSix = OtpLength(6)
)
We welcome contributions to enhance the OTPLess Go SDK. To contribute, please follow these steps:
-
Fork the Repository: Create a fork of this repository on your GitHub account.
-
Clone the Fork: Clone your fork to your local machine using:
git clone https://github.com/kisshan13/otplessgo.git
-
Create a Branch : Create a new branch for your feature or bug fix:
git checkout -b feature-name
-
Make Changes : Implement your feature or fix the bug. Ensure your code is well-documented and adheres to the existing coding style.
-
Commit Changes : Commit your changes with a meaningful commit message:
git commit -m "Add a brief description of your change"
-
Push Changes: Push your branch to your fork:
git push origin feature-name
-
Create a pull request : Open a pull request (PR) to the main repository. Ensure your PR includes a detailed description of your changes.