Authentication
i. Access Token Check
API : BSA.loadAccessToken
swift
if let token = BSA.loadAccessToken() {
// While Holding Access Token
}
else {
// No Access Token
}
Description
- If no
Access Token
is stored, it returns nil. - The
Access Token
is stored internally in the SDK when the basic authentication logic is successfully completed throughAutoAuthenticator
. - Most user-related functions such as query, authentication type change, and withdrawal require the
Access Token
.
ii. AutoAuthenticator
API : BSA.AutoAuthenticator()
swift
// authenticator
let autoAuthenticator = BSA.AutoAuthenticator()
// parameters
let qrId: String? = nil
let pushData: BSA.FCM.PushData? = nil
let clientKey = "a1hrg2xv..."
guard let userKey = BSA.loadUserKey() else {
return false
}
guard let deviceId = BSA.loadDeviceID() else {
return false
}
let otpAuth = false
let sendPush = false
let localAuthType = BSA.loadLocalAuthType() ?? .BIOMETRIC
let usePasscodeWhenFailed = false
// setData
autoAuthenticator.setData(qrId: qrId,
pushData: pushData,
clientKey: clientKey,
userKey: userKey,
deviceId: deviceId,
otpAuth: otpAuth,
sendPushMessage: sendPush,
localAuthType: localAuthType,
usePasscodeWhenFailed: usePasscodeWhenFailed)
// setEvent
.setEvent(onProcessing: { [weak self] processDescription in
// onProcessing operates in the background thread, so processing such as UI must be done in the main thread.
DispatchQueue.main.async {
// Process Verification
var processName = ""
switch(processDescription) {
case .StartAuth:
processName = "Start Authentication"
.
.
.
}
self?.labelProcess.text = processName
}
}, onSuccess: { [weak self] in
// Authentication Success
}, onCancel: { [weak self] in
// Authentication Canceled
}, onFailed: { [weak self] rtCode, resultMessage in
// Authentication Failed
}, onError: { [weak self] error in
// Invocation Error
}, onTotalLog: { [weak self] totalLog in
// Invocation Log
}).start() // Start Authentication
Parameters
setData
swift
autoAuthenticator.setData(qrId: String?,
pushData: BSA.FCM.PushData?,
clientKey: String,
userKey: String,
deviceId: String,
otpAuth: Bool,
sendPushMessage: Bool,
localAuthType: BSA.Enums.LocalAuthType,
usePasscodeWhenFailed: Bool) -> AutoAuthenticator
Parameter | Type | Description |
---|---|---|
qrId | String? | QR recognition result. If it's not QR authentication, it's nil. |
pushData | BSA.FCM.PushData? | Authentication data received via push. If it's not Push Message Authentication, it's nil. |
clientKey | String | Client's unique key |
userKey | String | UserID |
deviceId | String | UUID processed by the SDK. |
otpAuth | Bool | Check if it's OTP authentication. |
sendPushMessage | Bool | Check if a push message should be sent. |
LocalAuthType | BSA.Enums.LocalAuthType | Local Authentication Type |
userPasscodeWhenFailed | Bool | Determine whether to use passcode in case of biometric authentication failure. |
setEvent
swift
autoAuthenticator.setEvent(
onProcessing: @escaping (BSA.Enums.ProcessDescription) -> (),
onSuccess: @escaping () -> (),
onCancel: @escaping () -> (),
onFailed: @escaping BSA.APICaller.OnFailed,
onError: @escaping BSA.APICaller.OnError,
onTotalLog: @escaping BSA.APICaller.OnTotalLog) -> AutoAuthenticator
Parameter | Type | Description |
---|---|---|
onProcessing | (BSA.Enums.ProcessDescription) -> () | Name of the currently processing process. |
onSuccess | () -> () | Called on success. |
onCancel | () -> () | Called on Cancel. |
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. |
start
swift
autoAuthenticator.start()
Description
- When using
AutoAuthenticator
, you must callsetData
andsetEvent
before callingstart
. - After calling
start
, it automatically performs all authentication processes(authentication start -> blockchain node verification -> local authentication -> authentication completion)
.onProcessing
is called with the name of the authentication process when that authentication process starts.
- If authentication is successful, the authentication token issued by the authentication is stored internally in the SDK (It's Called an AccessToken).
- Caution: If you proceed with QR or push authentication, a token will not be issued.
- Depending on the
removeToken
parameter when callingBSA.initialize
, this token can be deleted or preserved.
- For the
otpAuth
parameter insetData
, you should put theotpAuth
value from push data.- If it's not Push Message Authentication, it's
false
.
- If it's not Push Message Authentication, it's
- Select and use the
clientKey
appropriately internally according to QR, Push, and Basic Authentication.
ii-i. Basic Authentication
- When requesting authentication for the purpose of obtaining
Access Token
to use other APIs. - If the parameters of
setData
are set as below, it's Basic Authentication.
swift
// parameters
let qrId: String? = nil
let pushData: BSA.FCM.PushData? = nil
let otpAuth = false
ii-ii. QR Authentication
swift
var qrHelper = BSA.QRHelper()
var cameraParent: UIView = "Parent View with Camera Preview"
// Check Camera Permission
qrHelper.checkCameraPermission(onGranted: { [weak self] in
// Start QR Parsing Logic
self?.qrHelper.startQR(cameraParent: cameraParent,
onPreviewLayerAdded: { cameraParent, previewLayer in
// UI handling
}, onSuccess: { [weak self] qrData in
// QR Recognition Successful
self?.data.qrData = qrData
}, onFailed: { [weak self] qrError in
// QR Recognition Failed
})
}, onDenied: {
// No Permission
})
- If you want to proceed with QR Authentication, obtain QRData using
BSA.QRHelper
and then setqrId: String?
inAuthAuthenticator
'ssetData
.
If a QR process already exists
swift
var qrHelper = BSA.QRHelper()
let qrData = qrHelper.parseData(code: "String that parses the QR code")
if qrData.qrResult { //If the authentication QR code for BSA is correct
// TODO: action on success
} else { //When the QR code is not in the correct form (when it is not a related QR code)
// TODO: Action on failure
}
- If there is a QR process, you can call
qrHelper.parseData()
on the string that parsed the QR and use the resulting value.
ii-iii. Push Message Authentication
- If you want to proceed with Push Message Authentication, set the
pushData
obtained through the callback ofBSA.FCM.registerPushNotificationProcessor
aspushData: BSA.FCM.PushData?
inAuthAuthenticator
'ssetData
.- Refer to the
FCM Setup and Configuration Guide
for details.
- Refer to the
ii-iv. OTP Authentication
- There are two methods for OTP authentication:
Press OTP authentication after entering the UserID in a different platform(web)
and receive push first.
Press OTP authentication without entering the UserID in a different platform(web)
and receive OTP number first.
- For the first method, after successful Push Message Authentication, receive the OTP number and enter it in the requesting platform.
- For the second method, first call
BSA.APICaller.issuanceOTPNumber
to receive the OTP number, then enter it in the requesting platform and proceed with Push Message Authentication.
Issuance OTP Number
API : BSA.APICaller.issuanceOTPNumber
swift
BSA.APICaller.issuanceOTPNumber(onSuccess: { [weak self] otpNumber in
// Issuance Successful
}, onTokenExpired: { [weak self] rtCode, resultMessage in
// Token Expired
}, onFailed: { rtCode, resultMessage in
// Invocation Failure
}, onError: { error in
// Invocation Error
}, onTotalLog: { text in
// Invocation Log
}, onCompleted: {
// invocation completed
}, disposeBag: disposeBag)
OTP Issuance Cancellation
API : BSA.APICaller.IssuanceCancelForOTPNumber
swift
let otpNumber = "226339" // OTP Number to Cancel
BSA.APICaller.IssuanceCancelForOTPNumber(otpNumber: otpNumber,
onSuccess: { [weak self] otpNumber in
// Cancellation of Issuance Successful
}, onTokenExpired: { [weak self] rtCode, resultMessage in
// Token Expired
}, onFailed: { rtCode, resultMessage in
// Invocation Failure
}, onError: { error in
// Invocation Error
}, onTotalLog: { text in
// Invocation Log
}, onCompleted: {
// invocation completed
}, disposeBag: disposeBag)
ii-v. TOTP Authentication
- TOTP is used as an alternative for authentication when network connectivity is not available.
- SignUp or Register New Device must proceed successfully.
- Use
BSA.loadTOTPSecretKey()
issued during SignUp or Register New Device to internally generate TOTP numbers.
- Use
swift
let result = BSA.TOTP.generateTOTP()
if let totpNumber = result.number {
// Successful TOTP Number Generation
}
else {
// If result.number is nil, it's an error
print(result.error)
}
iii. Authentication Cancellation
API : BSA.APICaller.requestCancelAuth
swift
guard let deviceId = BSA.loadDeviceID() else {
return
}
guard let userKey = BSA.loadUserKey() else {
return
}
BSA.APICaller.requestCancelAuth(qrId: nil,
clientKey: "a1hrg2xv...",
deviceId: deviceId,
userKey: userKey,
sendPushMessage: false,
onSuccess: {
// Successful Invocation
}, onTokenExpired: { [weak self] rtCode, resultMessage in
// Token Expired
}, 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)
Parameters
swift
BSA.APICaller.requestCancelAuth(qrId: String?,
clientKey: String,
deviceId: String,
userKey: String,
sendPushMessage: Bool,
onSuccess: @escaping () -> (),
onTokenExpired: @escaping BSA.APICaller.OnTokenExpired,
onFailed: @escaping OnFailed,
onError: @escaping OnError,
onTotalLog: @escaping OnTotalLog? = nil,
onCompleted: @escaping onCompleted? = nil,
disposeBag: DisposeBag)
Parameter | Type | Description |
---|---|---|
qrId | String? | QR recognition result. If it's not QR authentication, it's nil. |
clientKey | String | Client's unique key |
deviceId | String | UUID processed by the SDK. |
userKey | String | UserID |
sendPushMessage | Bool | Check if a push message should be sent. |
onSuccess | () -> () | Called on success. |
onTokenExpired | onTokenExpired | Function called when token expires. Same format as onFailed |
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. |
Description
- When cancellation is needed during authentication, you can request it.
- When this API is called, the operations of
AutoAuthenticator
are canceled.
- When this API is called, the operations of
- When canceling during QR Authentication request,
qrId
is required.
iv. Biometric Authentication Re-registration
- If biometric authentication information (FaceID, TouchID) changes after SignUp or Register New Device, it will fail in Auth-Logic.
- If it has changed:
BSA.APICaller.requestOTPNumberSend
BSA.APICaller.verifyOTPNumber
BSA.LocalAuth.startSimpleAuth
- If performed in sequence, the biometric authentication information will be updated.
- Detailed API information can be found in the SignUp Guide.
- Biometric authentication information itself can be resolved by calling
BSA.LocalAuth.startSimpleAuth
, but for security, OTP number must be requested and authenticated.