3131import com .microsoft .aad .adal .AuthenticationCallback ;
3232import com .microsoft .aad .adal .AuthenticationCancelError ;
3333import com .microsoft .aad .adal .AuthenticationContext ;
34+ import com .microsoft .aad .adal .AuthenticationException ;
3435import com .microsoft .aad .adal .AuthenticationResult ;
3536import com .microsoft .aad .adal .PromptBehavior ;
3637import com .onedrive .sdk .core .ClientException ;
@@ -295,7 +296,7 @@ public synchronized IAccountInfo login(final String emailAddressHint) throws Cli
295296
296297 // Request a fresh auth token for the OneDrive service.
297298 final AuthenticationResult oneDriveServiceAuthToken =
298- getOneDriveServiceAuthResult (discoveryServiceAuthToken , oneDriveServiceInfo );
299+ getOneDriveServiceAuthResult (oneDriveServiceInfo );
299300
300301 // Get the OneDrive auth token and save a reference to it.
301302 final String serviceInfoAsString = mHttpProvider .getSerializer ()
@@ -394,7 +395,13 @@ public void onSuccess(final AuthenticationResult authenticationResult) {
394395
395396 @ Override
396397 public void onError (final Exception e ) {
397- error .set (new ClientAuthenticatorException ("Silent authentication failure from ADAL" ,
398+ String message = "Silent authentication failure from ADAL" ;
399+ if (e instanceof AuthenticationException ) {
400+ message = String .format ("%s; Code %s" ,
401+ message ,
402+ ((AuthenticationException )e ).getCode ().getDescription ());
403+ }
404+ error .set (new ClientAuthenticatorException (message ,
398405 e ,
399406 OneDriveErrorCodes .AuthenticationFailure ));
400407 loginSilentWaiter .signal ();
@@ -509,7 +516,13 @@ public void onError(final Exception ex) {
509516 code = OneDriveErrorCodes .AuthenticationCancelled ;
510517 }
511518
512- final String message = "Error while retrieving the discovery service auth token" ;
519+ String message = "Error while retrieving the discovery service auth token" ;
520+ if (ex instanceof AuthenticationException ) {
521+ message = String .format ("%s; Code %s" ,
522+ message ,
523+ ((AuthenticationException )ex ).getCode ().getDescription ());
524+ }
525+
513526 error .set (new ClientAuthenticatorException (message , ex , code ));
514527 mLogger .logError ("Error while attempting to login interactively" , error .get ());
515528 discoveryCallbackWaiter .signal ();
@@ -591,12 +604,10 @@ private ServiceInfo getOneDriveServiceInfoFromDiscoveryService(final String acce
591604
592605 /**
593606 * Gets the authentication token for the OneDrive service.
594- * @param authenticationResult The authentication result from the Discovery Service.
595607 * @param oneDriveServiceInfo The OneDrive services info.
596608 * @return The authentication result for this OneDrive service.
597609 */
598- private AuthenticationResult getOneDriveServiceAuthResult (final AuthenticationResult authenticationResult ,
599- final ServiceInfo oneDriveServiceInfo ) {
610+ private AuthenticationResult getOneDriveServiceAuthResult (final ServiceInfo oneDriveServiceInfo ) {
600611 final SimpleWaiter authorityCallbackWaiter = new SimpleWaiter ();
601612 final AtomicReference <ClientException > error = new AtomicReference <>();
602613 final AtomicReference <AuthenticationResult > oneDriveServiceAuthToken = new AtomicReference <>();
@@ -611,26 +622,31 @@ public void onSuccess(final AuthenticationResult authenticationResult) {
611622
612623 @ Override
613624 public void onError (final Exception e ) {
625+ String message = "Error while retrieving the service specific auth token" ;
614626 OneDriveErrorCodes code = OneDriveErrorCodes .AuthenticationFailure ;
615627 if (e instanceof AuthenticationCancelError ) {
616628 code = OneDriveErrorCodes .AuthenticationCancelled ;
617629 }
630+ if (e instanceof AuthenticationException ) {
631+ message = String .format ("%s; Code %s" ,
632+ message ,
633+ ((AuthenticationException )e ).getCode ().getDescription ());
634+ }
618635
619- error .set (new ClientAuthenticatorException ("Error while retrieving the service specific auth token" ,
636+ error .set (new ClientAuthenticatorException (message ,
620637 e ,
621638 code ));
622639 mLogger .logError ("Unable to refresh token into OneDrive service access token" , error .get ());
623640 authorityCallbackWaiter .signal ();
624641 }
625642 };
626- final String refreshToken = authenticationResult .getRefreshToken ();
627-
628643 mLogger .logDebug ("Starting OneDrive resource refresh token request" );
629- mAdalContext .acquireTokenByRefreshToken (
630- refreshToken ,
631- getClientId (),
632- oneDriveServiceInfo .serviceResourceId ,
633- authorityCallback );
644+ mAdalContext .acquireToken (mActivity ,
645+ oneDriveServiceInfo .serviceResourceId ,
646+ getClientId (),
647+ getRedirectUrl (),
648+ PromptBehavior .Auto ,
649+ authorityCallback );
634650
635651 mLogger .logDebug ("Waiting for token refresh" );
636652 authorityCallbackWaiter .waitForSignal ();
0 commit comments