Search code examples
iosauthenticationtapkey

Tapkey token exchange is successful, but getting a 400 Bad Request when trying to login


I am successfully using the Tapkey token exchange endpoint to exchange a Firebase token for a Tapkey one, but am then having an error calling login.

I am requested the following Scope's when exchanging the token:

register:mobiles read:user read:ip:users handle:keys

My swift code is below (basically lifted straight from the documentation):

let authToken = ExchangeFirebaseTokenForTapkeyToken(firebaseToken);

if authToken == nil {
    return
}

// For testing purposes, normally this would be static and only built once
let serviceFactory = TKMServiceFactoryBuilder()
    .setTokenRefreshHandler(TapkeyTokenRefreshHandler())
    .build()

let userManager = serviceFactory.userManager

let result = userManager.logInAsync(accessToken: authToken!, cancellationToken: TKMCancellationTokens.None)

result.continueOnUi { (userId) -> Void in
    print(userId as Any)
}
.catchOnUi { (error) -> Void in
    print(error)
}
.conclude()

The logs are below, as you can see I get a Failed to authenticateAsync error, and a HTTP 400 response.

2021-06-14 14:25:48.805135+0100 App[11940:234234] LogonManager: start authentication

Jun 14 14:25:48 [11940] : LogonManager: start authentication

2021-06-14 14:25:48.805917+0100 App[11940:234234] NetTpkyMcRestLoggingAsyncHttpRequestExecutor: Request POST 'https://my.tapkey.com/api/v1/Auth/Auth/UserInfo?t=tk' started.

Jun 14 14:25:48 [11940] : NetTpkyMcRestLoggingAsyncHttpRequestExecutor: Request POST 'https://my.tapkey.com/api/v1/Auth/Auth/UserInfo?t=tk' started.

2021-06-14 14:25:49.464429+0100 App[11940:234234] NetTpkyMcRestLoggingAsyncHttpRequestExecutor: Request POST 'https://my.tapkey.com/api/v1/Auth/Auth/UserInfo?t=tk' completed with code 400 after 659ms.

Jun 14 14:25:49 [11940] : NetTpkyMcRestLoggingAsyncHttpRequestExecutor: Request POST 'https://my.tapkey.com/api/v1/Auth/Auth/UserInfo?t=tk' completed with code 400 after 659ms.

2021-06-14 14:25:49.476961+0100 App[11940:234234] AuthenticationManagerImpl: Failed to authenticateAsync

If I provide any value other than the access key returned from the Token Exchange endpoint, I get a 401 Unauthorised (which is to be expected).

I have tried adding this user to the portal, but I still have the same issue.

Is there anything else I need to do, or any extra configuration I need to add to my iOS app? I have matched my configuration with the sample app (as far as I can tell) to no avail.

Thanks


Solution

  • Users of external identity providers have to be registered before the can login.

    You can find the details here: https://developers.tapkey.io/api/authentication/identity_providers/#working-with-users

    When it is necessary for your use case, that these users are automatically created when they login, please send a request to tapkey support and they will enable this feature for you.