Magical Auth Reference
To perform a Magical Auth 2FA verification you need to the following steps:
- 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.
- 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_server_auth
Description:
start_server_auth
starts the 2FA verification process by sending a request from the application server by providing the user's phone number or email.
Syntax:
async def start_server_auth(self, **kwargs) -> MagicAuthStartServerAuthResponse:
Parameters:
Property | Type | Description |
---|---|---|
phone_number | str | Optional - The phone number to verify |
email | str | Optional - The email to verify |
redirect_url | str | Optional - URL to redirect after verification |
state | str | Optional - A state value that can be used to maintain state between the client and server. |
otp_confirmation_url | str | Optional - Custom URL for OTP confirmation page |
rcs_confirmation_url | str | Optional - Custom URL for RCS waiting page |
fallback_channel | str | Optional - Fallback verification method ('SMS', 'EMAIL', 'RCS', or 'NO_FALLBACK') |
At least one of phone_number
or email
must be provided.
Returns:
MagicAuthStartServerAuthResponse
: An object containing the session identifier and the auth URL to redirect the user to complete the verification.
MagicAuthStartServerAuthResponse Properties:
Property | Type | Description |
---|---|---|
session_id | str | Unique session identifier for this verification attempt |
auth_url | str | URL where the user should be directed to complete verification |
Example:
import asyncio
from glide_sdk import GlideClient
async def main():
glide = GlideClient()
# Start server auth with phone number
response = await glide.magic_auth.start_server_auth(
phone_number="+555123456789"
)
print(f"Session ID: {response['session_id']}")
print(f"Auth URL: {response['auth_url']}")
if __name__ == "__main__":
asyncio.run(main())
2. check_server_auth
Description:
check_server_auth
checks the status of a server-side verification initiated with start_server_auth
.
Syntax:
async def check_server_auth(self, session_id: str) -> CheckServerAuthResponse:
Parameters:
Property | Type | Description |
---|---|---|
session_id | str | The session ID received from start_server_auth |
Returns:
CheckServerAuthResponse
: An object containing the verification status.
CheckServerAuthResponse Properties:
Property | Type | Description |
---|---|---|
status | str | Current status of the verification ('PENDING' or 'COMPLETED') |
verified | bool | Whether the verification was successful (only meaningful when status is COMPLETED) |
Example:
import asyncio
from glide_sdk import GlideClient
async def main():
glide = GlideClient()
# Check server auth status
response = await glide.magic_auth.check_server_auth(
session_id="session-id-from-start-server-auth"
)
if response["status"] == "COMPLETED":
if response["verified"]:
print("Verification successful!")
else:
print("Verification failed!")
else:
print("Verification still pending...")
if __name__ == "__main__":
asyncio.run(main())
3. 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:
Property | Type | Description |
---|---|---|
phone_number | string | Optional - The phone number to verify. |
email | string | Optional - The email to verify. |
fallback_channel | string | Optional - Specifies the fallback verification method if the primary method fails. Can be 'SMS', 'EMAIL', or 'NO_FALLBACK'. |
redirect_url | string | Optional - The URL to which the user will be redirected after a successful verification. |
state | string | Optional - A state value that can be used to maintain state between the client and server. |
device_ip_address | string | Optional - The IP address of the user's device. |
One of phone_number
or email
must be provided.
device_ip_address
should be provided when the request is made from a server on behalf of the end-user device, ensuring accurate IP-based verification and geolocation services.
Returns:
MagicAuthStartResponse
: An object containing the verification status.
MagicAuthStartResponse Properties:
Property | Type | Description |
---|---|---|
type | string | The value can be MAGIC , SMS or EMAIL |
authUrl | string | Optional - The URL to open on the user's device in case of MAGIC type. |
flatAuthUrl | string | Optional - The plain URL to use .In case you do not want to redirect or to open at user's device use this. |
operatorId | string | Optional - 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()
4. 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:
Property | Type | Description |
---|---|---|
code | string | Optional - The code received from the user's device via EMAIL or SMS. |
phone_number | string | Optional - The phone number to verify if SMS or MAGIC. |
email | string | Optional - The email to verify in case of EMAIL |
token | string | Optional - The token received from the user's device in case of MAGIC. |
device_ip_address | string | Optional - The IP address of the user's device. |
Two paramters need to be sent based on the type
received from the start_auth
method.
- MAGIC:
token
andphone_number
- SMS:
code
andphone_number
- EMAIL:
code
andemail
Returns:
MagicAuthCheckResponse
: AMagicAuthCheckResponse
instance.
MagicAuthCheckResponse Properties:
Property | Type | Description |
---|---|---|
verified | boolean | Whether 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
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 | number | The expiration time of the session. |
scopes | string[] | An array of scopes associated with the session. |