Xamarin表单中的Google身份验证

问题描述 投票:1回答:2

我试图在Xamarin Forms应用程序中验证用户。我相信每个平台都必须采用不同的方式,所以我在MainActivity中使用一个函数来验证应用程序何时启动。我在他们的网站上使用了Google .NET文档但我收到了一些错误。

我直接复制了Google代码,并通过嵌入式资源获取了credentials.json。当我尝试使用GoogleWebAuthorizationBroker.AuthorizeAsync设置凭据时,会出现此问题。在Google代码中,credPath设置为token.json。我得到一个错误,我没有这个权限。然后我尝试使用Android.OS.Environment.ExternalStorageDirectory,现在我得到了多个错误。我看不到个别错误,只有System.AggregateException:发生了一个或多个错误。

UserCredential credential;
var assembly = typeof(MainActivity).GetTypeInfo().Assembly;
using (var stream = 
assembly.GetManifestResourceStream("Briefing.Droid.credentials.json"))
{
   // The file token.json stores the user's access and refresh tokens, and is created
   // automatically when the authorization flow completes for the first time.
   string credPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "token.json");
   credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
   GoogleClientSecrets.Load(stream).Secrets,
   Scopes,
    "user",
    CancellationToken.None,
    new FileDataStore(credPath, true)).Result;
    Console.WriteLine("Credential file saved to: " + credPath);
 }

我希望打开一个窗口,允许用户使用他们的谷歌帐户登录。我收到System.AggregateException:发生了一个或多个错误。

c# xamarin.forms xamarin.android google-authentication
2个回答
0
投票

你在哪里知道一切都必须在Native代码中完成?使用社交网络进行身份验证是非常常见的情况,并且已经有大多数绑定库。这个用于Google身份验证https://causerexception.com/2017/12/03/google-native-login-with-xamarin-forms/


0
投票
© www.soinside.com 2019 - 2024. All rights reserved.