Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
gcloud-flask-oauth-cors
Advanced tools
A tiny utility to authenticate requests using GCP OAuth and send CORS headers in Flask
Please note: This is not an officially supported Google product.
If you are using OAuth to authenticate to a Cloud Function written in Python and hosted on GCP, and your client is running in a browser, this is for you. If not, you probably won't find this useful.
This class does three things:
Authorization
HTTP header, validates it, and then fetches the information encoded by the tokenYou can install the latest version of this package using pip:
python3 -m pip install --user gcloud-flask-oauth-cors
It's hosted on pypi: https://pypi.org/project/gcloud-flask-oauth-cors/
If you don't have one, create an OAuth client ID and pass it as an environment variable to your cloud function. Then, you can use the following:
import gcloud_flask_oauth_cors as oauth
def my_function_name(request):
auth = oauth.Auth(os.getenv("OAUTH_CLIENT_ID"))
id_info = auth.get_id_info(request)
if id_info is None:
# If we were called with the HTTP OPTIONS method, this will return the relevant CORS headers.
# If another HTTP method was used and we can't authenticate, this will return a 401 (Unauthorized)
return auth.get_response()
# Do something with the id_info, for example:
print(id_info["sub"])
On the client side, you can use Google Sign-in. Make sure you pass your id_token
in any requests like this:
let xhr = new XMLHttpRequest();
xhr.setRequestHeader("Authorization", "Bearer " + id_token);
FAQs
A tiny utility to authenticate requests using GCP OAuth and send CORS headers in Flask
We found that gcloud-flask-oauth-cors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.