【发布时间】:2015-05-03 12:37:20
【问题描述】:
我想通过谷歌登录验证用户,我从前端获取授权码,我想用它来换取谷歌的访问令牌。
这是我的代码:
[Route("google")]
public object Google(AuthModel model) {
IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer {
ClientSecrets = new ClientSecrets {
ClientId = model.ClientId,
ClientSecret = Constants.Constants.GOOGLE_SECRET
},
Scopes = new[] { "https://www.googleapis.com/auth/plus.login" }
});
var token = flow.ExchangeCodeForTokenAsync("", model.Code, "postmessage",
CancellationToken.None).Result;
return token.AccessToken;
}
调用方法flow.ExchangeCodeForTokenAsync时出现错误
{"Error:\"redirect_uri_mismatch\", Description:\"\", Uri:\"\""}
我不明白,我可以在哪里定义重定向 URL?我花了几个小时在谷歌上搜索这个问题,答案都说我应该在我的谷歌应用程序帐户中定义一些 URL,我现在有:
Redirect URIs
http://localhost:53906
http://localhost:53906/authcallback
【问题讨论】:
-
ExchangeCodeForTokenAsync的第三个参数应该是重定向URI,我不认为
postmessage是你要使用的值。 -
查看开发者控制台定义重定向 uri
标签: c# asp.net .net google-plus google-api-dotnet-client