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

using link.magic.unity.sdk;

public class MagicUnity : MonoBehaviour
{
    void Start()
    {
        Magic magic = new Magic("YOUR_PUBLISHABLE_KEY");
        Magic.Instance = magic;
    }
}

#Auth module

The Auth Module and its members are accessible on the Magic SDK instance by the auth property.

using link.magic.unity.sdk;

magic.Auth;
magic.Auth.LoginWithMagicLink;
magic.Auth.LoginWithSMS;
magic.Auth.LoginWithEmailOTP;

#LoginWithMagicLink

#Public Methods

Methods
async Task<string> LoginWithMagicLink(string email, bool showUI = true)
  • email The user email to log in with.
  • showUI If true, 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.

import MagicSDK

var magic = Magic.Instance

magic.User
magic.User.GetIdToken
magic.User.GenerateIdToken
magic.User.GetMetadata
magic.User.UpdateEmail
magic.User.IsLoggedIn
magic.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 If true, 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.

[Serializable]
    public sealed class UserMetadata
    {
        [CanBeNull] public string issuer;
        [CanBeNull] public string publicAddress;
        [CanBeNull] public string email;
    }
  • 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>

Did you find what you were looking for?