我正在尝试OAuth通过 android 应用程序实现实时连接的流程。对于身份验证和同意部分,我使用WebView将用户重定向到相应的页面。我试图实现的流程是 -
- 启动MyActivity。
- 在onCreate()中,启动auth url并等待。
- 用户使用帐户登录并被重定向到同意页面。
- 用户同意访问权限。
- 解析授权码。
- 返回并使用代码MyActivity执行操作。auth
下面是代码片段:
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;
            } 
我坚持要MyActivity等到步骤 3-5 完成。请提出替代方案来实施这种流程。