We want to switch from WebAuth passwordless to native Passwordless thanks to recent addition in iOS SDK (v1.20). But during the login process the rules are not fired.
The flow in the app is the following:
- User creates an unverified account
- In Profile settings in app user taps “verify” which opens passwordless flow
-
ID token is enriched with some additional parameters (including the
userId
from parameters) using Rules - The enriched ID token is sent back to the app, which unlocks functionalities that require a user’s e-mail.
The configuration described below is an exact copy of the config passed to WebAuth
(parameters, clientID, scope, audience…)
Our invocation code:
static func startPasswordless(userId: String?, deviceToken: String? = nil,
email: String, completion: @escaping EmptyRequestResultBlock) {
let optionalParameters: [String: String?] = [
"prompt": "login",
"platform": "ios",
"locale": Locale.current.languageCode,
"countryCode": Locale.current.regionCode,
"deviceToken": deviceToken,
"userId": userId
]
let unwrappedParameters: [String: String] = optionalParameters.compactMapValues { $0 }
Auth0
.authentication(clientId: Auth0Configuration.shared.clientId, domain: Auth0Configuration.shared.domain)
.startPasswordless(email: email, type: .Code, connection: ConnectionType.email.rawValue,
parameters: unwrappedParameters)
.start { result in
DispatchQueue.main.async {
switch result {
case .success:
completion(.success)
case .failure(let error):
completion(.failure(error))
}
}
}
}
static func sendOTP(_ otp: String, for email: String,
completion: @escaping ((RequestResult<Credentials>) -> Void)) {
let scope: String = [
"openid",
"email",
"profile",
"read"
].joined(separator: " ")
Auth0
.authentication(clientId: Auth0Configuration.shared.clientId,
domain: Auth0Configuration.shared.domain)
.login(
email: email,
code: otp,
audience: Auth0Configuration.shared.userInfoEndpoint,
scope: scope)
.start {
switch $0 {
case .success(let credentials):
completion(.success(credentials))
case .failure(let error):
completion(.failure(error))
}
}
}