OAuth2.0を使用してWebサイトにサインインしています。そのため、サーバーにログインしようとするたびに、有効期限、アクセストークン、更新トークンを参照する応答が返されました。問題は、サーバーから取得した所定の時間より前にトークンが期限切れになることです。だから私はサーバーの時間とiPhoneの時間の間に間隔があることを理解しています。SDK facebookのコードを見ると、この問題を処理するロジックはありません。単純な比較です。だから私の質問はサーバー側からのこの問題です私は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);
}