#AdditionalJar: com.google.android.gms:play-services-safetynet
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
'RecaptchaKey is a process global string.
Sub Verify
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim Client As JavaObject
Client = Client.InitializeStatic("com/google/android/gms/safetynet.SafetyNet".Replace("/", ".")).RunMethod("getClient", Array(ctxt))
Dim task As JavaObject = Client.RunMethod("verifyWithRecaptcha", Array(RecaptchaKey))
Dim start As Long = DateTime.Now
Do While task.RunMethod("isComplete", Null) = False And start + 10000 > DateTime.Now
Sleep(100)
Loop
If task.RunMethod("isSuccessful", Null) Then
Dim token As JavaObject = task.RunMethod("getResult", Null)
Dim tokenkey As String = token.RunMethod("getTokenResult", Null)
Log(tokenkey)
VerifyToken(tokenkey) '<---the token should be sent to your server and the server should verify the token
Else
Log("error")
End If
End Sub
'ServerSecretKey is a process global string.
Sub VerifyToken(token As String)
'verify the token
Dim j As HttpJob
j.Initialize("", Me)
j.PostString("https://www.google.com/recaptcha/api/siteverify", $"secret=${ServerSecretKey}&response=${token}"$)
Wait For (j) JobDone (j As HttpJob)
If j.Success Then
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim m As Map = parser.NextObject
Dim success As Boolean = m.Get("success")
If success Then
Log("User verified!!!!")
Else
Log("error!!!")
End If
End If
j.Release
End Sub
'RecaptchaKey is a process global string.
Sub Verify
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim Client As JavaObject
Client = Client.InitializeStatic("com/google/android/gms/safetynet.SafetyNet".Replace("/", ".")).RunMethod("getClient", Array(ctxt))
Dim task As JavaObject = Client.RunMethod("verifyWithRecaptcha", Array(RecaptchaKey))
Dim start As Long = DateTime.Now
Do While task.RunMethod("isComplete", Null) = False And start + 10000 > DateTime.Now
Sleep(100)
Loop
If task.RunMethod("isSuccessful", Null) Then
Dim token As JavaObject = task.RunMethod("getResult", Null)
Dim tokenkey As String = token.RunMethod("getTokenResult", Null)
Log(tokenkey)
VerifyToken(tokenkey) '<---the token should be sent to your server and the server should verify the token
Else
Log("error")
End If
End Sub
Yes i see it, but small square with loading animated circle only, no pictures puzzle or any security question!Do you see the recaptcha form?
What recaptcha key you used? v2 or v3?It started working after I changed the recaptcha key and package name.
4. Call verify in your activity:
B4X:'RecaptchaKey is a process global string. Sub Verify Dim ctxt As JavaObject ctxt.InitializeContext Dim Client As JavaObject Client = Client.InitializeStatic("com/google/android/gms/safetynet.SafetyNet".Replace("/", ".")).RunMethod("getClient", Array(ctxt)) Dim task As JavaObject = Client.RunMethod("verifyWithRecaptcha", Array(RecaptchaKey)) Dim start As Long = DateTime.Now Do While task.RunMethod("isComplete", Null) = False And start + 10000 > DateTime.Now Sleep(100) Loop If task.RunMethod("isSuccessful", Null) Then Dim token As JavaObject = task.RunMethod("getResult", Null) Dim tokenkey As String = token.RunMethod("getTokenResult", Null) Log(tokenkey) VerifyToken(tokenkey) '<---the token should be sent to your server and the server should verify the token Else Log("error") End If End Sub
"error": {
"success": false,
"error-codes": [
"timeout-or-duplicate"
]
}