嵌入式Web浏览器上的Azure

嵌入式Web浏览器上的Azure

 <?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");
                    }
                }
            }
        }


    }


我正在从蔚蓝关注以下文档

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


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

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


b:

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


在清单中我也尝试了两种方法
 A:

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


b:

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


我已经尝试了两种方式,但是即使在webView说SignedIn Successl时,我也在onActivityResult中将用户数据获取为null。
请让我知道我在做什么,在哪里做错了。 enter code here

最佳答案

刚结束时(供将来参考),此问题正在GitHub上讨论,并将在此处回答。

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

10-11 04:15