authentication - Azure Google 身份验证显示错误 :disallowed_useragent

标签 authentication xamarin.forms google-oauth azure-mobile-services

我最近遇到了这个错误Error Message

我认为这是由于 Google Oauth 发生了这种变化:https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html .

我正在使用 Azure 身份验证服务对我用 Xamarin Forms (C#) 编写的 iOS 应用程序进行身份验证。

代码请求 Azure 身份验证服务:

var window = UIKit.UIApplication.SharedApplication.KeyWindow;
var root = window.RootViewController;
if(root != null)
{
    var current = root;
    while(current.PresentedViewController != null)
    {
        current = current.PresentedViewController;
    }

    var user = await AzureService.Instance.Client.LoginAsync(window.RootViewController, MobileServiceAuthenticationProvider.Google, new Dictionary<string, string>() { { "access_type", "offline" } });
    return user;
}

网址请求是:
using(var client = new HttpClient())
{
    const string url = "https://www.googleapis.com/oauth2/v3/userinfo?alt=json&suppress_webview_warning=true";
    client.DefaultRequestHeaders.Add("Authorization", token);
    var json = client.GetStringAsync(url).Result;
    var profile = JsonConvert.DeserializeObject<GoogleUserProfile>(json);
    return profile;
}

但是它仍然向我显示错误:
谷歌的 Azure 身份验证设置正确,因为直到最近我一直使用这个设置一个多月。任何人都有同样的问题或任何想法如何解决这个问题?

最佳答案

简短的版本是谷歌将 OAuth 协议(protocol)更改为“更安全”。我们目前正在对各种客户端 SDK 进行更新,以启用新的更安全的方法,该方法仅影响服务器流。

要做的事情的简短版本是实现客户端流。将 Google SDK 集成到您的应用中,然后将收到的 token 发送到后端。由于您在 Xamarin.Forms 中,这将意味着在特定于平台的代码中实现某些内容。

抱歉,我没有这方面的例子。我已经完成了 FB auth 和 AAD auth,但目前还没有完成 Google auth。然而,概念是相同的。您需要在特定于平台的代码中执行 Google 身份验证,然后使用类似于以下内容的方式调用 ZUMO 身份验证端点:

public async Task<MobileServiceUser> LoginAsync(MobileServiceClient client)
{
    // Call the code to do the Google Auth via the Google SDK
    var accessToken = await LoginGoogleAsync();
    // Construct and call the client-flow ZUMO auth
    var zumoPayload = new JObject();
    zumoPayload["access_token"] = accessToken;
    return await client.LoginAsync("google", zumoPayload);
}

每个 Azure 移动应用 SDK 的下一个版本都将包含 Google OAuth 更改。不幸的是,我没有这些版本的时间表。

关于authentication - Azure Google 身份验证显示错误 :disallowed_useragent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40553074/

相关文章:

Spring security with @RestController - JSONish CustomAuthenticationProvider 响应

c# - 嵌入 Xamarin Forms 或 native 嵌入

xamarin.forms - Xamarin 中的 FontAwesome 形成 UWP

google-app-engine - 错误 : invalid_client with Google Apps API OAuth2

c# - 在 C# .NET 中使用服务帐户检索 Google Analytics 数据时出现无效响应错误

java - java中基于 token 的登录和身份验证

ios - 为一个选项卡设置不同的 View Controller

php - 如何在php中设置访问权限以查看页面

xaml - 在 xamarin 中更改导航栏标题位置

google-oauth - 谷歌人 API "Request mask cannot be empty"