The application represents your service. It’s a good practice to have separate applications for separate services.
request := sms.NewApplicationRequest("2FA application")
apiResponse, httpResponse, err := infobipClient.
TfaAPI.
CreateTfaApplication(auth).
ApplicationRequest(*request).
Execute()
appId := apiResponse.ApplicationId
Message template is the message body with the PIN placeholder that is sent to end users.
pinLength := int32(4)
request := sms.NewCreateMessageRequest("Your pin is {{pin}}", sms.PINTYPE_ALPHANUMERIC)
request.PinLength = &pinLength
apiResponse, httpResponse, err := infobipClient.
TfaAPI.
CreateTfaMessageTemplate(auth, appId).
CreateMessageRequest(*request).
Execute()
msgId := apiResponse.MessageId
After setting up the application and message template, you can start generating and sending PIN codes via SMS to the provided destination address.
from := "InfoSMS"
to := "41793026727"
request := sms.NewStartAuthenticationRequest(*appId, *msgId, to)
request.From = &from
apiResponse, httpResponse, err := infobipClient.
TfaAPI.
SendTfaPinCodeOverSms(auth).
StartAuthenticationRequest(*request).
Execute()
pinId := apiResponse.PinId
Verify a phone number to confirm successful 2FA authentication.
request := sms.NewVerifyPinRequest("1598")
apiResponse, httpResponse, err := infobipClient.
TfaAPI.
VerifyTfaPhoneNumber(auth, *pinId).
VerifyPinRequest(*request).
Execute()