Google使用Xamarin表单登录时出现错误400 redirect_uri_missmatch

时间:2018-07-25 07:24:15

标签: android xamarin xamarin.forms google-oauth

我已按照以下Google登录https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/authentication/oauth指南进行操作,并以本示例https://developer.xamarin.com/samples/xamarin-forms/WebServices/OAuthNativeFlow/为参考。

按照步骤,我创建了Android和iOS客户端ID,但对于android,我没有任何重定向URL选项。

public static class Constants
{
    public static string AppName = "TestingLogin";

    // OAuth
    // For Google login, configure at https://console.developers.google.com/
    public static string iOSClientId = "clientID";
    public static string AndroidClientId = "clientID";

    // These values do not need changing
    public static string Scope = "https://www.googleapis.com/auth/userinfo.email";
    public static string AuthorizeUrl = "https://accounts.google.com/o/oauth2/auth";
    public static string AccessTokenUrl = "https://www.googleapis.com/oauth2/v4/token";
    public static string UserInfoUrl = "https://www.googleapis.com/oauth2/v2/userinfo";

    // Set these to reversed iOS/Android client ids, with :/oauth2redirect appended
    public static string iOSRedirectUrl = "<insert IOS redirect URL here>:/oauth2redirect";
    public static string AndroidRedirectUrl = "http://weblogin.bestokleen.com/googleindex.aspx:/oauth2redirect";
}

请检查图像以供参考。我添加了android客户端ID,但是在console.developers.google.com上找不到任何针对android的重定向网址。因此,我创建了一个Web客户端并注册了一个可在Web浏览器中使用的重定向URL,因此我在项目中使用了该特定的重定向URL,但遇到了同样的错误。

现在,我尝试放置Web客户端ID和redirectURL而不是Android客户端ID,但仍然遇到如图所示的相同错误。

The error

1 个答案:

答案 0 :(得分:0)

从您的第一个链接:

  

因此,使用自定义URL方案的重定向URL的完整示例为com.googleusercontent.apps.<client ID>:/oauth2redirect

无论如何,Android客户端ID看起来像<What I called Client ID>.apps.googleusercontent.com。因此,通过将反向链接的Android客户端ID用作重定向URL,您可能会成功。

无论如何,我在Android和iOS上都成功使用了<my package name>:/oauth2redirect(类似com.yourcompany.yourapp:/oauth2redirect),但是不要问我是否还有其他步骤。

编辑

也是从第一个链接开始(see here

  

必须将IntentFilter的DataSchemes属性设置为从Google API控制台上的项目的Android客户端ID获取的反向客户端标识符。

这支持我对其他信息的推测。