Skip to main content
Version: Python

Quickstart

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: Initialize the SDK

pip -m venv venv
source venv/bin/activate
pip install glide-sdk

Step 4: Perform a Verification

index.py
from glide import GlideClient

def main():
glide = GlideClient()
magic_auth_start_response = glide.magic_auth.start_auth({
"phoneNumber": "+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()

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.

Step 5: Follow the URL

Add the following function to your code to perform the verification programmatically:

index.py
import requests

def get_code_from_verification(magic_auth_url):
response = requests.get(magic_auth_url)
return response.text

Step 6: Check the Verification Code

index.py
def main():
glide = GlideClient()
magic_auth_start_response = glide.magic_auth.start_auth({
"phoneNumber": "+555123456789"
})
if magic_auth_start_response["type"] == "MAGIC":
print(f"Open this URL on the user's device: {magic_auth_start_response['authUrl']}")
code = get_code_from_verification(magic_auth_start_response['authUrl'])
magic_auth_check_response = glide.magic_auth.check_auth({
"phoneNumber": "+555123456789",
"code": code
})

if magic_auth_check_response["status"] == "SUCCESS":
print("Verification successful")
else:
print("Verification failed")
else:
print(f"Verification code sent to the user's device using channel {magic_auth_start_response['type']}")

if __name__ == "__main__":
main()

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

Next Steps - Testing with a real number

To test the verification process with a real number, you can replace the test number +555123456789 with your own number. Depending on the support by your carrier, you will receive the verification code via one of the silent verification methods or via SMS.

If you recieved the verification code via one of the manual methods like SMS or EMAIL, you can create a seperate script to check the code and verify the user as you would when a user would submit the code they recieved into your application.

check.py
def main():
glide = GlideClient()
magic_auth_check_response = glide.magic_auth.check_auth({
"phoneNumber": "+555123456789",
"code": "123456"
})

if magic_auth_check_response["status"] == "SUCCESS":
print("Verification successful")
else:
print("Verification failed")

if __name__ == "__main__":
main()

Conclusion

You have successfully performed your first verification using the Magical Auth API. You can now integrate this into your application to provide a seamless 2FA experience for your users.