Skip to main content
Version: Go

Number Verify Reference

To perform a number verification you need to the following steps:

  1. Initiate a number verification session: This is done on the user's device by following a URL provided by the service.
  2. Generate a token: This is done by the backend server once the user has initiated the session.
  3. Check the verification status: This is done by calling the service with the token generated in the previous step.

To initiate the process you use the NumberVerifyClient. It is accessible via the GlideClient. This can be run from the frontend or backend and only requires a client id and not a client secret. With the NumberVerifyClient you can call the GetAuthUrl method for a specific user to get the URL to start the verification process.

info

Once the user has followed the URL and initiated the session they will be redirected to your redirect URL with a code query parameter.

This code can then be used to create a NumberVerifyUserClient which will automatically exchange the code for an access token and allow you to call the VerifyNumber method to check the verification status.

NumberVerifyClient Reference

Methods

1. GetAuthURL

Description: GetAuthURL retrieves the URL for the user to initiate a number verification session.

Syntax:

GetAuthURL(opts ...NumberVerifyAuthUrlInput) (string, error)

Parameters:

ParameterTypeDescription
optsNumberVerifyAuthUrlInputA struct containing the auth URL options.

NumberVerifyAuthUrlInput Properties:

PropertyTypeDescription
State*stringOptional - A state parameter to pass to the redirect URL.
UseDevNumberstringOptional - A phone number to use for testing instead of using IP based routing (only works for sandbox numbers). Basically adds to the requset a login_hint query param
PrintCodeboolOptional - Returns the user code in the response body. Saves the need to configure redirect_url in order to get the code. Only relevant for server request

Returns:

  • string: The URL for the user to initiate a number verification session. This URL should be opened on the user's device.

Example:

import (
"github.com/GlideApis/sdk-go/pkg/glide"
"github.com/GlideApis/sdk-go/pkg/types"
)
client, err := glide.NewGlideClient(settings)
authUrl, err := glideClient.NumberVerify.GetAuthURL()
// fmt.Println("Open this URL on the user's device: ", authUrl)


2. For

Description: For creates a NumberVerifyUserClient which is a numberVerify client for a specific user. This can later save the need to send the user phone number as param for every function call for example.

Syntax:

For(params types.NumberVerifyClientForParams) (*NumberVerifyUserClient, error)

Parameters:

ParameterTypeDescription
paramsNumberVerifyClientForParamsA struct containing the For parameters.

NumberVerifyClientForParams Properties:

PropertyTypeDescription
CodestringThe code received from the user's device.
PhoneNumber*stringOptional - The phone number to verify.

Returns:

  • NumberVerifyUserClient: A NumberVerifyUserClient.

Example:

import (
"github.com/GlideApis/sdk-go/pkg/glide"
"github.com/GlideApis/sdk-go/pkg/types"
)
glideClient, err := glide.NewGlideClient(settings)
// this code is the result of the GetAuthURL request before
code := "code-from-user-device"
phoneNumber := "+555123456789"
client, err := glideClient.NumberVerify.For(types.NumberVerifyClientForParams{Code: code, PhoneNumber: &phoneNumber})


NumberVerifyUserClient Reference

The NumberVerifyUserClient is used to interact with the Number Verify service for a specific phone number.

Methods

1. VerifyNumber

Description: VerifyNumber verifies that a user's phone number matches the phone number provided.

Syntax:

VerifyNumber(number *string, conf types.ApiConfig) (*NumberVerifyFuncResponse, error)

Parameters:

ParameterTypeDescription
number*stringThe phone number to verify. can be omitted if provided in the For method
confApiConfigA struct containing optional API configuration like session.

Returns:

  • *NumberVerifyResponse: A struct containing the verification status.

NumberVerifyResponse Properties:

PropertyTypeDescription
DevicePhoneNumberVerifiedboolWhether the phone number is verified.

Example:

import (
"github.com/GlideApis/sdk-go/pkg/glide"
"github.com/GlideApis/sdk-go/pkg/types"
)
glideClient, err := glide.NewGlideClient(settings)
// this code is the result of the GetAuthURL request before
code := "code-from-user-device"
phoneNumber := "+555123456789"
numberVerifyUserClient, err := glideClient.NumberVerify.For(types.NumberVerifyClientForParams{Code: code, PhoneNumber: &phoneNumber})
numberVerifyResponse, err := numberVerifyUserClient.VerifyNumber(nil, types.ApiConfig{})
// if numberVerifyResponse.DevicePhoneNumberVerified is true number is verified


Error Handling

Each method in NumberVerifyService can throw errors under certain conditions. Developers should handle these exceptions as part of their implementation. Common errors include:

  • InvalidInputError: Thrown when input parameters do not meet the required format or type.
  • OperationFailedError: Thrown when an operation cannot be completed successfully due to various issues, such as network problems or service unavailability.

Type Definitions

ApiConfig

This object can be sent to most service apis to override the default configuration like the access token used in the request.

Properties

PropertyTypeDescription
SessionSessionAn optional session struct for authentication and authorization.

Session

This object represents a user session with an access token, expiration time, and associated scopes.

Properties

PropertyTypeDescription
AccessTokenstringThe access token for the session.
ExpiresAtint64The expiration time of the session.
Scopes[]stringA string with scopes associated with the session.