Omkar008 commited on
Commit
0c2ac5a
·
verified ·
1 Parent(s): 5cd03a9

Create authenticate.py

Browse files
Files changed (1) hide show
  1. 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