【发布时间】:2013-10-19 06:00:37
【问题描述】:
按照previous question posted here,我正在尝试从服务器应用程序使用日历服务。
我“自己”管理身份验证流程,并将用户的访问令牌和刷新令牌存储在数据库中。现在我想我可以使用 .NET 客户端示例中显示的方法来使用CalendarService。但我仍然想知道 IAuthorizationState GetAuthorization(WebServerClient client) 方法的最佳实现是什么,以便仅在需要时请求刷新访问令牌。我当前的幼稚实现每次都会刷新令牌:
private IAuthorizationState GetAuthorization(WebServerClient client)
{
IAuthorizationState state = new AuthorizationState(new[] { "profile", CalendarService.Scopes.Calendar.GetStringValue() });
state.AccessToken = _accessToken;
state.RefreshToken = _refreshToken;
client.RefreshToken(state);
return state;
}
...但我确信有更聪明的方法可以做到这一点!
提前致谢。
【问题讨论】:
标签: c# authentication oauth-2.0 google-oauth google-api-dotnet-client