Accessing Authenticated Cloud Run Services from a React Frontend

My frontend is in React, and I have deployed an authenticated Cloud Run service for the backend. I want to access this service through a token generated by code written in the frontend itself. I have analyzed multiple docs, but In React Google-auth library is not supporting in my case , and I'm not able to generate a token from the frontend itself. Is there any solution for this?

Is there any token available with a longer expiration time, like more than a month if available i can use it further ? In that case, is a refresh token helpful? Please suggest if any solution is available.

Solved Solved
0 4 109
1 ACCEPTED SOLUTION

You can use api key to authenticate to "token generation backend" cloud run. And in return it will give you the token required to authenticate to other service.

View solution in original post

4 REPLIES 4

You can use api gateway and generate a key, which will be used for authentication to cloud run.

Otherwise migrate your token generation code to backend and use google auth library to generate token and use it for authentication to cloud run.

Even if I migrate the token generation code to the backend, I still need to deploy the backend on an authenticated Cloud Run service. In that case, I won't be able to call the endpoint itself, so it won't help.

You can use api key to authenticate to "token generation backend" cloud run. And in return it will give you the token required to authenticate to other service.

Okay,got it! thank you.