幾天來,我一直在嘗試在 Xamarin Forms App 中實作 google OAuth。我有一個非常簡單的XAML代碼
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Google.ViewModels"
x:Class="Google.MainPage">
<ContentPage.BindingContext>
<local:MainPageViewModel/>
</ContentPage.BindingContext>
<StackLayout>
<WebView Source="{Binding OAuthRequestUrl}"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"/>
</StackLayout>
并且ViewModel:
public string OAuthRequestUrl
{
get
{
string oauthReuest = string.Format(
"https://accounts.google.com/o/oauth2/v2/auth?client_id={0}&redirect_uri={1}&response_type={2}&scope={3}",
clientId,
redirectUrl,
responceType,
scope);
return oauthReuest;
}
}
但是在 webview 初始化之后,我得到了403: disalloed_useragent. 最初,我通過瀏覽器 郵遞員成功完成了使用 Web 客戶端憑據和 OAuth。

uj5u.com熱心網友回復:
您需要更改 WebView 控制元件的用戶代理。
不幸的是,目前不支持此功能,但您會在此處找到一些解決方法:https ://github.com/xamarin/Xamarin.Forms/issues/8432
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/459780.html
標籤:C# xamarin 网络 oauth-2.0 谷歌认证
