使用Xamarin.Auth从Xamarin Forms App

时间:2017-10-03 04:28:45

标签: xamarin.forms xamarin.auth mobileserviceclient

我正在尝试在我的Xamarin Forms应用中使用Google身份验证,方法是使用Xamarin.Auth执行客户端身份验证,然后将收到的令牌传递到配置为使用Google身份验证的Azure App Service自定义网站后端。

我从客户端的Xamarin.Auth那里得到了令牌。但是,当我尝试使用MobileServiceClient的LoginAsync方法时,我得到一个例外情况:

Newtonsoft.Json.JsonReaderException:解析值时遇到意外的字符:<。路径'',第0行,第0位。

我发现这篇文章:Xamarin MobileServiceClient RefreshUserAsync with Google 403,其中rleffler显然有这个工作,但我不认为我可以直接给他发消息。

这是我的代码调用LoginAsync:

MobileServiceClient client = new 
MobileServiceClient("http://<mywebsite>.azurewebsites.net");

            var zumoPayload = new JObject();
            zumoPayload["access_token"] = accessToken;
            zumoPayload["id_token"] = idToken;

            if (user == null)
            {
                string message;
                try
                {
                    user = await client.LoginAsync(MobileServiceAuthenticationProvider.Google, zumoPayload);
                    message = string.Format("You are now logged in - {0}", user.UserId);
                }
                catch (Exception ex)
                {
                    //This is where I catch the JsonReaderException
                    message = "You must log in. Login Required";
                }
            }

0 个答案:

没有答案