为 Google OAuth Android 重定向 url
Redirect url for Google OAuth Android
从未真正使用过 OAuth,现在尝试实现它,我想从 google 和 facebook 获取访问令牌和配置文件数据。使用 Xamarin.Auth。
使用 Facebook 没有问题,我将“http://www.facebook.com/connect/login_success.html”指定为重定向 url,在我登录后它又回到了我之前的 activity。
然而 Google 它并不那么流畅 - 找不到任何类似于 facebook 登录成功页面的东西,在某处找到了使用“https://www.googleapis.com/plus/v1/people/me”的建议 - 添加它以重定向 url 白名单,但是在登录后我会得到 "Redirect_url_mismatch" A native application: application name
根据他们的文档我应该使用 "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;
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}";
在上面列出的代码中,您没有给出重定向 uri,而是给出了 google api 的范围。 redirect uri 的目的是在授权后接收来自 google api 的响应。响应应为 code。此响应代码用于访问 access_token、refresh_token、id_token 等。所以你必须在你的项目中接收这个代码 side.For 这个目的,使用重定向 uri。
转到您的 google 控制台,创建项目,添加凭据,然后您将被重定向到包含
的页面
您可以找到授权的重定向url。给出 url ,然后使用新的重定向 url 配置您的代码。之后一切都会好起来的。
从未真正使用过 OAuth,现在尝试实现它,我想从 google 和 facebook 获取访问令牌和配置文件数据。使用 Xamarin.Auth。
使用 Facebook 没有问题,我将“http://www.facebook.com/connect/login_success.html”指定为重定向 url,在我登录后它又回到了我之前的 activity。
然而 Google 它并不那么流畅 - 找不到任何类似于 facebook 登录成功页面的东西,在某处找到了使用“https://www.googleapis.com/plus/v1/people/me”的建议 - 添加它以重定向 url 白名单,但是在登录后我会得到 "Redirect_url_mismatch" A native application: application name
根据他们的文档我应该使用 "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;
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}";
在上面列出的代码中,您没有给出重定向 uri,而是给出了 google api 的范围。 redirect uri 的目的是在授权后接收来自 google api 的响应。响应应为 code。此响应代码用于访问 access_token、refresh_token、id_token 等。所以你必须在你的项目中接收这个代码 side.For 这个目的,使用重定向 uri。 转到您的 google 控制台,创建项目,添加凭据,然后您将被重定向到包含
的页面您可以找到授权的重定向url。给出 url ,然后使用新的重定向 url 配置您的代码。之后一切都会好起来的。