iOS API Reference
Constructor
Configure and construct a Magic instance with publishable API Key retrieved from the Magic Dashboard
Magic
Public constructors |
---|
Magic(apiKey: String, locale: String) -> Magic Instance |
Magic(apiKey: String, network: EthNetwork, locale: String) |
Magic(apiKey: String, customNode: CustomNodeConfiguration, locale: String) |
apiKey
: publishable API Key retrieved from the Magic Dashboardlocale
: locale string (e.g."en_US"
), it will default toLocale.current.identifier
(your application locale) if blank is left
Example
In AppDelegate
Auth Module
The Auth Module and its members are accessible on the Magic SDK instance by the auth
property.
loginWithMagicLink
Authenticate a user passwordlessly using a "magic link" sent to the specified user's email address.
Public Methods
Methods |
---|
loginWithMagicLink( _ configuration: LoginWithMagicLinkConfiguration, response: (_ resp: Response<String>) -> Void ) |
loginWithMagicLink(_ configuration: LoginWithMagicLinkConfiguration) -> Promise <String> |
Returns
Promise<string | null>
: The promise 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.
Example
- Closure
- promise
Associated Class
LoginWithMagicLinkConfiguration(showUI: Bool = true, email: String)
email
The user email to log in with.showUI
Iftrue
, show an out-of-the-box pending UI while the request is in flight.
User Module
The User Module and its members are accessible on the Magic SDK instance by the user
property.
updateEmail
Initiates the update email flow that allows a user to change to a new email
Public Methods
Methods |
---|
updateEmail( _ configuration: UpdateEmailConfiguration, response: (_ resp: Response<Bool>) |
updateEmail(_ configuration: UpdateEmailConfiguration) -> Promise <Bool> |
Returns
Promise<Bool>
: The promise resolves with a true boolean value if update email is successful and rejects with a specific error code if the request fails.
Example
Associated Class
UpdateEmailConfiguration(showUI: Bool = true, email: String)
email
The user email to update with.showUI
Iftrue
, show an out-of-the-box pending UI while the request is in flight.
getIdToken
Generates a Decentralized Id Token which acts as a proof of authentication to resource servers.
Public Methods
Methods |
---|
getIdToken( _ configuration: GenerateIdTokenConfiguration? = nil, response: (_ resp: Response<String>) |
getIdToken(_ configuration: GenerateIdTokenConfiguration? = nil) -> Promise <String> |
Returns
Promise<String>
: Base64-encoded string representation of a JSON tuple representing [proof, claim]
Example
Associated Class
GetIdTokenConfiguration(lifespan: Int = 900)
lifespan?
(Int): will set the lifespan of the generated token. Defaults to 900s (15 mins)
generateIdToken
Generates a Decentralized Id Token with optional serialized data.
Public Methods
Methods |
---|
generateIdToken( _ configuration: GenerateIdTokenConfiguration, response: (_ resp: Response<String>) |
generateIdToken(_ configuration: GenerateIdTokenConfiguration) -> Promise <String> |
Returns
Promise<String>
: Base64-encoded string representation of a JSON tuple representing [proof, claim]
Example
Associated Class
GenerateIdTokenConfiguration(lifespan: Int = 900, attachment: String = 'none')
lifespan
(Number) : will set the lifespan of the generated token. Defaults to 900s (15 mins)attachment
(String) : will set a signature of serialized data in the generated token. Defaults to"none"
getMetadata
Retrieves information for the authenticated user.
Public Methods
Methods |
---|
getMetadata( response: (_ resp: Response<String>) |
getMetadata() -> Promise <String> |
Returns
UserMetadata
: containing the issuer, email and cryptographic public address of the authenticated user.
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.
Example
isLoggedIn
Checks if a user is currently logged in to the Magic SDK.
Public Methods
Methods |
---|
getMetadata( response: (_ resp: Response<Bool>) |
getMetadata() -> Promise <Bool> |
Returns
Promise<Bool>
Example
logout
Logs out the currently authenticated Magic user
Public Methods
Methods |
---|
logout( response: (_ resp: Response<Bool>) |
logout() -> Promise <Bool> |
Returns
Promise<Bool>