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

Commit

Permalink
Added an optional scope parameter for getting a request token per htt…
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-bnr committed Mar 5, 2013
1 parent f98e76f commit 48395d7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
17 changes: 17 additions & 0 deletions AFOAuth1Client/AFOAuth1Client.h
Expand Up @@ -73,6 +73,15 @@ typedef enum {
///---------------------


- (void)authorizeUsingOAuthWithRequestTokenPath:(NSString *)requestTokenPath
userAuthorizationPath:(NSString *)userAuthorizationPath
callbackURL:(NSURL *)callbackURL
accessTokenPath:(NSString *)accessTokenPath
accessMethod:(NSString *)accessMethod
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *accessToken))success
failure:(void (^)(NSError *error))failure;

/**
*/
Expand All @@ -84,6 +93,14 @@ typedef enum {
success:(void (^)(AFOAuth1Token *accessToken))success
failure:(void (^)(NSError *error))failure;


- (void)acquireOAuthRequestTokenWithPath:(NSString *)path
callback:(NSURL *)url
accessMethod:(NSString *)accessMethod
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *requestToken))success
failure:(void (^)(NSError *error))failure;

/**
*/
Expand Down
31 changes: 28 additions & 3 deletions AFOAuth1Client/AFOAuth1Client.m
Expand Up @@ -188,7 +188,7 @@ - (NSDictionary *)OAuthParameters {
if (self.realm) {
[parameters setValue:self.realm forKey:@"realm"];
}

return parameters;
}

Expand Down Expand Up @@ -234,7 +234,7 @@ - (NSString *)authorizationHeaderForMethod:(NSString*)method

[mutableParameters addEntriesFromDictionary:mutableAuthorizationParameters];
[mutableAuthorizationParameters setValue:[self OAuthSignatureForMethod:method path:path parameters:mutableParameters token:self.accessToken] forKey:@"oauth_signature"];

NSArray *sortedComponents = [[AFQueryStringFromParametersWithEncoding(mutableAuthorizationParameters, self.stringEncoding) componentsSeparatedByString:@"&"] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSMutableArray *mutableComponents = [NSMutableArray array];
for (NSString *component in sortedComponents) {
Expand All @@ -255,7 +255,19 @@ - (void)authorizeUsingOAuthWithRequestTokenPath:(NSString *)requestTokenPath
success:(void (^)(AFOAuth1Token *accessToken))success
failure:(void (^)(NSError *error))failure
{
[self acquireOAuthRequestTokenWithPath:requestTokenPath callback:callbackURL accessMethod:(NSString *)accessMethod success:^(AFOAuth1Token *requestToken) {
[self authorizeUsingOAuthWithRequestTokenPath:requestTokenPath userAuthorizationPath:userAuthorizationPath callbackURL:callbackURL accessTokenPath:accessTokenPath accessMethod:accessMethod scope:nil success:success failure:failure];
}

- (void)authorizeUsingOAuthWithRequestTokenPath:(NSString *)requestTokenPath
userAuthorizationPath:(NSString *)userAuthorizationPath
callbackURL:(NSURL *)callbackURL
accessTokenPath:(NSString *)accessTokenPath
accessMethod:(NSString *)accessMethod
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *accessToken))success
failure:(void (^)(NSError *error))failure
{
[self acquireOAuthRequestTokenWithPath:requestTokenPath callback:callbackURL accessMethod:(NSString *)accessMethod scope:scope success:^(AFOAuth1Token *requestToken) {
__block AFOAuth1Token *currentRequestToken = requestToken;
[[NSNotificationCenter defaultCenter] addObserverForName:kAFApplicationLaunchedWithURLNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
NSURL *url = [[notification userInfo] valueForKey:kAFApplicationLaunchOptionsURLKey];
Expand Down Expand Up @@ -294,9 +306,22 @@ - (void)acquireOAuthRequestTokenWithPath:(NSString *)path
accessMethod:(NSString *)accessMethod
success:(void (^)(AFOAuth1Token *requestToken))success
failure:(void (^)(NSError *error))failure
{
[self acquireOAuthRequestTokenWithPath:path callback:callbackURL accessMethod:accessMethod scope:nil success:success failure:failure];
}

- (void)acquireOAuthRequestTokenWithPath:(NSString *)path
callback:(NSURL *)callbackURL
accessMethod:(NSString *)accessMethod
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *requestToken))success
failure:(void (^)(NSError *error))failure
{
NSMutableDictionary *parameters = [[self OAuthParameters] mutableCopy];
[parameters setValue:[callbackURL absoluteString] forKey:@"oauth_callback"];
if (scope && !self.accessToken) {
[parameters setValue:scope forKey:@"scope"];
}

NSMutableURLRequest *request = [self requestWithMethod:accessMethod path:path parameters:parameters];
[request setHTTPBody:nil];
Expand Down

0 comments on commit 48395d7

Please sign in to comment.