I'm finally getting back to this after many distractions, and still not 
able to get things working unfortunately.

Just to note - I was previously using the AsyncAuthInterceptor for adding a 
token to the call headers, but because this is not a true interceptor, it's 
not possible to retry if the call fails authentication on the server side.

So, I'm back to trying to figure out how to retry a server streaming call. 
My question is, how can I know from the response headers if the call was 
unauthenticated?

Here's a snippet of my code so far:

var responseContinuation = continuation(request, context);

try
{
    // Any way to raise an exception when call is 
StatusCode=Unauthenticated here?
    responseContinuation.ResponseHeadersAsync.WaitAndUnwrapException();

    return new AsyncServerStreamingCall<TResponse>(
        responseContinuation.ResponseStream,
        responseContinuation.ResponseHeadersAsync,
        responseContinuation.GetStatus,
        responseContinuation.GetTrailers,
        responseContinuation.Dispose);
}
catch (RpcException e) when (e.StatusCode == StatusCode.Unauthenticated)
{
    if (Task.Run(() => RefreshTokensAsync(cancellationToken), 
cancellationToken).Result == false)
        _logger.Warn("Unable to refresh access token");

    AddOrUpdateHeader(context.Options.Headers, CreateBearerTokenHeader(
AccessToken));

    return continuation(request, context);
}


Any pointers very gratefully received.


On Friday, 1 March 2019 15:12:36 UTC+1, Benjamin Krämer wrote:
>
> You also might want to have a look at 
> https://github.com/grpc/grpc/tree/master/src/csharp/Grpc.Auth since 
> that's the cleaner way to achieve what you try. You can implement an ` 
> <https://github.com/grpc/grpc/blob/master/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs#L44>
> AsyncAuthInterceptor` 
> <https://github.com/grpc/grpc/blob/master/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs#L44>
>  
> that you then can use for `ChannelCredentials` 
> <https://github.com/grpc/grpc/blob/master/src/csharp/Grpc.Auth/GoogleGrpcCredentials.cs#L78>
> .
>
> I still have to check on how to implement the server side for 
> checking/validating the token and making the result available through the 
> call context. But this should at least solve your current problem.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/ddf1cafd-1938-4881-8c6d-0b55b6542449%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to