【发布时间】:2016-11-21 03:54:37
【问题描述】:
从来没有真正使用过 OAuth,现在尝试实现它,我想从 google 和 facebook 获取访问令牌和配置文件数据。使用 Xamarin.Auth。
使用 Facebook 没有问题,我将“http://www.facebook.com/connect/login_success.html”指定为重定向 url,登录后它会返回到之前的活动。
但是,使用 Google 并不顺利 - 找不到与 facebook 登录成功页面类似的页面,在某处找到了使用“https://www.googleapis.com/plus/v1/people/me”的建议 - 将其添加到重定向 url 白名单,但登录后我会得到@ 987654323@根据他们的文档,我应该使用“my.package.name:”,然后我再次添加了重定向url白名单,尝试登录,这一次在登录屏幕后我进入第二个屏幕,我需要确认阅读权限,然后我收到非常短的错误,例如“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;
网址:
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}";
【问题讨论】:
标签: android xamarin oauth xamarin.android google-oauth