User not verified after migrating from Authy to Verify

111 Views Asked by At

We had earlier asked a question regarding migrating the data from Authy to Verify API. We were following the steps provided in this URL.

(https://www.stackoverflow.com/questions/74302235/migrate-authy-totp-to-verify)

However, when we are migrating the user, the user is not verified even after the migration. Here is the code which we are using

Dim oAuthy = New clsAuthy(apiKey, False)

'Fetch details from authy to migrate to verify
Dim authyDetails As clsAuthySecret = oAuthy.GetAuthyDetails(item("TwilioAuthyId"))

oAuthy = Nothing

'Migrate data to verify API
With oVerify
    .GenerateQRCode(item("UserName"), item("UserId").ToString(), authyDetails.Secret)

    .VerifyToken(.FactorID, authyDetails.OTP, item("UserId").ToString())

    FactorId = .FactorID
    VerifyUrl = .QrUrl
End With
Public Function GetAuthyDetails(ByRef AuthyID As String) As clsAuthySecret

    Dim apiResponse As clsAuthySecret
    Dim url = String.Format("{0}/protected/json/users/{1}/secret/export", Me.baseUrl, AuthyID, Me.apikey)

    Try
        client.Headers.Set("X-Authy-API-Key", Me.apikey)

        Dim response = client.DownloadString(url)
        apiResponse = JsonConvert.DeserializeObject(Of clsAuthySecret)(response)
        apiResponse.RawResponse = response
    Catch ex As WebException
        apiResponse = New clsAuthySecret()
        apiResponse.Status = AuthyStatus.BadRequest 'bad request
        apiResponse.Message = ex.Message
        'apiResponse.RawResponse = ex.Response.ToString()
    End Try

    If (apiResponse.Success) Then
        apiResponse.Status = AuthyStatus.Success
    End If

    Return apiResponse
End Function
Public Function GenerateQRCode(ByVal Email As String, 
                               ByVal UserID As String,
                               ByVal Secret As String
                               ) As Task(Of Boolean)
    Try
        TwilioClient.Init(_accountSID, _authToken)
        Dim newFactor = NewFactorResource.Create(friendlyName:=Email,
                                                 factorType:=NewFactorResource.FactorTypesEnum.Totp,
                                                 pathServiceSid:=_serviceSID,
                                                 pathIdentity:=UserID.ToLower(),
                                                 bindingSecret:=Secret)

        _factorID = newFactor.Sid
        _qrUrl = JObject.Parse(newFactor.Binding.ToString())("uri")
    Catch ex As Exception
        _responseMessage = ex.Message
        Return False
    End Try

    Return True
End Function


Public Function VerifyToken(ByVal FactorID As String,
                            ByVal Token As String,
                            ByVal UserID As String
                            ) As Task(Of Boolean)
    Try
        TwilioClient.Init(_accountSID, _authToken)
        Dim factor = FactorResource.Update(authPayload:=Token,
                                           pathServiceSid:=_serviceSID,
                                           pathIdentity:=UserID.ToLower(),
                                           pathSid:=FactorID)

        If factor.Status.ToString = "verified" Then
            Return True
        Else
            Return False
        End If
    Catch ex As Exception
        _responseMessage = ex.Message
        Return False
    End Try
End Function

Is there anything we are missing from our end? Following is the response as shown in the image link below

https://i.stack.imgur.com/lhTkE.png

0

There are 0 best solutions below