SIM Swap Reference
The SIM Swap client operates with a specific user identifier (e.g., a phone number). To interact with the SIM Swap service for a particular user, you need to create a SimSwapUserClient configured for that user.
SimSwapUserClient
s are creating using the SimSwapClient
accessible from the GlideClient
.
SimSwapClient Reference
Methods
1. For
Description:
For
creates and returns a SimSwapUserClient
configured for the specified user identifier.
Syntax:
For(identifier types.UserIdentifier) (*SimSwapUserClient, error)
Parameters:
Parameter | Type | Description |
---|---|---|
identifier | UserIdentifier | An interface representing a user (can be a phonenumber, ip address or custom user id but only one of the above) |
UserIdentifier Properties:
Property | Type | Description |
---|---|---|
PhoneNumber | string | The phone number of the user. |
IPAddress | string | The IP address of the user. |
UserID | string | A custom user identifier. |
Only one of the properties should be provided.
Returns:
*SimSwapUserClient
: A pointer to a SimSwapUserClient configured for the specified user identifier.
Example:
client, err := glide.NewGlideClient(settings)
userClient, err := client.SimSwap.For(types.PhoneIdentifier{PhoneNumber: "+555123456789"})
SimSwapUserClient Reference
The SimSwapUserClient
is used to interact with the SIM Swap service for a specific phone number.
Properties
1. requiresConsent
A boolean indicating if the user needs to provide consent before checking for a SIM swap. If this is true then you need to call getConsentUrl
to get the consent URL and ask the user to provide consent before calling check
or retrieveDate
.
Methods
1. Check
Description:
Check
verifies if a SIM swap has occurred for the user's phone number.
Syntax:
Check(params types.SimSwapCheckParams, conf types.ApiConfig) (*SimSwapCheckResponse, error)
Parameters:
Parameter | Type | Description |
---|---|---|
checkParams | SimSwapCheckParams | A struct containing the check parameters. |
SimSwapCheckParams Properties:
Property | Type | Description |
---|---|---|
PhoneNumber | string | Optional - The phone number to check for a SIM swap. |
MaxAge | *int | Optional - Maximum age of the SIM swap in hours. |
If phoneNumber was provided in the for
method as the user identifier, it can be omitted here.
Returns:
SimSwapCheckResponse
: A struct containing the SIM swap status.
SimSwapCheckResponse Properties:
Property | Type | JSON key | Description |
---|---|---|---|
Swapped | bool | swapped | Indicates if a SIM swap has occurred up to maxAge hours ago |
Example:
import (
"github.com/GlideApis/sdk-go/pkg/glide"
"github.com/GlideApis/sdk-go/pkg/types"
)
client, err := glide.NewGlideClient(settings)
userClient, _ := client.SimSwap.For(types.PhoneIdentifier{PhoneNumber: "+555123456789"})
response, err := userClient.Check(types.SimSwapCheckParams{}, types.ApiConfig{})
2. RetrieveDate
Description:
RetrieveDate
retrieves the date of the last SIM swap for the user's phone number.
Syntax:
RetrieveDate(params types.SimSwapRetrieveDateParams, conf types.ApiConfig) (*SimSwapRetrieveDateResponse, error)
Parameters:
Parameter | Type | Description |
---|---|---|
params | SimSwapRetrieveDateParams | A struct containing the retrieve date parameters. |
SimSwapRetrieveDateParams Properties:
Property | Type | Description |
---|---|---|
PhoneNumber | string | Optional - The phone number to check for a SIM swap. |
Returns:
SimSwapRetrieveDateResponse
: An object containing the date of the last SIM swap.
SimSwapRetrieveDateResponse Properties:
Property | Type | JSON Key | Description |
---|---|---|---|
LatestSimChange | string | latestSimChange | The date of the last SIM swap in ISO 8601 format. |
Example:
import (
"github.com/GlideApis/sdk-go/pkg/glide"
"github.com/GlideApis/sdk-go/pkg/types"
)
client, err := glide.NewGlideClient(settings)
userClient, _ := client.SimSwap.For(types.PhoneIdentifier{PhoneNumber: "+555123456789"})
response, err := userClient.RetrieveDate(types.SimSwapRetrieveDateParams{}, types.ApiConfig{})
// Output: { LatestSimChange: "2022-01-01T00:00:00Z" }
3. GetConsentUrl
Description:
GetConsentUrl
retrieves the URL for the user to provide consent before checking for a SIM swap.
Syntax:
GetConsentURL() string
Returns:
string
: The URL for the user to provide consent.
Example:
import (
"github.com/GlideApis/sdk-go/pkg/glide"
"github.com/GlideApis/sdk-go/pkg/types"
)
simSwapUserClient, _ := client.SimSwap.For(types.PhoneIdentifier{PhoneNumber: "+555123456789"})
if simSwapUserClient.requiresConsent {
consentURL := simSwapUserClient.GetConsentURL()
}
Error Handling
Each method in SimSwapService
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 string 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 object 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. |