Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return AuthenticationCallback results on the UI thread (if the AT/ATS call was invoked there) #1094

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand Down Expand Up @@ -262,13 +263,19 @@ private void setUpADALForCallingBroker() {
Telemetry.getInstance().registerDispatcher(telemetryDispatcher, true);
}

private void verifyThread() {
final boolean onUiThread = Looper.getMainLooper().getThread() == Thread.currentThread();
Log.d(TAG, "AuthenticationCallback returned on UI thread? [" + onUiThread + "]");
}

private void callAcquireTokenWithResource(final String resource, PromptBehavior prompt, final String loginHint,
final String clientId, final String redirectUri, final String extraQp) {
mAuthContext.acquireToken(MainActivity.this, resource, clientId, redirectUri, loginHint,
prompt, extraQp, new AuthenticationCallback<AuthenticationResult>() {

@Override
public void onSuccess(AuthenticationResult authenticationResult) {
verifyThread();
mAuthResult = authenticationResult;
showMessage("Response from broker: " + authenticationResult.getAccessToken());

Expand All @@ -280,6 +287,7 @@ public void onSuccess(AuthenticationResult authenticationResult) {

@Override
public void onError(Exception exc) {
verifyThread();
showMessage("MainActivity userapp:" + exc.getMessage());
}
});
Expand Down Expand Up @@ -320,12 +328,14 @@ private void callAcquireTokenSilent(final String resource, final String userUniq

@Override
public void onSuccess(AuthenticationResult authenticationResult) {
verifyThread();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

furthermore, in the method body of "showMessage", could we use something similar to:
runOnUiThread(new Runnable() {
@OverRide
public void run() {
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();
}
});

thanks

mAuthResult = authenticationResult;
showMessage("Response from broker: " + authenticationResult.getAccessToken());
}

@Override
public void onError(Exception exc) {
verifyThread();
showMessage("Error occurred when acquiring token silently: " + exc.getMessage());
}
});
Expand Down