Skip to main content
Version: Python

Your First Verification

This guide will help you get started with the Magical Auth API by going through the steps to perform your first 2FA verification.

Prerequisites

Before you begin, you need to have the following:

Step 1: Get your API Credentials

To get your API Credentials, you can go to the Magical Auth Product Page and click on "Manage on Provider" to access the service dashboard. For a full guide on how to get your credentials, you can refer to the Registration guide.

Step 2: Create a new project

Create a new folder and enter the folder from a terminal.

mkdir magical-auth-test
cd magical-auth-test

Step 3: Set Up Python Environment and Install SDK

Create and activate a virtual environment, then install the required packages:

python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
pip install glide-sdk httpx python-dotenv

Step 4: Perform a Verification

main.py
import asyncio
import httpx
from glide_sdk import GlideClient

async def main():
glide = GlideClient(
client_id="<client_id>",
client_secret="<client_secret>"
)
phone_number = '+555123456789'

magic_auth_start_response = await glide.magic_auth.start_auth(
phone_number=phone_number
)

async with httpx.AsyncClient(follow_redirects=True) as client:
res = await client.get(magic_auth_start_response.authUrl)
token = res.headers.get("token")
magic_auth_check_response = await glide.magic_auth.verify_auth(
phone_number=phone_number,
token=token
)
print('magic auth response', magic_auth_check_response)

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

Since we are using the test number +555123456789, the verification will always return type MAGIC and provide an authUrl. Unlike a regular MAGIC verification where the link would need to be opened on the user's device, this test number will return a test URL that can be opened on any device.

Because of this we can simply fetch the URL and extract the token from the response headers directly from the script.

With a token received, you can then verify the user's phone number using the verify_auth method.

Using the test number you should get back a response saying the verification was successful.

To run the script, you can use the following command:

python main.py

Conclusion

You have successfully performed your first verification using the Magical Auth API. You can now follow our 5-minute quickstart to deploying a test application using the Magical Auth API.