Skip to main content
Version: Python

Magical Auth Reference

To perform a Magical Auth 2FA verification you need to the following steps:

  1. Initiate a 2FA verification session: This is done by sending a request from the user's device or from the backend by providing the user's phone number. The server will detect what verification channel the user is able to perform and initiate the verification process.
  2. Verify the user: This is done by sending the verification code to the server to check if the user has successfully verified their phone number.

The Magical Auth service is available through the MagicalAuthClient through the GlideClient instance.

MagicAuthClient Reference

Methods

1. start_auth

Description: start_auth starts the 2FA verification process by sending a request from the user's device or by providing the user's phone number.

Syntax:

async def start_auth(self, **kwargs) -> MagicAuthStartResponse:

Parameters:

MagicAuthStartProps Properties:

PropertyTypeDescription
phone_numberstringOptional - The phone number to verify.
emailstringOptional - The email to verify.
fallback_channelstringOptional - Specifies the fallback verification method if the primary method fails. Can be 'SMS', 'EMAIL', or 'NO_FALLBACK'.
redirect_urlstringOptional - The URL to which the user will be redirected after a successful verification.
statestringOptional - A state value that can be used to maintain state between the client and server.

One of phone_number or email must be provided.

Returns:

  • MagicAuthStartResponse: An object containing the verification status.

MagicAuthStartResponse Properties:

PropertyTypeDescription
typestringThe value can be MAGIC, SMS or EMAIL
authUrlstringOptional - The URL to open on the user's device in case of MAGIC type.
flatAuthUrlstringOptional - The plain URL to use .In case you do not want to redirect or to open at user's device use this.
operatorIdstringOptional - The OperatorId.

Example:

import asyncio
from glide_sdk import GlideClient

async def main():
glide = GlideClient()
magic_auth_start_response = await glide.magic_auth.start_auth(
phone_number="+555123456789"
)
if magic_auth_start_response["type"] == "MAGIC":
print(f"Open this URL on the user's device: {magic_auth_start_response['authUrl']}")
else:
print(f"Verification code sent to the user's device using channel {magic_auth_start_response['type']}")

if __name__ == "__main__":
main()

2. verify_auth

Description: verify_auth checks the code / token received from the user's device to verify the user.

Syntax:

async def verify_auth(self, **kwargs) -> MagicAuthCheckResponse:

Parameters:

PropertyTypeDescription
codestringOptional - The code received from the user's device via EMAIL or SMS.
phone_numberstringOptional - The phone number to verify if SMS or MAGIC.
emailstringOptional - The email to verify in case of EMAIL
tokenstringOptional - The token received from the user's device in case of MAGIC.

Two paramters need to be sent based on the type received from the start_auth method.

  • MAGIC: token and phone_number
  • SMS: code and phone_number
  • EMAIL: code and email

Returns:

  • MagicAuthCheckResponse: A MagicAuthCheckResponse instance.

MagicAuthCheckResponse Properties:

PropertyTypeDescription
verifiedbooleanWhether the user is verified.

Example:

import asyncio
from glide_sdk import GlideClient

async def main():
glide = GlideClient()
magic_auth_check_response = await glide.magic_auth.verify_auth(
token="code-from-user-device",
phone_number="+555123456789"
)

if magic_auth_check_response.verified:
print("User verified")
else:
print("User not verified")

if __name__ == "__main__":
asyncio.run(main())

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 object 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.
expiresAtnumberThe expiration time of the session.
scopesstring[]An array of scopes associated with the session.