使用Azure功能进行Google身份验证

时间:2018-05-29 12:33:49

标签: azure xamarin xamarin.forms google-login azure-authentication

我想要完成的是用户应该使用我的Xamarin表单应用程序登录谷歌,然后该应用程序应验证用户令牌服务器端。 所以我已经使用Xamarin.Auth在Xamarin中实现了登录,并且能够获得这些令牌:

  • 的access_token
  • refresh_token
  • id_token

当我阅读Azure功能身份验证的文档时,我应该发出POST请求并将id_token作为client_id提供给https://mysite.azurewebsites.net/.auth/login/google 在体内作为JSON。

这导致

  

400 - 无效的客户端凭据

来自邮递员。

在Google APIS / Services中,我有一个带有两个凭据的应用

  • 用于Android for my App
  • 用于我的Azure功能的Web应用程序

我按照指南在我的Azure功能中使用App id和secret启用了Google身份验证。

Xamarin代码:

    public partial class LoginPage : ContentPage
    {
        public static OAuth2Authenticator Auth;
        public AuthenticatorPage AuthPage;
        public LoginPage()
        {
            InitializeComponent();

            Auth = new OAuth2Authenticator(
                "AndroidGoogleApiIdString.apps.googleusercontent.com",
                string.Empty,
                "email",
                new Uri("https://accounts.google.com/o/oauth2/v2/auth"),
                new Uri("com.companyname.AppName:/oauth2redirect"),
                new Uri("https://www.googleapis.com/oauth2/v4/token"),
                null,
                true);

            Auth.CreateRequestQueryParameters(new System.Collections.Generic.Dictionary<string, string>()
            {
                {"requestServerAuthCode", "AzureFunctionGoogleAppIdString.apps.googleusercontent.com" },
                {"response_type", "code" }
            });

            AuthPage = new AuthenticatorPage(Auth);

            Auth.Completed += Auth_Completed;
            Auth.Error += Auth_Error;
        }

        ...
}

Azure功能设置。 Azure function authentication screenshot

0 个答案:

没有答案