Google OAuth在WP8.1.Runtime或WinStoreApp 8.1中失败
我有一个谷歌认证的例子,它工作了,但现在它失败了,不明白为什么 现在它给出了类似于 而在那之前,我和Google OAuth在WP8.1.Runtime或WinStoreApp 8.1中失败,oauth,google-oauth,Oauth,Google Oauth,我有一个谷歌认证的例子,它工作了,但现在它失败了,不明白为什么 现在它给出了类似于 而在那之前,我和 code=4/ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 我正在使用 GoogleClientId = TTTTTTTTT GoogleCallbackUrl = "urn:ietf:wg:oauth:2.0:oob"; var googleUrl = "https://accounts.google.com/o/oauth2/auth?cl
code=4/ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
我正在使用
GoogleClientId = TTTTTTTTT
GoogleCallbackUrl = "urn:ietf:wg:oauth:2.0:oob";
var googleUrl = "https://accounts.google.com/o/oauth2/auth?client_id=" + Uri.EscapeDataString(GoogleClientId) + "&redirect_uri=" + Uri.EscapeDataString(GoogleCallbackUrl) + "&response_type=code&scope=" + Uri.EscapeDataString("https://www.googleapis.com/auth/userinfo.profile");
var startUri = new Uri(googleUrl);
var endUri = new Uri("https://accounts.google.com/o/oauth2/approval?");
什么是错误的或更改的?看起来您的作用域和回调URI不正确。作用域应为openid格式。有关作用域的更多信息,请参阅 您的回调似乎也不正确。回调需要是一个url。您下载的json文件中有一个urn,但是如果在线查看您的凭据,您将注意到一个重定向uri(我有localhost)。有关重定向的更多信息,请参阅 这个请求对我来说很有效: 我需要做
#if !WINDOWS_PHONE_APP
public const string GoogleCallbackUrl = "urn:ietf:wg:oauth:2.0:oob";
#else
public const string GoogleCallbackUrl = "http://localhost";
#endif
然后
public async Task<Session> LoginAsync()
{
var googleUrl = new StringBuilder();
googleUrl.Append("https://accounts.google.com/o/oauth2/auth?client_id=");
googleUrl.Append(Uri.EscapeDataString(Constants.GoogleClientId));
googleUrl.Append("&scope=openid%20email%20profile");
googleUrl.Append("&redirect_uri=");
googleUrl.Append(Uri.EscapeDataString(Constants.GoogleCallbackUrl));
googleUrl.Append("&state=foobar");
googleUrl.Append("&response_type=code");
var startUri = new Uri(googleUrl.ToString());
#if !WINDOWS_PHONE_APP
var endUri = new Uri("https://accounts.google.com/o/oauth2/approval?");
var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.UseTitle, startUri, endUri);
return await GetSession(webAuthenticationResult);
#else
WebAuthenticationBroker.AuthenticateAndContinue(startUri, new Uri(Constants.GoogleCallbackUrl), null, WebAuthenticationOptions.None);
return null;
#endif
public异步任务LoginAsync()
{
var googleUrl=new StringBuilder();
googleUrl.Append(“https://accounts.google.com/o/oauth2/auth?client_id=");
Append(Uri.EscapeDataString(Constants.GoogleClientId));
Append(&scope=openid%20email%20profile”);
追加(“&redirect_uri=”);
Append(Uri.EscapeDataString(Constants.GoogleCallbackUrl));
Append(“&state=foobar”);
Append(“&response_type=code”);
var startUri=新Uri(googleUrl.ToString());
#如果!WINDOWS\u PHONE\u应用程序
var endUri=新Uri(“https://accounts.google.com/o/oauth2/approval?");
var webAuthenticationResult=等待WebAuthenticationBroker.authenticateSync(WebAuthenticationOptions.usetTitle、startUri、endUri);
返回等待GetSession(webAuthenticationResult);
#否则
WebAuthenticationBroker.AuthenticateAndContinue(startUri,新Uri(Constants.GoogleCallbackUrl),null,WebAuthenticationOptions.None);
返回null;
#恩迪夫
请参见此处的完整代码:
奇怪的是,我遵循文档。您可以在此处看到:我认为您的范围不正确。请参见此处:还有您的callbackUri,请参见感谢帮助,该url适用于Windows Phone 8.1运行时,但不适用于Windows应用商店应用程序8.1…您可以在此处看到最终结果: