commit | author | age
|
a0a843
|
1 |
// |
H |
2 |
// TWTRSessionRefreshStrategy.h |
|
3 |
// TwitterCore |
|
4 |
// |
|
5 |
// Created by Kang Chen on 6/24/15. |
|
6 |
// Copyright (c) 2015 Twitter Inc. All rights reserved. |
|
7 |
// |
|
8 |
|
|
9 |
@class TWTRAuthConfig; |
|
10 |
@protocol TWTRAPIServiceConfig; |
|
11 |
@protocol TWTRBaseSession; |
|
12 |
|
|
13 |
NS_ASSUME_NONNULL_BEGIN |
|
14 |
|
|
15 |
/** |
|
16 |
* Completion block to call when done refreshing the session or it fails. |
|
17 |
* |
|
18 |
* @param refreshedSession The refreshed session |
|
19 |
* @param error Non nil error if the refresh fails. |
|
20 |
*/ |
|
21 |
typedef void (^TWTRSessionRefreshCompletion)(id _Nullable refreshedSession, NSError *_Nullable error); |
|
22 |
|
|
23 |
/** |
|
24 |
* Protocol for session refresh strategies. |
|
25 |
*/ |
|
26 |
@protocol TWTRSessionRefreshStrategy <NSObject> |
|
27 |
|
|
28 |
/** |
|
29 |
* Determines whether the strategy supports the given session class. |
|
30 |
* |
|
31 |
* @param sessionClass The class of session to check. |
|
32 |
* |
|
33 |
* @return YES if this strategy can be used to refresh the given session class. |
|
34 |
*/ |
|
35 |
+ (BOOL)canSupportSessionClass:(Class)sessionClass; |
|
36 |
|
|
37 |
/** |
|
38 |
* Determines whether the session has expired based on the API response of a previous API request made with the session. |
|
39 |
* |
|
40 |
* @param response HTTP response of a previous API request |
|
41 |
* |
|
42 |
* @return YES if the HTTP response is contains information to indicate the session is invalid or has expired. |
|
43 |
*/ |
|
44 |
+ (BOOL)isSessionExpiredBasedOnRequestResponse:(NSHTTPURLResponse *)response; |
|
45 |
|
|
46 |
/** |
|
47 |
* Determines whether the session has expired based on the API response error of a previous API request made with the session. |
|
48 |
* |
|
49 |
* @param response error a previous API request |
|
50 |
* |
|
51 |
* @return YES if the error contains information to indicate the session is invalid or has expired. |
|
52 |
*/ |
|
53 |
+ (BOOL)isSessionExpiredBasedOnRequestError:(NSError *)responseError; |
|
54 |
|
|
55 |
/** |
|
56 |
* Request to fetch a new session. |
|
57 |
* |
|
58 |
* @param session Expired session to request new one for |
|
59 |
* @param URLSession URL session to make the authentication request with |
|
60 |
* @param completion Completion block to call when done refreshing the session or it fails. |
|
61 |
*/ |
|
62 |
- (void)refreshSession:(id<TWTRBaseSession>)session URLSession:(NSURLSession *)URLSession completion:(TWTRSessionRefreshCompletion)completion; |
|
63 |
|
|
64 |
@end |
|
65 |
|
|
66 |
/** |
|
67 |
Concrete implementation of a strategy for handling expiration and refresh of guest sessions. |
|
68 |
*/ |
|
69 |
@interface TWTRGuestSessionRefreshStrategy : NSObject <TWTRSessionRefreshStrategy> |
|
70 |
|
|
71 |
/** |
|
72 |
* Initializes a new guest refresh strategy. |
|
73 |
* |
|
74 |
* @param authConfig The `authConfig` associated with the app to refresh guest sessions for |
|
75 |
* @param APIServiceConfig The API service config to configure endpoints |
|
76 |
* |
|
77 |
* @return Initialized strategy that can refresh guest sessions of the given application |
|
78 |
*/ |
|
79 |
- (instancetype)initWithAuthConfig:(TWTRAuthConfig *)authConfig APIServiceConfig:(id<TWTRAPIServiceConfig>)APIServiceConfig; |
|
80 |
- (instancetype)init __unavailable; |
|
81 |
|
|
82 |
@end |
|
83 |
|
|
84 |
NS_ASSUME_NONNULL_END |