未经验证:凭据需要具有隐私和完整性安全级别的通道观察到的安全级别:无

carvr3hs  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(389)

使用firebase admin sdk和java将我的后端服务器连接到firestore。
这是我进行firebase设置的初始化方法

public void initialize() throws IOException {
        FileInputStream serviceAccount = new FileInputStream(GOOGLE_APPLICATION_CREDENTIALS);
        GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(credentials)
                .build();
        FirebaseApp.initializeApp(options);

    }

当我使用cloudfirestore运行时,我的项目运行得很好,但是当我尝试通过添加环境变量firestore\u emulator\u host来使用firestore local emulator运行时,我遇到了以下问题

Caused by: com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Credentials require channel with PRIVACY_AND_INTEGRITY security level. Observed security level: NONE
    at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:73)
    at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
    at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
    at com.google.api.gax.grpc.ExceptionResponseObserver.onErrorImpl(ExceptionResponseObserver.java:82)
    at com.google.api.gax.rpc.StateCheckingResponseObserver.onError(StateCheckingResponseObserver.java:86)
    at com.google.api.gax.grpc.GrpcDirectStreamController$ResponseObserverAdapter.onClose(GrpcDirectStreamController.java:149)
    at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426)
    at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:689)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$900(ClientCallImpl.java:577)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:751)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:740)
    at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
mqkwyuun

mqkwyuun1#

我也有这个问题。。。看起来这里有个bug被修复了https://github.com/firebase/firebase-admin-java/issues/452
然而。。。如果你只导入 com.google.firebase:firebase-admin:7.1.0 它似乎在使用 google-cloud-firestore:1.35.0 这里面没有修正!
您需要同时指定这两个依赖项,以使它在中的仿真器正常工作 build.gradle ```
implementation "com.google.firebase:firebase-admin:7.1.0"
implementation "com.google.cloud:google-cloud-firestore:2.1.0"

相关问题