从未真正使用过 OAuth,现在尝试实现它,我想从 google 和 facebook 获取访问令牌和配置文件数据。使用 Xamarin.Auth。
使用 Facebook 没有问题,我指定“http://www.facebook.com/connect/login_success.html“作为重定向网址,登录后它会返回到我之前的活动。
然而,对于谷歌来说,它并不那么顺利 - 找不到任何类似于 facebook 登录成功页面,在某处找到了使用建议“https://www.googleapis.com/plus/v1/people/me“ - 将其添加到重定向网址白名单中,但是登录后我会得到"Redirect_url_mismatch" A native application: application name
根据他们的文档,我应该使用“my.package.name:”,并再次添加它来重定向网址白名单,尝试登录,这次登录屏幕后,我进入第二个屏幕,我需要在其中确认读取权限和之后,我收到非常短的错误,例如“com.my.package:/?oauthparameterX=value1....”,并再次重定向到权限屏幕。
这是我完整的 OAuth2Authenticator:
var auth = new OAuth2Authenticator(
clientId: SocialIds.GooglePlusId,
clientSecret: SocialIds.GooglePlusSecret,
scope: OAuthUrl.GoogleScope,
authorizeUrl: new Uri(OAuthUrl.GoogleAuthorize),
redirectUrl: new Uri("https://www.googleapis.com/plus/v1/people/me"),
accessTokenUrl: new Uri("https://accounts.google.com/o/oauth2/token"),
getUsernameAsync: null);
auth.AllowCancel = false;
urls:
public static string GoogleAuthorize = "https://accounts.google.com/o/oauth2/auth";
public static string GoogleScope = "https://www.googleapis.com/auth/userinfo.email";
public static string GoogleRedirect = "https://www.googleapis.com/plus/v1/people/me";
public static string GoogleUserInfo = "https://www.googleapis.com/oauth2/v1/userinfo?access_token={0}";