Permalink
Browse files

Added an optional scope parameter for getting a request token per htt…

  • Loading branch information...
1 parent f98e76f commit 48395d7e62080e865bd971b4a6e35c3b436c3145 @owen-bnr owen-bnr committed Mar 5, 2013
Showing with 45 additions and 3 deletions.
  1. +17 −0 AFOAuth1Client/AFOAuth1Client.h
  2. +28 −3 AFOAuth1Client/AFOAuth1Client.m
@@ -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;
+
/**
*/
@@ -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;
+
/**
*/
@@ -188,7 +188,7 @@ - (NSDictionary *)OAuthParameters {
if (self.realm) {
[parameters setValue:self.realm forKey:@"realm"];
}
-
+
return parameters;
}
@@ -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) {
@@ -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];
@@ -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];

0 comments on commit 48395d7

Please sign in to comment.