2012-07-31 192 views
1

我使用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); 

}

回答

1

不幸的是,沒有什麼好的機制來檢查客戶端之間的時滯和服務器。我會堅持簡單的檢查,因爲有更少的代碼需要維護和調試。無論您檢查多少,您仍需要處理找回TOKEN EXPIRED錯誤。