OAuth刷新令牌错误
问题描述:
我使用OAuth 2.0登录到网站。所以每次当我尝试登录到服务器时,我都得到了一个引用过期日期,访问令牌和刷新令牌的响应。问题是令牌在我从服务器获得给定时间之前过期。所以我发现服务器的时间与iPhone的时间之间有一段时间间隔。当我查看SDK的Facebook的代码没有逻辑来处理这个问题,这是一个简单的比较。所以我的问题是从服务器端的这个问题,我的意思是OAuth的实施是不正确的或这是客户端的问题?OAuth刷新令牌错误
Facebook的代码:
- (BOOL)isSessionValid {
return (self.accessToken != nil && self.expirationDate != nil
&& NSOrderedDescending == [self.expirationDate compare:[NSDate date]]);
}
我的代码:
// Get the remaining period of the token to expire and subtract 30 sec
int delay = ([expirationDate timeIntervalSinceDate:serverDateTaken] - 30);
// Save the new Expiring date
objectOAuth.expiresIn = [[[NSDate date] dateByAddingTimeInterval:delay] description];
+ (BOOL)isSessionValid
{
// Get expiration date
OAuth *authParam = [Connection getSessionParameters];
// Formating
static NSString *timeZone = @"UTC";
NSDate *expirationDate = [Connection getDateFromString:authParam.expiresIn withTimeZone:timeZone];
// get the remaining period
int diff = [expirationDate timeIntervalSinceNow];
// Check if it's expired
return (diff <= 0);
}
答
不幸的是,没有什么好的机制来检查客户端之间的时滞和服务器。我会坚持简单的检查,因为有更少的代码需要维护和调试。无论您检查多少,您仍需要处理找回TOKEN EXPIRED错误。