I have a desktop program that requires user permissions to access a Sharepoint list. I have implemented the necessary structure to authenticate a user and retrieve its token with acquire_token_silent() method. As uploading into a list may take some time, I want to make sure the token is refreshed. I can not make the user login again because that would stop the uploading process due to the redirect to the login form. After doing some research I have implemented the next code:
Before uploading data refresh token and check:
token = _get_token_from_cache(MYSCOPE)
if not token:
return redirect(login page)
During the data upload:
token = _get_token_from_cache(MYSCOPE)
if not token:
token = methodB(MYSCOPE)
if not token:
return redirect(login page)
The function methodB is:
def methodB(scope):
cache = _load_cache()
a = _build_msal_app(cache=cache)
accounts = cca.get_accounts()
if accounts: # So all account(s) belong to the current signed-in user
result = a.acquire_token_silent(scope, account=accounts[0])
if not result:
result = app.acquire_token_by_xxx(scope)
_save_cache(cache)
return result
As in the beginning, I already check if the user is loged I would like to know if there is any way to avoid the login redirect during the uploading process. Thanks in advance.