UNAUTHENTICATED:凭据需要具有PRIVACY_AND_INTEGRITY安全级别的通道.观察到的安全级别:



使用firebase admin-sdk和java将我的后端服务器连接到firestore。

这是我的初始化方法,它完成了火球设置

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);

}

当我使用cloud firestore运行时,我的项目运行良好,但当我尝试通过添加环境变量来使用firestore本地模拟器运行时,出现以下问题

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)

我也遇到了这个问题。。。看起来这里修复了一个错误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"

最新更新