Permalink
Browse files

Merge pull request #28 from owen-bnr/scope

Added an optional scope parameter for getting a request token.
  • Loading branch information...
mattt committed May 7, 2013
2 parents dbd74eb + 48395d7 commit 8e945e57826febcc5c432eec9c275b65238a44c1
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;
+
/**
*/
@@ -189,7 +189,7 @@ - (NSDictionary *)OAuthParameters {
if (self.realm) {
[parameters setValue:self.realm forKey:@"realm"];
}
-
+
return parameters;
}
@@ -235,7 +235,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) {
@@ -256,7 +256,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];
@@ -304,9 +316,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 8e945e5

Please sign in to comment.