使用SafetyNet的安全环境检查使用SafetyNet Attestation API不起作用,因为它无法在成功或失败回调中获得回调 [英] Safety environment check in android using SafetyNet Attestation API is not working as it not getting callback on success or failure callback

查看:3227
本文介绍了使用SafetyNet的安全环境检查使用SafetyNet Attestation API不起作用,因为它无法在成功或失败回调中获得回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于安卓环境中的saftey环境检查,我正在使用
$ b https://developer.android.com/training/safetynet/attestation.html

  SafetyNet.getClient(this).attest(nonce,API_KEY)
.addOnSuccessListener(this,successListner)
.addOnFailureListener(this,failureListener)
pre>

我因为网络错误null 而失败回调。任何人都可以点亮一下吗?



但是 https://medium.com/@hargoyal/secure-android-app-with-safetynet-8e367a1c8ad0



<$ (新的ResultCallback< SafetyNetApi.AttestationResult>(){
@Override
public void onResult(); pre $ SafetyNet.SafetyNetApi.attest(mGoogleApiClient,nonce)
.setResultCallback (SafetyNetApi.AttestationResult结果){
Status status = result.getStatus();
if(status.isSuccess()){
decodeJws(result.getJwsResult());
//表示与服务的通信成功
//使用result.getJwsResult()获取结果数据
} else {
//与服务通信时发生错误。
}
}
});

此方法正在运行,但 SafetyNet.SafetyNetApi 已被弃用。

解决方案

重新检查API密钥或创建一个像这里



  • >转到Google API控制台中的图书馆页面。

  • 搜索Android设备验证API。当你找到API时,点击它。出现Android设备验证API仪表板
    屏幕。

  • 如果API尚未启用,请单击启用。证书按钮出现,点击它生成一个API密钥。否则,请点击所有API凭证下拉列表
    ,并选择与启用了Android设备验证API的
    项目相关联的API密钥。

  • 在左侧的边栏中,单击凭证。复制出现的API密钥。



For saftey environment check in android I was using

https://developer.android.com/training/safetynet/attestation.html

SafetyNet.getClient(this).attest(nonce, API_KEY)
   .addOnSuccessListener(this,successListner)
   .addOnFailureListener(this,failureListener)

for which I am getting failure callback with network error null. Can anybody please throw some light on this ?

but https://medium.com/@hargoyal/secure-android-app-with-safetynet-8e367a1c8ad0

SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce)
                .setResultCallback(new ResultCallback<SafetyNetApi.AttestationResult>() {
                    @Override
                    public void onResult(SafetyNetApi.AttestationResult result) {
                        Status status = result.getStatus();
                        if (status.isSuccess()) {
                            decodeJws(result.getJwsResult());
                            // Indicates communication with the service was successful.
                            // Use result.getJwsResult() to get the result data.
                        } else {
                            // An error occurred while communicating with the service.
                        }
                    }
                });

this approach is working but SafetyNet.SafetyNetApi is deprecated.

解决方案

Recheck the API key or create a new one like here. I was having the same issue and the problem was that I was restricting the key to the wrong package name.

  • Go to the Library page in the Google APIs Console.
  • Search for the Android Device Verification API. When you've found the API, click on it. The Android Device Verification API dashboard screen appears.
  • If the API isn't already enabled, click Enable.
  • If the Create credentials button appears, click on it to generate an API key. Otherwise, click the All API credentials drop-down list and select the API key that is associated with the project for which the Android Device Verification API is enabled.
  • In the sidebar on the left, click Credentials. Copy the API key that appears.

这篇关于使用SafetyNet的安全环境检查使用SafetyNet Attestation API不起作用,因为它无法在成功或失败回调中获得回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆