Device Re-registration
iOS SDK provides featured to re-register device and use BSA SDK by using basic information.
i. User Information Verification & OTP Number Request
userKey, name, verifyDatamust all be valid for OTP to be sent. In all other cases, it will report an error through onFailed. The LocalAuthType received on success represents the Local Authentication Type last used by the user and must be authenticated before making a Register New Device request.
Example
BSA.APICaller.requestSendOTPNumberForRegisterDevice(
clientKey: "a1hrg2xv...",
userKey: "user1",
name: "username1",
sendType: .Email,
sendTarget: "user@email.com",
bundleIdentifier: "com.your.app",
onSuccess: { [weak self] localAuthType in
// Successful Invocation
// Local Authentication Type of Registered User
self?.data.existingUserData?.authType = localAuthType
}, onFailed: { [weak self] rtCode, resultMessage in
// Invocation Failure
}, onError: { [weak self] error in
// Invocation Error
}, onTotalLog: { text in
// Invocation Log
}, onCompleted: {
// invocation completed
}, disposeBag: disposeBag)
BSA.APICaller.requestSendOTPNumberForRegisterDevice
BSA.APICaller.requestSendOTPNumberForRegisterDevice(
clientKey:String,
userKey: String,
name: String,
sendType: BSA.APICaller.OTPSendType,
sendTarget: String,
bundleIdentifier: String,
onSuccess: @escaping (BSA.Enums.LocalAuthType) -> (),
onFailed: @escaping OnFailed,
onError: @escaping OnError,
onTotalLog: @escaping OnTotalLog? = nil,
onCompleted: @escaping onCompleted? = nil,
disposeBag: DisposeBag )
Parameter
Parameter | Type | Description |
---|---|---|
clientKey | String | Client's unique key |
userKey | String | UserID |
name | String | User name |
sendType | BSA.APICaller.OTPSendType | Email, PhoneNumber |
sendTarget | String | Address or number matching sendType |
bundleIdentifier | String | App's bundleIdentifier |
onSuccess | (BSA.Enums.LocalAuthType) -> () | Callback called on success. It returns the last Local Authentication Type used by the user. |
onFailed | OnFailed | Callback function called on API processing failure. |
onError | OnError | Callback function called on error. |
onTotalLog | OnTotalLog | Callback function to receive all logs generated during API calls. |
onCompleted | onCompleted | Called at the end after all processes are completed. |
disposeBag | DisposeBag | DisposeBag variable to manage RxSwift Disposable objects. |
ii. OTP Number Validation
Enter the OTP number received by email/sms, call the API, and if successful, receive the disposeToken string. disposeToken is used to check whether the user is the correct user during Register New Device.
Example(BSA.APICaller.verifyOTPNumber
BSA.APICaller.verifyOTPNumber(sendType: BSA.APICaller.OTPSendType,
sendTarget: String,
otpNumber: "298336",
clientKey: "a1hrg2xv...",
onValidOTPNumber: { [weak self] disposeToken in
// OTP Number Matches
// Token Storage
self?.data.disposeToken = disposeToken
}, onInvalidOTPNumber: {
// OTP Number Doesn't Match
}, onFailed: { [weak self] rtCode, resultMessage in
// Invocation Failure
}, onError: { [weak self] error in
// Invocation Error
}, onTotalLog: { text in
// Invocation Log
}, onCompleted: {
// invocation completed
}, disposeBag: disposeBag)
BSA.APICaller.verifyOTPNumber(sendType: BSA.APICaller.OTPSendType,
sendTarget: String,
otpNumber: String,
clientKey: String,
onValidOTPNumber: @escaping (String) -> (),
onInvalidOTPNumber: @escaping () -> (),
onFailed: @escaping OnFailed,
onError: @escaping OnError,
onTotalLog: @escaping OnTotalLog? = nil,
onCompleted: @escaping onCompleted? = nil,
disposeBag: DisposeBag )
Parameter
Parameter | Type | Description |
---|---|---|
sendType | BSA.APICaller.OTPSendType | Platform to receive OTP number (Email, SMS) |
sendTarget | String | Address for OTP number type |
otpNumber | String | Received OTP number. |
clientKey | String | Client's unique Key |
onValidOTPNumber | (String) -> () | Callback called when OTP numbers match. The disposeToken value passed as a parameter is used in SignUp. |
onInvalidOTPNumber | () -> () | Callback called when OTP numbers don't match. |
onFailed | OnFailed | Callback function called on API processing failure. |
onError | OnError | Callback function called on error. |
onTotalLog | OnTotalLog | Callback function to receive all logs generated during API calls. |
onCompleted | onCompleted | Called at the end after all processes are completed. |
disposeBag | DisposeBag | DisposeBag variable to manage RxSwift Disposable objects. |
iii. Local Authentication
When called, it performs biometric and passcode authentication. For Register New Device, there is no saved DomainState for biometric authentication, so checkDomainStateChanged should be set to false.
Local Authentication must succeed to invoke BSA.APICAller.requestSignUp. The callback called with onResult runs on a background thread, so UI operations should be done on the main thread.
Example
BSA.LocalAuth.startSimpleAuth(localAuthType: .BIOMETRIC,
reason: "Authentication is required to verify your identity",
checkDomainStateChanged: false,
usePasscodeWhenFailed: false,
onSuccess: {
// onSuccess operates on a background thread, so UI-related tasks should be performed on the main thread.
DispatchQueue.main.async {
// Local Authentication Successful
}
}, onError: { errorCode in
// onError operates on a background thread, so UI-related tasks should be performed on the main thread.
DispatchQueue.main.async {
// Local Authentication Failed
switch errorCode {
case .DOMAIN_STATE_CHANGED:
// Biometric authentication info has been changed
case .BIOMETRIC_NOT_AVILABLE
case .BIOMETRIC_NOT_SUPPORT_HARDWARE
case .BIOMETRIC_LOCK_OUT:
// Biometric authentication not available
case .BIOMETRIC_NOT_ENROLLED_DEVICE:
// Biometric authentication info is not on device
case .PASSCODE_NOT_ENROLLED_DEVICE:
// Passcode not on device
case .USER_CANCEL, .USER_FALLBACK:
// User cancels authentication
case .AUTH_FAILED:
// Authentication failed
default:
// Other errors
}
}
})
BSA.LocalAuth.startSimpleAuth
BSA.LocalAuth.startSimpleAuth(
localAuthType: BSA.Enums.LocalAuthType,
reason: String,
checkDomainStateChanged: Bool,
usePasscodeWhenFailed: Bool,
onSuccess: @escaping ()->(),
onError: @escaping (BSA.LocalAuthHelper.ErrorCode?)->())
Parameter
Parameter | Type | Description |
---|---|---|
localAuthType | BSA.Enums.LocalAuthType | Local authentication type |
reason | String | Message displayed on OS during biometric authentication |
checkDomainStateChanged | Bool | Determine whether to detect biometric changes |
usePasscodeWhenFailed | Bool | Decide whether to use a passcode when biometric authentication fails |
onSuccess | ()->() | Local authentication processing result callback |
onError | (BSA.LocalAuthHelper.ErrorCode?)->() | Local authentication processing result callback |
iv. Register New Device
existingUserData must be filled with complete data when making the call.
Example
BSA.APICaller.requestRegisterDevice(existingUserData: data.existingUserData!,
onSuccess: {
// Successful Device Re-registration
}, onFailed: { [weak self] rtCode, resultMessage in
// Invocation Failure
}, onError: { [weak self] error in
// Invocation Error
}, onTotalLog: { text in
// Invocation Log
}, onCompleted: {
// invocation completed
}, disposeBag: disposeBag)
Parameter
BSA.APICaller.requestRegisterDevice(
existingUserData: BSA.SignUpData.ExistingUserData,
onSuccess: @escaping () -> (),
onFailed: @escaping OnFailed,
onError: @escaping OnError,
onTotalLog: @escaping OnTotalLog? = nil,
onCompleted: @escaping onCompleted? = nil,
disposeBag: DisposeBag )
Parameter | Type | Description |
---|---|---|
existingUserData | BSA.SignUpData.ExistingUserData | Data required for Register New Device. Fill all fields and make the call. |
onSuccess | () -> () | Callback called on Register New Device success. |
onFailed | OnFailed | Callback function called on API processing failure. |
onError | OnError | Callback function called on error. |
onTotalLog | OnTotalLog | Callback function to receive all logs generated during API calls. |
onCompleted | onCompleted | Called at the end after all processes are completed. |
disposeBag | DisposeBag | DisposeBag variable to manage RxSwift Disposable objects. |
BSA.SignUpData.ExistingUserData
Name | Type | Description |
---|---|---|
appPackage | String | BundleIdentifier |
clientKey | String | Client's unique key |
appVersion | String | App version (e.g., 1.1.1) |
token | String | FCM token value. |
String | Email address. | |
phoneNumber | String | Phone number. |
userKey | String | UserID |
name | String | User name |
authType | BSA.Enums.LocalAuthType | Local Authentication Type (NONE, BIOMETRIC, PASSCODE) |
os | BSA.Enums.OSType | os type (fixed to iOS) |
disposeToken | String | Token received upon OTP authentication success. |
otpType | BSA.Enums.OTPType | Type of OTP number received (email, SMS). |
Information saved after Register New Device
If Register New Device is successful, you can retrieve information using the following functions. BSA.loadTOTPSecretKey BSA.loadDeviceID BSA.loadFCMToken BSA.loadUserKey BSA.loadLocalAuthType