Authentication responses
How to subscribe and process authentication responses

Subscribe

Users can respond to authentication requests by accepting or rejecting them. On the other hand, you won’t receive asynchronous notifications for requests which have timed out.

You can subscribe to authentication responses with this snippet

@client.authentication.subscribe do |auth_res|
    puts resp.status
end
client.MessagingService().Subscribe("identities.authenticate.req", func(m *messaging.Message)) {
    // manage the response
}
client.messaging().subscribe("identities.authenticate.req", (res: any): any => {
    // manage the response
})

Processing the response

if resp.accepted?
    p "accepted"
elsif resp.rejected?
    p "rejected"
elsif resp.unauthorized?
    p "unauthorized"
elsif resp.errored?
    p "errored"
else
    p "unkonwn status"
end

// Or simply access the status string p resp.status

// Go SDK will return an error for unsuccessful
// responses
err = authService.Request("1112223334")
if err != nil {
    log.Fatal("auth returned with: ", err)
}

log.Println("authentication succeeded")

try {
let res = await client.authentication().request("1112223334")
if(res.isAccepted() == true) {
    client.logger.info(`${res.selfID} is now authenticated 🤘`)
} else if(res.accepted == false) {
    client.logger.warn(`${res.selfID} has rejected your authentication request`)
} else {
    client.logger.error(res.errorMessage)
}
} catch (error) {
    client.logger.error(error.toString())
}

The interesting field in an authentication response is status. Valid values for status are:

accepted

The user has accepted the authentication request, so you can proceed authenticating it on your app.

rejected

The user has rejected the authentication request.

unauthorized

You’re unauthorized to interact with this user, let it know it needs to be connected to your app before continuing with an authentication process.

errored

An internal error happened.

Depending on the SDK there are different ways you can deal with different status, see some examples below