7

我相當最近Error MessageAzure的谷歌認證顯示錯誤:disallowed_useragent

我認爲這是遇到了這個錯誤,由於這一變化在谷歌的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; 
} 

的URL請求是:

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的身份驗證是否設置正確,因爲我有直到最近一直在使用這種設置一個月。任何人都有同樣的問題或任何想法如何解決這個問題?

+0

我正在處理同樣的問題,我得到的所有建議都是用原生iOS代碼編寫的。我正在處理前端使用JS和HTML的傳統Ruby on Rails應用程序。我沒有用JS做OAuth。我是Ruby的任何東西,但我認爲這個改變基本上殺了我的獨立應用程序。 –

回答

4

簡短的說法是Google將OAuth協議更改爲「更安全」。我們目前正在對各種客戶端SDK進行更新,以啓用新的更安全的方法,該方法僅影響服務器流。

做什麼的簡短版本是實現客戶端流。將Google SDK集成到您的應用中,然後將收到的令牌發送到後端。既然你在Xamarin.Forms中,這將意味着在平臺特定的代碼中實現一些東西。

對不起,我沒有這方面的例子。我已經完成了FB認證和AAD認證,但是目前還沒有Google認證。然而,這些概念是相同的。你需要使用一個類似於此做谷歌驗證在你的平臺相關的代碼,然後調用謨身份驗證的端點:

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的下一個版本將包括谷歌OAuth的變化。不幸的是,我沒有這些版本的時間表。

+0

在Google博客中,他們說我們可以在請求URL中添加「suppress_webview_warning = true」來暫時避免錯誤,但我不確定是否將它添加到了正確的位置。對於您發佈的代碼,LoginGoogleAsync函數裏面有什麼? –

+0

LoginGoogleAsync()方法是觸發Google SDK身份驗證的調用。您必須在該方法中通過其客戶端SDK實施Google Auth,並返回您接收的訪問令牌。 –

+0

任何時間表?我們不能等待這個固定的... – Ben