Skip to content

Supertecnoboff/Simple-OAuth-1.0a---iOS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Simple-OAuth-1.0a---iOS

A super simple OAuth 1.0a implementation for iOS.

Note: This is a very basic implementation/mashup of TDOAuth and simple-oauth1.

This is an example Xcode project showing you how to login/authenticate with an OAuth 1.0a service (ie: Twitter).

Installation

  1. Drag and drop the OAuth library files to your Xcode project.

  2. #import the following files:

#import "OAuth1Controller.h"
#import "LoginWebViewController.h"
  1. Create the following @property:
@property (nonatomic, strong) OAuth1Controller *oauth1Controller;
  1. Add the intialisation method to your implementation file:
-(OAuth1Controller *)oauth1Controller {
    
    if (_oauth1Controller == nil) {
        _oauth1Controller = [[OAuth1Controller alloc] init];
    }
    
    return _oauth1Controller;
}
  1. Create an IBAction in your header file and a UIButton in your user interface file, then link them together.

  2. Add the following code to your IBAction:

-(IBAction)login {
    
    // Set the various OAuth 1.0a settings - Twitter example.
    self.oauth1Controller.pass_oauth_callback = @"YOUR-CALLBACK-HERE";
    self.oauth1Controller.pass_consumer_key = @"YOUR-KEY-HERE";
    self.oauth1Controller.pass_consumer_secret = @"YOUR-SECRET-HERE";
    self.oauth1Controller.pass_auth_url = @"https://api.twitter.com/oauth";
    self.oauth1Controller.pass_api_url = @"api.twitter.com/oauth";
    self.oauth1Controller.pass_request_token_url = @"/request_token";
    self.oauth1Controller.pass_authenticate_url = @"/authorize";
    self.oauth1Controller.pass_access_token_url = @"/access_token";
    self.oauth1Controller.pass_oauth_scope_params = @"";
    
    // Setup the OAuth 1.0a login view.
    UIStoryboard *story_file = [UIStoryboard storyboardWithName:@"LoginWebViewController" bundle:nil];
    LoginWebViewController *login_view = [story_file instantiateViewControllerWithIdentifier:@"loginOA1"];
    
    // Open the OAuth 1.0a login view.
    [self presentViewController:login_view animated:YES completion:^{
        
        // Begin the OAuth 1.0a authentication process.
        [self.oauth1Controller loginWithWebView:login_view.webView completion:^(NSDictionary *oauthTokens, NSError *error) {
            
            if (!error) {
                NSLog(@"Success: %@", oauthTokens);
            }
            
            else {
                NSLog(@"Error authenticating: %@", error);
            }
            
            // Now close OAuth 1.0a login view.
            [self dismissViewControllerAnimated:YES completion: ^{
                self.oauth1Controller = nil;
            }];
        }];
    }];
}

Other

You will need to create a developer account and get the appropriate OAuth related info (such as a consumer key), in order for this to work.

Releases

No releases published

Packages

No packages published