【问题标题】:Redirect url for Google OAuth AndroidGoogle OAuth Android 的重定向网址
【发布时间】: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


    【解决方案1】:

    在上面列出的代码中,您没有给出重定向 uri,而是给出了 google api 的范围。重定向 uri 的目的是在授权后接收来自 google api 的响应。响应应该是一个代码。此响应码用于访问 access_token、refresh_token、id_token 等。因此,您必须在项目端接收此代码。为此,使用了重定向 uri。 转到您的 google 控制台,创建项目,添加凭据,然后您将被重定向到包含的页面,

    您可以找到授权的重定向网址。提供 url ,然后使用新的重定向 url 配置您的代码。之后一切都会好起来的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-12
      • 2018-03-20
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多