Description
Aim
To simplify the OAuth authentication and terminate reliance on pickle module to make the code more redundant while retaining the core functionality.
Details
#3094
The latest code features the following code to handle authentication:
`def _auth():
creds = None
if os.path.exists("token.json"):
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
"credentials.json", SCOPES
)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open("token.json", "w") as token:
token.write(creds.to_json())
service = build("calendar", "v3", credentials=creds)
return service`
A global variable 'SCOPES' is used to define "https://www.googleapis.com/auth/calendar".
Record
- I agree to follow this project's Code of Conduct
- I'm a GSSoC'23 contributor
- I want to work on this issue