Unity API reference
Unity API reference
For Unity Demo, please try the prefabs in the Magic Unity Repo
#Constructor
The Magic class is the entry-point to the Magic SDK. It must be instantiated with a Magic publishable key.
Magic
Public constructors | |
Magic(string apikey, EthNetwork network = EthNetwork.Mainnet, string locale = "en-US") | Construct a Magic instance with publishable Key and Ethereum network |
Magic(string apikey, CustomNodeConfiguration config, string locale = "en-US") | Construct a Magic instance with publishable Key and Custom Node configuration |
Example
01using link.magic.unity.sdk;
02
03public class MagicUnity : MonoBehaviour
04{
05 void Start()
06 {
07 Magic magic = new Magic("YOUR_PUBLISHABLE_KEY");
08 Magic.Instance = magic;
09 }
10}
#Auth module
The Auth Module and its members are accessible on the Magic SDK instance by the auth
property.
01using link.magic.unity.sdk;
02
03magic.Auth;
04magic.Auth.LoginWithMagicLink;
05magic.Auth.LoginWithSMS;
06magic.Auth.LoginWithEmailOTP;
#LoginWithMagicLink
On June 20th, passcodes (loginWithSMS()
||loginWithEmailOTP()
) are replacing Magic Links (loginWithMagicLink()
) for all of our Mobile SDKs. Learn more ->
#Public Methods
Methods |
async Task<string> LoginWithMagicLink(string email, bool showUI = true) |
email
The user email to log in with.showUI
Iftrue
, show an out-of-the-box pending UI while the request is in flight.
#Returns
DIDToken: Task<String>
The function resolves upon authentication request success and rejects with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
#LoginWithSMS
Authenticate a user passwordlessly using a one-time code sent to the specified phone number.
List of Currently Blocked Country Codes
#Public Methods
Methods |
async Task<string> LoginWithSms(string phoneNumber) |
phoneNumber
The phone number to log in with
#Returns
DIDToken: Response<String>()
The function resolves upon authentication request success and rejects with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
#LoginWithEmailOTP
Authenticate a user passwordlessly using an email one-time code sent to the specified user's email address.
#Public Methods
Methods |
async Task<string> LoginWithEmailOtp(string email) |
email
The user email to log in with.
#Returns
DIDToken: Task<String>
The function resolves upon authentication request success and rejects with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
#User Module
The User Module and its members are accessible on the Magic SDK instance by the user
property.
01import MagicSDK
02
03var magic = Magic.Instance
04
05magic.User
06magic.User.GetIdToken
07magic.User.GenerateIdToken
08magic.User.GetMetadata
09magic.User.UpdateEmail
10magic.User.IsLoggedIn
11magic.User.Logout
#UpdateEmail
Initiates the update email flow that allows a user to change to a new email
#Public Methods
Methods |
public async Task<bool> UpdateEmail() |
email
The user email to update with.showUI
Iftrue
, show an out-of-the-box pending UI while the request is in flight.
#Returns
Task<Boolean>
The Completable
resolves with a true boolean value if update email is successful and rejects with a specific error code if the request fails.
#GetIdToken
Generates a Decentralized Id Token which acts as a proof of authentication to resource servers.
#Public Methods
Methods |
public async Task<string> GetIdToken(int lifespan = 900) |
* lifespan?
: will set the lifespan of the generated token. Defaults to 900s (15 mins)
#Returns
GetIdTokenResponse: Task<String>
The Completable
resolves with a true boolean value if update email is successful and rejects with a specific error code if the request fails.
#GenerateIdToken
Generates a Decentralized Id Token with optional serialized data.
#Public Methods
Methods |
public async Task<string> GenerateIdToken(int lifespan = 900, string attachment = "none") |
lifespan
: will set the lifespan of the generated token. Defaults to 900s (15 mins)attachment
: will set a signature of serialized data in the generated token. Defaults to"none"
#Returns
Task<String>
Base64-encoded string representation of a JSON tuple representing [proof, claim]
#GetMetadata
Retrieves information for the authenticated user.
#Public Methods
Methods |
public async Task<UserMetadata> GetMetadata() |
#Returns
`Task<UserMetadata>`
The `UserMetadata` containing the issuer, email and cryptographic public address of the authenticated user.
01[Serializable]
02 public sealed class UserMetadata
03 {
04 [CanBeNull] public string issuer;
05 [CanBeNull] public string publicAddress;
06 [CanBeNull] public string email;
07 }
issuer
: The Decentralized ID of the user. In server-side use-cases, we recommend this value to be used as the user ID in your own tables.email
: Email address of the authenticated user.publicAddress
: The authenticated user's public address (a.k.a.: public key). Currently, this value is associated with the Ethereum blockchain.
#IsLoggedIn
Checks if a user is currently logged in to the Magic SDK.
#Public Methods
Methods |
public async Task<bool> IsLoggedIn() |
#Returns
Task<Boolean>
#Logout
Logs out the currently authenticated Magic user
#Public Methods
Methods |
public async Task<bool> Logout() |
#Returns
Task<Boolean>