forked from EthanArbuckle/Apollo-CustomApiCredentials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.m
44 lines (34 loc) · 1.8 KB
/
Tweak.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
static NSString * const kRedditClientID = @"CLIENT_ID_GOES_HERE";
static NSString * const kImgurClientID = @"IMGUR_CLIENT_ID_GOES_HERE";
static NSString * const kImgurRapidAPIKey = @"RAPID_API_KEY_GOES_HERE";
__attribute__ ((constructor)) static void init(void) {
Class _RDKOAuthCredential = objc_getClass("RDKOAuthCredential");
if (_RDKOAuthCredential) {
Method clientIdMethod = class_getInstanceMethod(_RDKOAuthCredential, sel_registerName("clientIdentifier"));
IMP replacementImp = imp_implementationWithBlock(^NSString *(id _self) {
return kRedditClientID;
});
method_setImplementation(clientIdMethod, replacementImp);
}
Class _NSURLSessionConfiguration = objc_getClass("NSURLSessionConfiguration");
Method setHeadersMethod = class_getInstanceMethod(_NSURLSessionConfiguration, sel_registerName("setHTTPAdditionalHeaders:"));
IMP originalSetHeadersImp = method_getImplementation(setHeadersMethod);
IMP replacementSetHeadersImp = imp_implementationWithBlock(^void (id _self, NSDictionary *headers) {
if (headers && [headers valueForKey:@"Authorization"]) {
if ([[headers valueForKey:@"Authorization"] isEqualToString:@"Client-ID 0b596f9aaeef0f4"]) {
NSMutableDictionary *newHeaders = [headers mutableCopy];
newHeaders[@"Authorization"] = [NSString stringWithFormat:@"Client-ID %@", kImgurClientID];
headers = newHeaders;
}
}
if (headers && [headers valueForKey:@"X-RapidAPI-Key"]) {
NSMutableDictionary *newHeaders = [headers mutableCopy];
newHeaders[@"X-RapidAPI-Key"] = kImgurRapidAPIKey;
headers = newHeaders;
}
((void (*)(id, SEL, id))originalSetHeadersImp)(_self, NSSelectorFromString(@"setHTTPAdditionalHeaders:"), headers);
});
method_setImplementation(setHeadersMethod, replacementSetHeadersImp);
}