GCP pub/sub push subscription frombody and fromquery issue

Mani kanta 1 Reputation point
2022-08-02T14:15:32.947+00:00

Hi - I have created the images for gcp pubsub push subscriptions with this below code and created the end point through cloud run. I have pointed the endpoint push subscription. Here having the issue is end point not send the "[FromBody] PushBody body" body object and "[FromQuery] string token" is missing. If possible may i know the solution for this ?

Seems having any issue while creating the pub/sub push subscription.

[HttpPost]
[Route("/AuthPush")]
public async Task<IActionResult> AuthPushAsync([FromBody] PushBody body, [FromQuery] string token)
{
// Get the Cloud Pub/Sub-generated "Authorization" header.
string authorizaionHeader = HttpContext.Request.Headers["Authorization"];
_logger.LogInformation("Authorization is sucessful" + authorizaionHeader);

        string verificationToken = token ?? body.message.attributes["token"];  
        _logger.LogInformation("Varifiacation token is assigned" + verificationToken);  


        // JWT token comes in `Bearer <JWT>` format substring 7 specifies the postion of first JWT char.  
        string authToken = authorizaionHeader.StartsWith("Bearer ") ? authorizaionHeader.Substring(7) : null;  

        if (string.IsNullOrEmpty(token))  
            _logger.LogInformation("token " + token);  
        //if (string.IsNullOrEmpty(body.ackId))  
        //    _logger.LogInformation("AckId " + body.ackId);  
        //if (string.IsNullOrEmpty(body.message.messageId))  
        //    _logger.LogInformation("Message Id " + body.message.messageId);  
        //if (string.IsNullOrEmpty(body.message.publishTime.ToString()))  
        //    _logger.LogInformation("PublishTime " + body.message.publishTime.ToString());  
        if (string.IsNullOrEmpty(body.message.data))  
            _logger.LogInformation("Data " + body.message.data);  

        if (verificationToken != _options.VerificationToken || authToken is null)  
        {  
            return new BadRequestResult();  
        }  
        // Verify and decode the JWT.  
        // Note: For high volume push requests, it would save some network  
        // overhead if you verify the tokens offline by decoding them using  
        // Google's Public Cert; caching already seen tokens works best when  
        // a large volume of messages have prompted a single push server to  
        // handle them, in which case they would all share the same token for  
        // a limited time window.  
        var payload = await JsonWebSignature.VerifySignedTokenAsync<PubSubPayload>(authToken);  

        // IMPORTANT: you should validate payload details not covered  
        // by signature and audience verification above, including:  
        //   - Ensure that `payload.Email` is equal to the expected service  
        //     account set up in the push subscription settings.  
        //   - Ensure that `payload.Email_verified` is set to true.  

        var messageBytes = Convert.FromBase64String(body.message.data);  
        string message = System.Text.Encoding.UTF8.GetString(messageBytes);  
        s_authenticatedMessages.Add(message);  
        return new OkResult();  
    }  
Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
59 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 15,856 Reputation points
    2022-08-09T04:21:03.293+00:00

    Hi @Mani kanta

    Thanks for the question. it looks like you're using GCP and not Azure Web Pubsub. Please try posting on their community site to get the right assistance with your issue.

    Best,
    Grace

    0 comments No comments