Number Verify Reference
To perform a number verification you need to the following steps:
- Initiate a number verification session: This is done on the user's device by following a URL provided by the service.
- Generate a token: This is done by the backend server once the user has initiated the session.
- 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.
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:
Parameter | Type | Description |
---|---|---|
opts | NumberVerifyAuthUrlInput | A struct containing the auth URL options. |
NumberVerifyAuthUrlInput Properties:
Property | Type | Description |
---|---|---|
State | *string | Optional - A state parameter to pass to the redirect URL. |
UseDevNumber | string | Optional - 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 |
PrintCode | bool | Optional - 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:
Parameter | Type | Description |
---|---|---|
params | NumberVerifyClientForParams | A struct containing the For parameters. |
NumberVerifyClientForParams Properties:
Property | Type | Description |
---|---|---|
Code | string | The code received from the user's device. |
PhoneNumber | *string | Optional - The phone number to verify. |
Returns:
NumberVerifyUserClient
: ANumberVerifyUserClient
.
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:
Parameter | Type | Description |
---|---|---|
number | *string | The phone number to verify. can be omitted if provided in the For method |
conf | ApiConfig | A struct containing optional API configuration like session. |
Returns:
*NumberVerifyResponse
: A struct containing the verification status.
NumberVerifyResponse Properties:
Property | Type | Description |
---|---|---|
DevicePhoneNumberVerified | bool | Whether 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
Property | Type | Description |
---|---|---|
Session | Session | An optional session struct for authentication and authorization. |
Session
This object represents a user session with an access token, expiration time, and associated scopes.
Properties
Property | Type | Description |
---|---|---|
AccessToken | string | The access token for the session. |
ExpiresAt | int64 | The expiration time of the session. |
Scopes | []string | A string with scopes associated with the session. |