簡體   English   中英

Google平台服務身份驗證中的JWT簽名無效

[英]Invalid JWT signature on google platform service authentication

使用Cloud Speech API繼續測試...我從這里下載了另一個示例,我稍微修改了它,因為不推薦使用ClientAuthInterceptor類。 我正在使用服務帳戶,相關的使用代碼如下:

// This is contained in the MainActivity code.
String fCred = _lu.getBasePath() + "auth.json";

try
{
    InputStream isCred = new FileInputStream(fCred);
    ManagedChannel channel = ManagedChannelBuilder.forAddress(HOSTNAME, PORT).build();
    mStreamingClient = new StreamingRecognizeClient(channel, isCred, RECORDER_SAMPLERATE);
}
catch (IOException openEx)
{
    Log.e(MainActivity.class.getSimpleName(), "Error", openEx);
}

// This is contained in the StreamingRecognizeClient class code
public StreamingRecognizeClient(ManagedChannel channel, InputStream credentials, int samplingRate) throws IOException
{
    this.mSamplingRate = samplingRate;
    this.mChannel = channel;
    GoogleCredentials creds = GoogleCredentials.fromStream(credentials);

    if (creds.createScopedRequired())
        creds = creds.createScoped(OAUTH2_SCOPES);

    CallCredentials callCreds = MoreCallCredentials.from(creds);
    mSpeechClient = SpeechGrpc.newStub(channel).withCallCredentials(callCreds);

    credentials.close();
}

在應用程序初始化期間調用所有此代碼,文件auth.json是由Google控制台生成的身份驗證文件,其中包含項目ID和私鑰的所有信息。 然后函數recognizeBytes被稱為帶有音頻數據的第一個塊; 在發送實際音頻數據之前,您必須發送僅包含識別配置的消息,這由以下功能完成:

private void initializeRecognition() throws InterruptedException, IOException
{
    requestObserver = mSpeechClient.streamingRecognize(this);
    RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(AudioEncoding.FLAC).setSampleRate(mSamplingRate).build();
    StreamingRecognitionConfig streamingConfig = StreamingRecognitionConfig.newBuilder().setConfig(config).setInterimResults(true).setSingleUtterance(true).build();
    StreamingRecognizeRequest initial = StreamingRecognizeRequest.newBuilder().setStreamingConfig(streamingConfig).build();

    requestObserver.onNext(initial);
}

在第一次調用之后,我獲得的是400錯誤代碼,如下面的堆棧跟蹤所示:

11-30 15:34:12.916 3676-7309/? W/StreamingRecognizeClient: recognize failed: {0}: Status{code=UNAUTHENTICATED, description=null, cause=java.io.IOException: Error getting access token for service account: }
11-30 15:34:12.918 3676-7309/? E/StreamingRecognizeClient: Error to Recognize.
   io.grpc.StatusRuntimeException: UNAUTHENTICATED
       at me.yurifariasg.StreamingRecognizeClient.onError(StreamingRecognizeClient.java:98)
       at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:395)
       at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:481)
       at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:398)
       at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:513)
       at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
       at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)
   Caused by: java.io.IOException: Error getting access token for service account: 
       at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:227)
       at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:97)
       at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:74)
       at io.grpc.auth.GoogleAuthLibraryCallCredentials$1.run(GoogleAuthLibraryCallCredentials.java:113)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
       at java.lang.Thread.run(Thread.java:818) 
   Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
       {
           "error" : "invalid_grant",
           "error_description" : "Invalid JWT Signature."
       }
       at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1054)
       at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:225)
                                                            ... 6 more

由於所有簽署請求的過程都是由Google圖書館執行的,我不確切知道可以做些什么...我已經向Google技術支持發送了一個請求,可以在試用期間提供,但也許有人有一些建議。

謝謝。 魯道夫。

就我而言,我正在將符號文件上傳到firebase崩潰報告中。 在firebase控制台上“生成新的私鑰”之后,問題就解決了。 那么,你是否試圖獲得一個新的“auth.json”?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM