I am trying to implment the OAuth flow for live connect through an android app. For the authentication and consent part, I am using WebView to redirect the user to the corresponding pages. The flow that I am trying to implement is -
- Launch
MyActivity. - In
onCreate(), launchauth urland wait. - User logs in using an account and is redirected to consent page.
- User agrees to access permissions.
- Parse auth code.
- Return to
MyActivityand perform actions usingauthcode.
Below is the code snippet :
public class MyActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
WebView myWebView = (WebView) findViewById(R.id.webview);
AuthFlowWebView authView = new AuthFlowWebView(); //AuthFlowWebView extends WebViewClient
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(authView);
myWebView.loadUrl("https://login.live.com/oauth20_authorize.srf?client_id=<CLIENT_ID>&scope=wl.signin%20wl.offline_access&response_type=code&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf&display=touch");
Log.i("", "Here already before the auth process is complete");
}
}
//Here is the Overriden onPageFinished method used to parse the auth code in AuthFlowWebView class:
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Thread.dumpStack();
if (url.contains("oauth20_desktop.srf?code=")) {
authSuccess = true;
Uri uri = Uri.parse(url);
authCode = uri.getQueryParameter("code");
Log.i("", "CODE : " + authCode);
authProcessComplete = true;
}
I am stuck with making MyActivity wait until steps 3-5 are complete. Please suggest alternatives to implement such a flow.