0

Hi I am facing an issue when triggering the tapkey lock it scans for the lock and successfully scans it. The when I trigger unlcok againsat the PhysicalLockId I get the lock blinks red and I get message Unauthorized.

Using Token Exchange Mechanism, generated Identity provider against Oauth Client. The lock is assigned to the user as unrestricted

iOS trigger Lock Function


private func triggerLock(physicalLockId: String) -> TKMPromise<Bool> {
    guard let bluetoothAddress = self.bleLockScanner.getLock(
        physicalLockId: physicalLockId)?.bluetoothAddress else {
            self.showAlert(title: "Alert", message: "Lock not nearby", okTitle: R.string.localizable.commonCancel(), cancelString: R.string.localizable.commonScanAgain(), cancelHandle:  { _ in
                self.scanLock()
            })
            return TKMAsync.promiseFromResult(false)
        }
    
    let ct = TKMCancellationTokens.fromTimeout(timeoutMs: 15000)
    
    // Use the BLE lock communicator to send a command to the lock
    return self.bleLockCommunicator.executeCommandAsync(
        bluetoothAddress: bluetoothAddress,
        physicalLockId: physicalLockId,
        commandFunc: { tlcpConnection -> TKMPromise<TKMCommandResult> in
            
            let triggerLockCommand = TKMDefaultTriggerLockCommandBuilder()
                .build()
            
            // Pass the TLCP connection to the command execution facade
            return self.commandExecutionFacade!.executeStandardCommandAsync(tlcpConnection, command: triggerLockCommand, cancellationToken: ct)
        },
        cancellationToken: ct)
    
    // Process the command's result
        .continueOnUi({ commandResult in
            let code: TKMCommandResult.TKMCommandResultCode = commandResult?.code ??
            TKMCommandResult.TKMCommandResultCode.technicalError
            
            switch code {
            case TKMCommandResult.TKMCommandResultCode.ok:
                return true
            default:
                return false
            }
        })
        .catchOnUi({ (_: TKMAsyncError) -> Bool in
            NSLog("Trigger lock failed")
            self.showAlert(title: "Alert", message: "Trigger lock failed")
            return false
        })
}
  • Hi Waqar, did you check, whether a key is present on the device? You can use [KeyManager.queryLocalKeysAsync](https://developers.tapkey.io/mobile/android/reference/Tapkey.MobileLib/latest/com/tapkey/mobile/manager/KeyManager.html#queryLocalKeysAsync(java.lang.String,com.tapkey.mobile.concurrent.CancellationToken)). – MarkusM Nov 25 '21 at 09:06
  • I wanted to know how will these keys be generated? – Waqar Yazdani Nov 25 '21 at 09:42
  • @MarkusM I get the grants, then I scan for lock nearby and get the PhysicalLockID to trigger the lock when lock is triggered it returns Unauthorized this looks like an issue from the identity provider on server side – Waqar Yazdani Nov 25 '21 at 10:18
  • What do you mean with 'I get the grants'? Does `queryLocalKeysAsync` return the expected key? – MarkusM Nov 25 '21 at 13:07
  • queryLocalKeysAsync is returning the expected key to me and against that I get the PhysicalLockId which I use to trigger the lock but the lock blinks red (gives a signal) but does not open – Waqar Yazdani Nov 26 '21 at 10:33
  • Can you paste a snippet of how you invoke the triggerLock action? – MarkusM Nov 26 '21 at 13:05
  • Added code snippet in quetion above as you can see in it I scan for Bluetooth address which is success then when I trigger against PhysicalLockId it blinks red (PhysicalLockId returned when getting keys) – Waqar Yazdani Nov 29 '21 at 06:19

1 Answers1

1

The error Unautorized means usually, that the current user don't have a grant to this specific lock. In other cases there would be a different error code.

As you are using your own app and so an own identity provider, you have also to create a contact for this specific users.

https://developers.tapkey.io/openapi/tapkey_management_api_v1/#/Contacts/Contacts_Put

If you are creating a contact, you have to specify the id of your identity provider as ipId, otherwise it will create a contact for a tapkey user.

As I can see in your account, you successfully created a user for your identity provider, but then created a contact for an tapkey user.

Harald
  • 465
  • 2
  • 8
  • Yes thats true the user I have created is tapkey user, thanks let me try this – Waqar Yazdani Nov 29 '21 at 11:20
  • I have created the contact against the ipId and added it to the lock and removed the previous user from lock but still I am not able to unlock it same error Unauthorized – Waqar Yazdani Nov 29 '21 at 13:48
  • Harold need your input to this as when I have created a new contact it is added to the Identity Provider but the existing contact is still there in it which is causing trouble I think – Waqar Yazdani Nov 30 '21 at 06:14
  • Thanks for the help Harold I have got success status Ok on mobile side now, please close this issue as resolved – Waqar Yazdani Nov 30 '21 at 09:26