@@ -487,15 +487,16 @@ def set_proxy(self, proxy_server, proxy_port, proxy_username,
487
487
@property
488
488
def msal_client (self ):
489
489
""" Returns the msal client or creates it if it's not already done """
490
- if self .auth_flow_type == 'public' :
491
- client = PublicClientApplication (client_id = self .auth [0 ], authority = self ._msal_authority )
492
- elif self .auth_flow_type in ('authorization' , 'credentials' ):
493
- client = ConfidentialClientApplication (client_id = self .auth [0 ], client_credential = self .auth [1 ],
494
- authority = self ._msal_authority )
495
- else :
496
- raise ValueError ('"auth_flow_type" must be "authorization", "public" or "credentials"' )
497
- self ._msal_client = client
498
- return client
490
+ if self ._msal_client is None :
491
+ if self .auth_flow_type == 'public' :
492
+ client = PublicClientApplication (client_id = self .auth [0 ], authority = self ._msal_authority )
493
+ elif self .auth_flow_type in ('authorization' , 'credentials' ):
494
+ client = ConfidentialClientApplication (client_id = self .auth [0 ], client_credential = self .auth [1 ],
495
+ authority = self ._msal_authority )
496
+ else :
497
+ raise ValueError ('"auth_flow_type" must be "authorization", "public" or "credentials"' )
498
+ self ._msal_client = client
499
+ return self ._msal_client
499
500
500
501
def get_token_with_msal_simple (self , requested_scopes = None ):
501
502
""" Gets the token using"""
@@ -544,7 +545,7 @@ def get_authorization_url(self, requested_scopes=None,
544
545
if not scopes :
545
546
raise ValueError ('Must provide at least one scope' )
546
547
547
- flow = self ._msal_client .initiate_auth_code_flow (scopes = scopes , redirect_uri = redirect_uri )
548
+ flow = self .msal_client .initiate_auth_code_flow (scopes = scopes , redirect_uri = redirect_uri )
548
549
549
550
return flow .get ('auth_uri' ), flow
550
551
@@ -569,17 +570,17 @@ def request_token(self, authorization_url, *,
569
570
parsed = urlparse (authorization_url )
570
571
query_params_dict = {k : v [0 ] for k , v in parse_qs (parsed .query ).items ()}
571
572
572
- result = self ._msal_client .acquire_token_by_auth_code_flow (flow , auth_response = query_params_dict )
573
-
573
+ result = self .msal_client .acquire_token_by_auth_code_flow (flow , auth_response = query_params_dict )
574
+ print ( result )
574
575
if "access_token" not in result :
575
576
log .error ('Unable to fetch auth token. Error: {}' .format (result .get ("error" )))
576
577
return False
577
578
else :
578
579
access_token = result ["access_token" ]
579
580
# TODO: retrieve token data from results and create a Token object with it
580
581
# How to pass this Token object into msal again?
581
- if store_token :
582
- self .token_backend .save_token ()
582
+ # if store_token:
583
+ # self.token_backend.save_token()
583
584
584
585
return True
585
586
0 commit comments