From a5db222c7a758d522bf73ddc3716661b469413f8 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 10 Oct 2018 11:39:29 -0600 Subject: [PATCH] move ud auth to request factory --- .../Network/API/Requests/OWSRequestFactory.m | 18 +++++++++++++++--- .../src/Network/API/Requests/TSRequest.h | 4 ---- .../src/Network/API/Requests/TSRequest.m | 12 ------------ 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m index daada24da..a68e90434 100644 --- a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m +++ b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m @@ -131,7 +131,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *path = [NSString stringWithFormat:textSecureProfileAPIFormat, recipientId]; TSRequest *request = [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}]; if (unidentifiedAccess != nil) { - [request useUDAuthWithAccessKey:unidentifiedAccess.accessKey]; + [self useUDAuthWithRequest:request accessKey:unidentifiedAccess.accessKey]; } return request; } @@ -197,7 +197,7 @@ NS_ASSUME_NONNULL_BEGIN TSRequest *request = [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}]; if (unidentifiedAccess != nil) { - [request useUDAuthWithAccessKey:unidentifiedAccess.accessKey]; + [self useUDAuthWithRequest:request accessKey:unidentifiedAccess.accessKey]; } return request; } @@ -342,7 +342,7 @@ NS_ASSUME_NONNULL_BEGIN TSRequest *request = [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:parameters]; if (unidentifiedAccess != nil) { - [request useUDAuthWithAccessKey:unidentifiedAccess.accessKey]; + [self useUDAuthWithRequest:request accessKey:unidentifiedAccess.accessKey]; } return request; } @@ -479,6 +479,18 @@ NS_ASSUME_NONNULL_BEGIN return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}]; } ++ (void)useUDAuthWithRequest:(TSRequest *)request accessKey:(SMKUDAccessKey *)udAccessKey +{ + OWSAssertDebug(request); + OWSAssertDebug(udAccessKey); + + // Suppress normal auth headers. + request.shouldHaveAuthorizationHeaders = NO; + + // Add UD auth header. + [request setValue:[udAccessKey.keyData base64EncodedString] forHTTPHeaderField:@"Unidentified-Access-Key"]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Network/API/Requests/TSRequest.h b/SignalServiceKit/src/Network/API/Requests/TSRequest.h index 600ef8fa6..b56e113dd 100644 --- a/SignalServiceKit/src/Network/API/Requests/TSRequest.h +++ b/SignalServiceKit/src/Network/API/Requests/TSRequest.h @@ -28,8 +28,4 @@ method:(NSString *)method parameters:(nullable NSDictionary *)parameters; -#pragma mark - UD - -- (void)useUDAuthWithAccessKey:(SMKUDAccessKey *)udAccessKey; - @end diff --git a/SignalServiceKit/src/Network/API/Requests/TSRequest.m b/SignalServiceKit/src/Network/API/Requests/TSRequest.m index 442713522..b3efd0723 100644 --- a/SignalServiceKit/src/Network/API/Requests/TSRequest.m +++ b/SignalServiceKit/src/Network/API/Requests/TSRequest.m @@ -112,16 +112,4 @@ } } -#pragma mark - UD - -- (void)useUDAuthWithAccessKey:(SMKUDAccessKey *)udAccessKey -{ - OWSAssertDebug(udAccessKey); - - // Suppress normal auth headers. - self.shouldHaveAuthorizationHeaders = NO; - // Add UD auth header. - [self setValue:[udAccessKey.keyData base64EncodedString] forHTTPHeaderField:@"Unidentified-Access-Key"]; -} - @end