如何解决Oauth2 / Xamarin-Google显示其主页
我试图通过Google获取用户名和邮件地址。但是,在用户登录后,Google会打开Google Hompepage,并且不会向应用返回任何内容。
为什么会这样,我该如何解决?
using Xamarin.Auth;
namespace test.Services
{
public class AuthenticationState
{
public static OAuth2Authenticator Authenticator;
}
public static class AuthConstants
{
public static string AppName = "test";
public static string GoogleClientId = @"396035829574-7qh2vrbindbm.....apps.googleusercontent.com";
public static string GoogleClientSecret = @"r8lqPTr5D....";
public static string GoogleAuthorizeUrl = @"https://accounts.google.com/o/oauth2/auth";
//public static string GoogleAccesstokenUrl = @"https://accounts.google.com/o/oauth2/token";
public static string GoogleAccesstokenUrl = @"https://www.googleapis.com/oauth2/v4/token";
public static string GoogleAndroidRedirectUrl = @"com.googleusercontent.apps.396035829574-7qh2vrbin..:/oauth2redirect";
public static string GoogleScope = @"https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile";
//public static string GoogleScope = @"email";
}
}
auth = new OAuth2Authenticator(AuthConstants.GoogleClientId,string.Empty,AuthConstants.GoogleScope,new Uri(AuthConstants.GoogleAuthorizeUrl),new Uri(AuthConstants.GoogleAndroidRedirectUrl),new Uri(AuthConstants.GoogleAccesstokenUrl),null,true);
authPresenter.Completed += (sender,args) => {
var request = new OAuth2Request("GET",new Uri("https://www.googleapis.com/oauth2/v2/userinfo"),args.Account);
Task<Response> googleResponse = request.GetResponseAsync();
googleResponse.Wait();
var googleUser = JsonValue.Parse(googleResponse.Result.GetResponseText());
userInfo.Add("username",googleUser["email"]);
userInfo.Add("password",googleUser["id"]);
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。