commit | author | age
|
655e66
|
1 |
/* |
H |
2 |
* Copyright (C) 2017 Twitter, Inc. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
* |
|
16 |
*/ |
|
17 |
|
a0a843
|
18 |
@class TWTRAuthConfig; |
H |
19 |
@protocol TWTRAPIServiceConfig; |
|
20 |
@protocol TWTRBaseSession; |
|
21 |
|
|
22 |
NS_ASSUME_NONNULL_BEGIN |
|
23 |
|
|
24 |
/** |
|
25 |
* Completion block to call when done refreshing the session or it fails. |
|
26 |
* |
|
27 |
* @param refreshedSession The refreshed session |
|
28 |
* @param error Non nil error if the refresh fails. |
|
29 |
*/ |
|
30 |
typedef void (^TWTRSessionRefreshCompletion)(id _Nullable refreshedSession, NSError *_Nullable error); |
|
31 |
|
|
32 |
/** |
|
33 |
* Protocol for session refresh strategies. |
|
34 |
*/ |
|
35 |
@protocol TWTRSessionRefreshStrategy <NSObject> |
|
36 |
|
|
37 |
/** |
|
38 |
* Determines whether the strategy supports the given session class. |
|
39 |
* |
|
40 |
* @param sessionClass The class of session to check. |
|
41 |
* |
|
42 |
* @return YES if this strategy can be used to refresh the given session class. |
|
43 |
*/ |
|
44 |
+ (BOOL)canSupportSessionClass:(Class)sessionClass; |
|
45 |
|
|
46 |
/** |
|
47 |
* Determines whether the session has expired based on the API response of a previous API request made with the session. |
|
48 |
* |
|
49 |
* @param response HTTP response of a previous API request |
|
50 |
* |
|
51 |
* @return YES if the HTTP response is contains information to indicate the session is invalid or has expired. |
|
52 |
*/ |
|
53 |
+ (BOOL)isSessionExpiredBasedOnRequestResponse:(NSHTTPURLResponse *)response; |
|
54 |
|
|
55 |
/** |
|
56 |
* Determines whether the session has expired based on the API response error of a previous API request made with the session. |
|
57 |
* |
|
58 |
* @param response error a previous API request |
|
59 |
* |
|
60 |
* @return YES if the error contains information to indicate the session is invalid or has expired. |
|
61 |
*/ |
|
62 |
+ (BOOL)isSessionExpiredBasedOnRequestError:(NSError *)responseError; |
|
63 |
|
|
64 |
/** |
|
65 |
* Request to fetch a new session. |
|
66 |
* |
|
67 |
* @param session Expired session to request new one for |
|
68 |
* @param URLSession URL session to make the authentication request with |
|
69 |
* @param completion Completion block to call when done refreshing the session or it fails. |
|
70 |
*/ |
|
71 |
- (void)refreshSession:(id<TWTRBaseSession>)session URLSession:(NSURLSession *)URLSession completion:(TWTRSessionRefreshCompletion)completion; |
|
72 |
|
|
73 |
@end |
|
74 |
|
|
75 |
/** |
|
76 |
Concrete implementation of a strategy for handling expiration and refresh of guest sessions. |
|
77 |
*/ |
|
78 |
@interface TWTRGuestSessionRefreshStrategy : NSObject <TWTRSessionRefreshStrategy> |
|
79 |
|
|
80 |
/** |
|
81 |
* Initializes a new guest refresh strategy. |
|
82 |
* |
|
83 |
* @param authConfig The `authConfig` associated with the app to refresh guest sessions for |
|
84 |
* @param APIServiceConfig The API service config to configure endpoints |
|
85 |
* |
|
86 |
* @return Initialized strategy that can refresh guest sessions of the given application |
|
87 |
*/ |
|
88 |
- (instancetype)initWithAuthConfig:(TWTRAuthConfig *)authConfig APIServiceConfig:(id<TWTRAPIServiceConfig>)APIServiceConfig; |
7be7ad
|
89 |
- (instancetype)init __unavailable; |
a0a843
|
90 |
|
H |
91 |
@end |
|
92 |
|
|
93 |
NS_ASSUME_NONNULL_END |