Native Passwordless Login

With the Headless Passwordless Login Flow, users can log in by entering their email address or phone number and verifying their identity with a one-time password (OTP). You control the front-end experience in your app. On the back end, your app calls the Headless Passwordless Login API via an Experience Cloud site to log in the user.

Before You Begin 

Before setting up the passwordless login flow, make sure these tasks are complete.

For public clients, we recommend that you always enable Require reCAPTCHA to access the Headless Passswordless Login API, which requires your app to include a reCAPTCHA token in your initial request to the API.

Note

To learn more about setting up reCAPTCHA, see:

Enable Headless Passwordless Login Flow 

To enable the flow with Mobile SDK, add these properties to the useNativeLogin method call.

  • To fill in these fields, use the values from the Google Cloud project reCAPTCHA settings.
  • Only enterprise reCAPTCHA requires reCaptchaSiteKeyId and googleCloudProjectId.
  • When using non-enterprise reCAPTCHA, set reCaptchaSiteKeyId and googleCloudProjectId to nil, and set isReCaptchaEnterprise to false.

iOS 

1let reCaptchaSiteKeyId = "your-recaptcha-site-key-id"
2let googleCloudProjectId = "your-google-cloud-project-id"
3let isReCaptchaEnterprise = true
4
5SalesforceManager.shared.useNativeLogin(
6    withConsumerKey: clientId,
7    callbackUrl: redirectUri,
8    communityUrl: loginUrl,
9    reCaptchaSiteKeyId: reCaptchaSiteKeyId,
10    googleCloudProjectId: googleCloudProjectId,
11    isReCaptchaEnterprise: isReCaptchaEnterprise,
12    nativeLoginViewController: nativeLoginViewController,
13    scene:scene)

Android 

1val reCaptchaSiteKeyId = "your-recaptcha-site-key-id"
2val googleCloudProjectId = "your-google-cloud-project-id"
3val isReCaptchaEnterprise = true
4
5MobileSyncSDKManager.getInstance().useNativeLogin(
6    consumerKey = clientId,
7    callbackUrl = redirectUri,
8    communityUrl = loginUrl,
9    googleCloudProjectId = googleCloudProjectId,
10    reCaptchaSiteKeyId = reCaptchaSiteKeyId,
11    isReCaptchaEnterprise = isReCaptchaEnterprise)

Request Password and Initialize Login 

To request the password and initialize passwordless login with OTP, use this method.

iOS 

1SalesforceManager.shared.nativeLoginManager().submitOtpRequest(
2    username: username,
3    reCaptchaToken: reCaptchaToken,
4    otpVerificationMethod: otpVerificationMethod)

Android 

1nativeLoginManager.submitOtpRequest(
2    username = username,
3    reCaptchaToken = reCaptchaToken,
4    otpVerificationMethod = otpVerificationMethod)

Submit the Passcode 

After the OTP has been requested, the user is prompted to enter the passcode. Use this method to submit the passcode with the OTP identifier returned by submitOtpRequest in the previous task.

iOS 

1SalesforceManager.shared.nativeLoginManager()
2.submitPasswordlessAuthorizationRequest(
3    otp: otp,
4    otpIdentifier: otpIdentifier,
5    otpVerificationMethod: otpVerificationMethod)

Android 

1nativeLoginManager.submitPasswordlessAuthorizationRequest(
2    otp = otp,
3    otpIdentifier = otpIdentifier,
4    otpVerificationMethod = otpVerificationMethod)

For working examples of Headless Passwordless Login Flow on Mobile SDK, see the iOSNativeLoginTemplate or the AndroidNativeLoginTemplate on GitHub.

We've Moved

Welcome to the new home of the Mobile SDK Developer Guide! For now, the Japanese guide can be found in PDF form.