【问题标题】:Redirect Url to my app after auth 2.0 in Uber api在 Uber api 中的 oauth 2.0 之后将 URL 重定向到我的应用程序
【发布时间】:2016-10-20 05:57:17
【问题描述】:

我正在将 uber api 与我的 android 应用程序集成。在 auth 2.0 的情况下,在从 uber 成功授权后,我应该给返回 url 以重定向以进入我的应用程序。这是我的超级登录活动

    WebView webView = (WebView) findViewById(R.id.webview);

    webView.setWebViewClient(new WebViewClient());
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    webView.setScrollbarFadingEnabled(false);
    progressBar = ProgressDialog.show(UberLoginActivity.this, "Please wait", "Loading...");
    webView.loadUrl("https://login.uber.com/oauth/v2/authorize?client_id=MDyPSkkFFSZHKcntIg9j2mhM7XP665R1&response_type=code");

    SessionConfiguration config = new SessionConfiguration.Builder()
            .setClientId("***********") //This is necessary
            .setRedirectUri("what should be added ") //This is necessary if you'll be using implicit grant
            .setServerToken("*********************")
            .setEnvironment(SessionConfiguration.Environment.SANDBOX) //Useful for testing your app in the sandbox environment
            .setScopes(Arrays.asList(Scope.PROFILE, Scope.RIDE_WIDGETS)) //Your scopes for authentication here
            .build();

    webView.setWebViewClient(new WebViewClient()
    {
        public void onPageFinished(WebView view, String url)
        {
            if (progressBar.isShowing())
            {
                progressBar.dismiss();
            }
        }
        @Override
        public void onReceivedError(WebView view, int errorCode,
                                    String description, String failingUrl)
        {
            view.loadUrl("about:blank");
            Toast.makeText(getApplication(), " Please check network connectivity", Toast.LENGTH_LONG).show();
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });

【问题讨论】:

    标签: android web-services url-redirection uber-api


    【解决方案1】:

    在 android 上最好使用 SSO 进行处理。查看android小部件教程中的相关代码:https://developer.uber.com/docs/ride-requests/tutorials/widget/android#login

    这将使用 uber 应用对用户进行身份验证,否则将重定向到应用商店。如果您仍然喜欢使用 webview,请跟进。

    【讨论】:

    • 但我得到了错误 - 无效的身份验证 2.0 凭据..!
    • 我没有使用 uber 小部件。我使用超级客户端库集成。我需要重定向 uri 的格式
    • 使用客户端库,您可以实现 sso 登录,这对您的用户来说是一个更好的体验。否则,请参阅格式化您的 oauth 请求的正确方法:developer.uber.com/docs/ride-requests/guides/authentication/…。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    相关资源
    最近更新 更多