0

We are planning to make a recommendations engine for the features in the app and we were thinking about using GCP Recommendations AI. Then, we ran into some unclear areas due to lack of examples.

When we send POST requests from iOS (swift) to GCP, is there a way to get access-token for the header field "Authorization: Bearer $(gcloud auth application-default print-access-token)" using Firebase iOS SDK? Could you please point us to some resources that we can follow. If it's not possible to do easily, what is the easiest secure method that you recommend? Any resources? example use case, we found.

Could you guys please help us with this?

VidU
  • 21
  • 3

1 Answers1

0

Calling the Google Cloud Recommendations AI API requires that you specify the OAuth2 access token for a Google account.

Firebase Authentication uses a JWT ID token to identify the users. These are not Google accounts, as for example you could create a user with email/password that Google's account system knows nothing about.

It is idiomatic to only call the Google Cloud APIs from a trusted environment, such as your development machine, a server you control, or Cloud Functions. This is done to protect yourself from abuse, as (unlike Firebase services) most Google Cloud APIs don't provide a mechanism to control access directly from the client.

So you'll typically want to wrap the GCP API in custom server-side code, that checks whether the user is authorized, and then call that from within your client-side application code.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks for the quick reply Frank van Puffelen. Could you please point us to some resources that we can follow. – VidU Oct 08 '21 at 02:52
  • If you're looking how to wrap a GCP API in Cloud Functions, have a look [here](https://www.google.com/search?q=how+to+wrap+Cloud+Vision+API+in+Cloud+Functions) or [here](https://www.google.com/search?q=how+to+wrap+a+server+API+in+Cloud+Functions). For a production-ready sample (but no tutorial), you can also look [here](https://github.com/firebase/extensions/tree/next/firestore-translate-text) or [here](https://github.com/firebase/functions-samples/tree/main/vision-annotate-images). – Frank van Puffelen Oct 08 '21 at 03:51
  • Hey @VidU. Anything else needed here? – Frank van Puffelen Oct 15 '21 at 00:03