android - 嵌入式 Web 浏览器上的 Azure Oauth 身份验证将于 2017 年 4 月 20 日被阻止,发出警告

标签 android azure webview oauth azure-mobile-services

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.mobileprogramming.sampleappforcnac">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        tools:replace="android:icon"
        android:theme="@style/AppTheme">

        <activity android:name="com.mobileprogramming.sampleappforcnac.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity android:name="com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="cnacs://easyauth.callback"
                    android:host="easyauth.callback"/>
            </intent-filter>
        </activity>


        <activity android:name="com.microsoft.windowsazure.mobileservices.authentication.CustomTabsIntermediateActivity" android:exported="false" />
        <activity android:name="com.microsoft.windowsazure.mobileservices.authentication.CustomTabsLoginActivity" android:exported="false" android:launchMode="singleTask" />

    </application>



</manifest>
<小时/>
package com.mobileprogramming.sampleappforcnac;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.microsoft.windowsazure.mobileservices.MobileServiceActivityResult;
import com.microsoft.windowsazure.mobileservices.MobileServiceClient;
import com.microsoft.windowsazure.mobileservices.authentication.MobileServiceAuthenticationProvider;
import com.microsoft.windowsazure.mobileservices.authentication.MobileServiceUser;

import java.net.MalformedURLException;

public class MainActivity extends Activity {

    public static final int GOOGLE_LOGIN_REQUEST_CODE = 1;
    private MobileServiceClient mClient;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            mClient = new MobileServiceClient("https://cnacs.azurewebsites.net", this);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        Button aadLoginButton = (Button) findViewById(R.id.googleLogin);
        aadLoginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mClient.login("Google", "cnacs://easyauth.callback", GOOGLE_LOGIN_REQUEST_CODE);

                }
            });

            try {

             //   mClient = new MobileServiceClient("https://cnacs.azurewebsites.net", this);

            } catch (Exception e) {

                e.printStackTrace();
            }


        }


        private void authenticate() {

            ListenableFuture<MobileServiceUser> mLogin = mClient.login(MobileServiceAuthenticationProvider.Google);

            Futures.addCallback(mLogin, new FutureCallback<MobileServiceUser>() {
                @Override
                public void onFailure(Throwable exc) {
                    Toast.makeText(MainActivity.this, "You must log in. Login Required", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onSuccess(MobileServiceUser user) {
                    Toast.makeText(MainActivity.this, "You must log in. Login Required", Toast.LENGTH_LONG).show();

                }
            });

        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // When request completes
            if (resultCode == RESULT_OK) {
                // Check the request code matches the one we send in the login request
                if (requestCode == GOOGLE_LOGIN_REQUEST_CODE) {
                    MobileServiceActivityResult result = mClient.onActivityResult(data);
                    if (result.isLoggedIn()) {
                        Toast.makeText(this, "logedin", Toast.LENGTH_SHORT).show();
                        // login succeeded
    //                    createAndShowDialog(String.format("You are now logged in - %1$2s", mClient.getCurrentUser().getUserId()), "Success");
                        //     createTable();
                    } else {
                        Toast.makeText(this, "failed", Toast.LENGTH_SHORT).show();
                        // login failed, check the error message
                        String errorMessage = result.getErrorMessage();
    //                    createAndShowDialog(errorMessage, "Error");
                    }
                }
            }
        }


    }

我正在关注 azure 的以下文档

https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-android-get-started-users

我尝试过以两种方式更改回调 答:

mClient.login("Google", "cnacs://easyauth.callback", GOOGLE_LOGIN_REQUEST_CODE);

b:

 mClient.login("Google", "cnacs", GOOGLE_LOGIN_REQUEST_CODE);

也在 list 中我尝试了两种方式 答:

<data android:scheme="cnacs://easyauth.callback"
                    android:host="easyauth.callback"/>

b:

 <data android:scheme="cnacs"
                    android:host="easyauth.callback"/>

我已经尝试了两种方式,但我在 onActivityResult 中获取的用户数据为空,即使 webView 说“登录成功”。 请让我知道我应该做什么以及我在哪里做错了。 在此处输入代码

最佳答案

为了结束这个问题(并供将来引用),这个问题正在 GitHub 上讨论。并将在那里得到答复。

关于android - 嵌入式 Web 浏览器上的 Azure Oauth 身份验证将于 2017 年 4 月 20 日被阻止,发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43594573/

相关文章:

android - 尝试从 Android 在 Facebook 上共享链接时出错

android - 如何创建一个按字母顺序显示android中所有字母的滚动条?

r - 无法从shinyapps.io连接到Microsoft Azure

java - 如何将 JSONObject 转换为 JSONArray

azure - Pyspark - 获取列表 azure synapse 工作区中容器文件夹的所有内容并存储该数据

c# - Azure 搜索 : Only the whitespace should be a word delimiter

javascript - 使用 Electron 和 Asar 打包应用程序

javascript - 从 Assets 目录中的 HTML 文件设置 Android Webview cookie

android - 辅助功能 : Talkback, WebView 和用户的区域设置

android - 如何将按钮中的图标向左对齐并保持文本居中