Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #34 from evoL/session_token
Browse files Browse the repository at this point in the history
Temporary session token support
  • Loading branch information
mattt committed Nov 29, 2014
2 parents 3508f7c + b71089b commit d991e21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion AFAmazonS3Client/AFAmazonS3Manager.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ - (void)setObjectWithMethod:(NSString *)method
#pragma mark - NSKeyValueObserving

+ (NSSet *)keyPathsForValuesAffectingBaseURL {
return [NSSet setWithObjects:@"baseURL", @"requestSerializer.bucket", @"requestSerializer.region", @"requestSerializer.useSSL", nil];
return [NSSet setWithObjects:@"baseURL", @"requestSerializer.bucket", @"requestSerializer.region", @"requestSerializer.sessionToken", @"requestSerializer.useSSL", nil];
}

#pragma mark - NSCopying
Expand Down
5 changes: 5 additions & 0 deletions AFAmazonS3Client/AFAmazonS3RequestSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
*/
@property (nonatomic, copy) NSString *region;

/**
The AWS STS session token. `nil` by default.
*/
@property (nonatomic, copy) NSString *sessionToken;

/**
Whether to connect over HTTPS. `YES` by default.
Expand Down
16 changes: 14 additions & 2 deletions AFAmazonS3Client/AFAmazonS3RequestSerializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
parameters:(NSDictionary *)parameters
error:(NSError *__autoreleasing *)error
{
return [[self requestBySettingAuthorizationHeadersForRequest:[super requestWithMethod:method URLString:URLString parameters:parameters error:error] error:error] mutableCopy];
NSMutableURLRequest *request = [super requestWithMethod:method URLString:URLString parameters:parameters error:error];

if (self.sessionToken) {
[request setValue:self.sessionToken forHTTPHeaderField:@"x-amz-security-token"];
}

return [[self requestBySettingAuthorizationHeadersForRequest:request error:error] mutableCopy];
}

- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
Expand All @@ -246,7 +252,13 @@ - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
constructingBodyWithBlock:(void (^)(id<AFMultipartFormData>))block
error:(NSError *__autoreleasing *)error
{
return [[self requestBySettingAuthorizationHeadersForRequest:[super multipartFormRequestWithMethod:method URLString:URLString parameters:parameters constructingBodyWithBlock:block error:error] error:error] mutableCopy];
NSMutableURLRequest *request = [super multipartFormRequestWithMethod:method URLString:URLString parameters:parameters constructingBodyWithBlock:block error:error];

if (self.sessionToken) {
[request setValue:self.sessionToken forHTTPHeaderField:@"x-amz-security-token"];
}

return [[self requestBySettingAuthorizationHeadersForRequest:request error:error] mutableCopy];
}

@end

0 comments on commit d991e21

Please sign in to comment.