title: OAuth 2.0 integration in iOS
body: <p>I have been trying for ages now to get OAuth 2.0 integration in my iPhone application.</p>
  
  <p>I have searched and searched for libraries, tutorials, etc... But they have all lead me to a dead end. The main problem I have is that they either have deprecated code, or they just don't work or they have some documentation but its really hard to follow (for me anyway...).</p>
  
  <p>The best OAuth2 library I could find for Xcode is this one: <a href="https://github.com/nxtbgthng/OAuth2Client">https://github.com/nxtbgthng/OAuth2Client</a></p>
  
  <p>But the main problem with that one is it doesn't seem to do anything... I have followed all the documentation and instructions that came with it, but after building and running, it doesn't seem to authenticate....</p>
  
  <p>So I guess my main question is: does anyone know of any good and up to date OAuth 2.0 tutorials for Xcode or any libraries for such a thing?</p>
  
  <p>Because I am really struggling at the moment.... :(</p>
  
  <p>Thanks for your time, Dan.</p>
  
  <p><strong>UPDATE 2: Here is my code (App Id and secret removed for security):</strong></p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
  
  oauthClient = [[LROAuth2Client alloc]
                 initWithClientID:@"MY_CLIENT_ID"
                 secret:@"MY_APP_SECRET"
                 redirectURL:[NSURL URLWithString:@"app://instagram-callback/?code="]];
  oauthClient.delegate = self;
  
  oauthClient.userURL  = [NSURL URLWithString:@"https://api.instagram.com/oauth/authorize/?client_id=ab6dc96859bf43b3a488199ec72d9964&amp;redirect_uri=app://instagram-callback/?code=&amp;response_type=code"];
  oauthClient.tokenURL = [NSURL URLWithString:@"https://api.instagram.com/oauth/access_token/"];
  
  
  [oauthClient authorizeUsingWebView:myWebView];
  
  
  }
  
  - (void)oauthClientDidReceiveAccessToken:(LROAuth2Client *)client;
  {
      LROAuth2AccessToken *token = client.accessToken;
      [NSKeyedArchiver archiveRootObject:token toFile:@"Path/To/MyAccessToken"];
  }
  
  - (void)checkAccessTokenForExpiry:(LROAuth2AccessToken *)accessToken;
  {
      if ([accessToken hasExpired]) {
          [oauthClient refreshAccessToken:accessToken];
      }
  }
  
  - (void)oauthClientDidRefreshAccessToken:(LROAuth2Client *)client;
  {
      LROAuth2AccessToken *token = client.accessToken;
      [NSKeyedArchiver archiveRootObject:token toFile:@"Path/To/MyAccessToken"];
  }
  </code></pre>