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 |
|
|
18 |
/** |
|
19 |
This header is private to the Twitter Core SDK and not exposed for public SDK consumption |
|
20 |
*/ |
a0a843
|
21 |
|
H |
22 |
@class TWTRAuthConfig; |
|
23 |
@protocol TWTRAPIServiceConfig; |
|
24 |
@protocol TWTRBaseSession; |
|
25 |
|
|
26 |
NS_ASSUME_NONNULL_BEGIN |
|
27 |
|
|
28 |
/** |
|
29 |
* Completion block to call when done refreshing the session or it fails. |
|
30 |
* |
|
31 |
* @param refreshedSession The refreshed session |
|
32 |
* @param error Non nil error if the refresh fails. |
|
33 |
*/ |
|
34 |
typedef void (^TWTRSessionRefreshCompletion)(id _Nullable refreshedSession, NSError *_Nullable error); |
|
35 |
|
|
36 |
/** |
|
37 |
* Protocol for session refresh strategies. |
|
38 |
*/ |
|
39 |
@protocol TWTRSessionRefreshStrategy <NSObject> |
|
40 |
|
|
41 |
/** |
|
42 |
* Determines whether the strategy supports the given session class. |
|
43 |
* |
|
44 |
* @param sessionClass The class of session to check. |
|
45 |
* |
|
46 |
* @return YES if this strategy can be used to refresh the given session class. |
|
47 |
*/ |
|
48 |
+ (BOOL)canSupportSessionClass:(Class)sessionClass; |
|
49 |
|
|
50 |
/** |
|
51 |
* Determines whether the session has expired based on the API response of a previous API request made with the session. |
|
52 |
* |
|
53 |
* @param response HTTP response of a previous API request |
|
54 |
* |
|
55 |
* @return YES if the HTTP response is contains information to indicate the session is invalid or has expired. |
|
56 |
*/ |
|
57 |
+ (BOOL)isSessionExpiredBasedOnRequestResponse:(NSHTTPURLResponse *)response; |
|
58 |
|
|
59 |
/** |
|
60 |
* Determines whether the session has expired based on the API response error of a previous API request made with the session. |
|
61 |
* |
|
62 |
* @param response error a previous API request |
|
63 |
* |
|
64 |
* @return YES if the error contains information to indicate the session is invalid or has expired. |
|
65 |
*/ |
|
66 |
+ (BOOL)isSessionExpiredBasedOnRequestError:(NSError *)responseError; |
|
67 |
|
|
68 |
/** |
|
69 |
* Request to fetch a new session. |
|
70 |
* |
|
71 |
* @param session Expired session to request new one for |
|
72 |
* @param URLSession URL session to make the authentication request with |
|
73 |
* @param completion Completion block to call when done refreshing the session or it fails. |
|
74 |
*/ |
|
75 |
- (void)refreshSession:(id<TWTRBaseSession>)session URLSession:(NSURLSession *)URLSession completion:(TWTRSessionRefreshCompletion)completion; |
|
76 |
|
|
77 |
@end |
|
78 |
|
|
79 |
/** |
|
80 |
Concrete implementation of a strategy for handling expiration and refresh of guest sessions. |
|
81 |
*/ |
|
82 |
@interface TWTRGuestSessionRefreshStrategy : NSObject <TWTRSessionRefreshStrategy> |
|
83 |
|
|
84 |
/** |
|
85 |
* Initializes a new guest refresh strategy. |
|
86 |
* |
|
87 |
* @param authConfig The `authConfig` associated with the app to refresh guest sessions for |
|
88 |
* @param APIServiceConfig The API service config to configure endpoints |
|
89 |
* |
|
90 |
* @return Initialized strategy that can refresh guest sessions of the given application |
|
91 |
*/ |
|
92 |
- (instancetype)initWithAuthConfig:(TWTRAuthConfig *)authConfig APIServiceConfig:(id<TWTRAPIServiceConfig>)APIServiceConfig; |
655e66
|
93 |
- (instancetype)init NS_UNAVAILABLE; |
a0a843
|
94 |
|
H |
95 |
@end |
|
96 |
|
|
97 |
NS_ASSUME_NONNULL_END |