Using PnP iOS SDK
Logging in a User
To login in a user, you can use the login
method. It will trigger login flow will navigate the
user to a browser model allowing the user to login into the service. You can pass in the supported
providers to the login method for specific social logins such as GOOGLE, APPLE, FACEBOOK, etc., and
do whitelabel login.
Parameters
The login method accepts W3ALoginParams
as a required parameter.
- Table
- Struct
Parameter | Description |
---|---|
loginProvider | It sets the OAuth login method to be used. You can use any of the supported values are GOOGLE , FACEBOOK , REDDIT , DISCORD , TWITCH , APPLE , LINE , GITHUB , KAKAO , LINKEDIN , TWITTER , WEIBO , WECHAT , EMAIL_PASSWORDLESS , SMS_PASSWORDLESS , and FARCASTER . |
extraLoginOptions? | It can be used to set the OAuth login options for corresponding loginProvider . For instance, you'll need to pass user's email address as. Default value for the field is nil , and it accepts ExtraLoginOptions as a value. |
redirectUrl? | Url where user will be redirected after successfull login. By default user will be redirected to same page where login will be initiated. Default value for the field is nil , and accepts URL as a value. |
appState? | It can be used to keep track of the app state when user will be redirected to app after login. Default is nil , and accepts String as a value. |
mfaLevel? | Customize the MFA screen shown to the user during OAuth authentication. Default value for field is MFALevel.DEFAULT , which shows MFA screen every 3rd login. It accepts MFALevel as a value. |
dappShare? | Custom verifier logins can get a dapp share returned to them post successful login. This is useful if the dapps want to use this share to allow users to login seamlessly. It accepts String as a value. |
curve? | It will be used to determine the public key encoded in the jwt token which returned in getUserInfo function after user login. This parameter won't change format of private key returned by We3Auth. Private key returned by getPrivKey is always secp256k1. To get the ed25519 key you can use getEd25519PrivKey method. The default value is SUPPORTED_KEY_CURVES.SECP256K1 . |
public struct W3ALoginParams: Codable {
public init() {
loginProvider = nil
dappShare = nil
extraLoginOptions = nil
redirectUrl = nil
appState = nil
mfaLevel = nil
curve = .SECP256K1
}
let loginProvider: String?
var dappShare: String?
let extraLoginOptions: ExtraLoginOptions?
let redirectUrl: String?
let appState: String?
let mfaLevel: MFALevel?
let curve: SUPPORTED_KEY_CURVES
}
public enum Web3AuthProvider: String, Codable {
case GOOGLE = "google"
case FACEBOOK = "facebook"
case REDDIT = "reddit"
case DISCORD = "discord"
case TWITCH = "twitch"
case APPLE = "apple"
case LINE = "line"
case GITHUB = "github"
case KAKAO = "kakao"
case LINKEDIN = "linkedin"
case TWITTER = "twitter"
case WEIBO = "weibo"
case WECHAT = "wechat"
case EMAIL_PASSWORDLESS = "email_passwordless"
case JWT = "jwt"
case SMS_PASSWORDLESS = "sms_passwordless"
case FARCASTER = "farcaster"
}
Usage
import Web3Auth
let web3auth = try await Web3Auth(W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network: .sapphire_mainnet,
redirectUrl: "bundleId://auth"
))
let result = try await web3Auth.login(W3ALoginParams(loginProvider: .GOOGLE))
Examples
- Discord
- Twitch
- Email Passwordless
- SMS Passwordless
- Farcaster
- JWT
import Web3Auth
let web3auth = try await Web3Auth(W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network: .sapphire_mainnet,
redirectUrl: "bundleId://auth"
))
let result = try await web3Auth.login(W3ALoginParams(loginProvider: .GOOGLE))
import Web3Auth
let web3auth = try await Web3Auth(W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network: .sapphire_mainnet,
redirectUrl: "bundleId://auth"
))
let result = try await web3Auth.login(W3ALoginParams(loginProvider: .FACEBOOK))
import Web3Auth
let web3auth = try await Web3Auth(W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network: .sapphire_mainnet,
redirectUrl: "bundleId://auth"
))
let result = try await web3Auth.login(W3ALoginParams(loginProvider: .DISCORD))
import Web3Auth
let web3auth = try await Web3Auth(W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network: .sapphire_mainnet,
redirectUrl: "bundleId://auth"
))
let result = try await web3Auth.login(W3ALoginParams(loginProvider: .TWITCH))
import Web3Auth
let web3auth = try await Web3Auth(
W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network:.sapphire_mainnet,
redirectUrl: "bundleId://auth"
)
)
let result = try await web3Auth.login(
W3ALoginParams(
loginProvider: .EMAIL_PASSWORDLESS,
extraLoginOptions: .init(loginHint: "hello@web3auth.io")
)
)
import Web3Auth
let web3auth = try await Web3Auth(W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network: .sapphire_mainnet,
redirectUrl: "bundleId://auth"
))
let result = try await web3Auth.login(W3ALoginParams(
Web3AuthProvider.SMS_PASSWORDLESS,
// The phone number should be in format of +{country_code}-{phone_number}
extraLoginOptions: .init(loginHint: "+91-9911223344")
))
import Web3Auth
let web3auth = try await Web3Auth(
W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network: .sapphire_mainnet,
redirectUrl: "bundleId://auth"
)
)
let result = try await web3Auth.login(W3ALoginParams(loginProvider: .FARCASTER))
import Web3Auth
let web3auth = try await Web3Auth(W3AInitParams(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
network: .sapphire_mainnet,
redirectUrl: "bundleId://auth"
))
let result = try await web3Auth.login(
W3ALoginParams(
loginProvider: .JWT,
extraLoginOptions: .init(domain:"your-domain", id_token: "your_jwt_token")
)
)
Retrieve Private Key
Web3Auth supports two widely used cryptographic curves, Secp256k1 and Ed25519, making it chain-agnostic and compatible with multiple blockchain networks. Learn more about how to connect different blockchains.
Secp256k1 Private Key
To retrieve the secp256k1 private key of the user, use getPrivkey
method. The method returns an
EVM compatible private key which can be used to sign transactions on EVM compatible chains.
let privateKey = web3Auth.getPrivKey();
Ed25519 Private Key
To retrieve the secp256k1 private key of the user., use getEd25519PrivKey
method. This private key
can be used to sign transactions on Solana.
let privateKey = web3Auth.getEd25519PrivKey();
Retrive User Information
You can use the getUserInfo
method to retrieve various details about the user, such as their login
type, whether multi-factor authentication (MFA) is enabled, profile image, name, and other relevant
information.