Spaces:
Sleeping
Sleeping
Create authenticate.py
Browse files- authenticate.py +16 -0
authenticate.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from google.oauth2 import service_account
|
2 |
+
from google.auth.transport.requests import Request
|
3 |
+
import json
|
4 |
+
|
5 |
+
def get_access_token():
|
6 |
+
# Load service account credentials from JSON file or environment variable
|
7 |
+
credentials = service_account.Credentials.from_service_account_info(
|
8 |
+
json.loads('ACCOUNT_CREDS'),
|
9 |
+
scopes=['https://www.googleapis.com/auth/cloud-platform']
|
10 |
+
)
|
11 |
+
|
12 |
+
# Refresh token if needed
|
13 |
+
if credentials.expired:
|
14 |
+
credentials.refresh(Request())
|
15 |
+
|
16 |
+
return credentials.token
|