Coder Social home page Coder Social logo

meetupoauth2client's Introduction

Meetup OAuth2 Client

MeetupOAuth2Client is an HTTP OAuth2 authentication client specifically for use with the Meetup.com API. This small library is completely self-contained–no dependencies. It features a nice pop-out animating web view to display the Meetup authorization page.

##Installation

Add the contents of the MUOAuth2Client/src folder to your project.

##Use and Flow

At the point in your application where you need to access the user's resources, the flow should be like the following:

// Grab a reference to the shared instance of `MUOAuth2Client`.
MUOAuth2Client *client = [MUOAuth2Client sharedClient];

// Attempt to unarchive an existing credential.
self.credential = [client credentialWithClientID:@"YOUR_CLIENT_ID"];

if (!self.credential) {

  // Here you should show the pre-logged in state of your application.
  // where the user may be presented with a "log in" button.
  // (See the "authorization" snippet)
  
} else if (self.credential.isExpired) {
  
    // Refresh the credential.
	[client refreshCredential:self.credential success:^(MUOAuth2Credential *credential) {
  
        // Hang on to this new credential.
        self.credential = credential;
    
	} failure:^(NSError *error) {
  
        // Handle the error.
		NSLog(@"Authorization error -> %@", error);
	}];

} else {

    // The credential should be valid. 
    // Proceed with accessing the Meetup API and loading the user's resources.
}

Authorization

The following will trigger a web view presentation of the Meetup.com mobile log-in/authorization page allowing the user to authorize your application:

// Grab a reference to the shared instance of `MUOAuth2Client`.
MUOAuth2Client *client = [MUOAuth2Client sharedClient];

// Authorize your client application with the client ID, secret, and redirect URI you set up with Meetup.com.
[client authorizeClientWithID:@"YOUR_CLIENT_ID" secret:@"SECRET" redirectURI:@"REDIRECT" success:^(MUOAuth2Credential *credential) {
  
    // Hang on the credential.
    self.credential = credential;
	
	// Proceed with accessing the Meetup API and loading the user's resources.
	
} failure:^(NSError *error) {
	
    // Handle the error.
	NSLog(@"Authorization error -> %@", error);
}];
    

Using the credential

Once you have obtained a valid MUOAuth2Credential object, you can use it's accessToken property to append to your requests to the Meetup.com API: credential.accessToken.

Using the MUAPIRequest class

The MUAPIRequest class provides a convenient way to access Meetup API endpoints, and parse JSON response bodies. For example:

- (void)accessMemberSelf
{
    MUOAuth2Credential* credential = [[MUOAuth2Client sharedClient] credentialWithClientID:@"oauth-consumer-key"];
    [MUAPIRequest getRequestWithURL:@"https://api.meetup.com/2/member/self.json"
                         parameters:@{}
                      andCredential:credential
                         completion:^(MUAPIRequest *request) {
                             NSLog(@"Response = %@", request.response); // response object
                             NSLog(@"Error = %@", request.error); // set if there was an error
                             NSLog(@"JSON = %@", request.responseBody); // JSON Decoded to NSDictionary
                         }];
  
}

##Requirements MUOAuth2Client requires iOS 5.0 or higher and uses ARC.

##Notes This library does not communicate with Meetup.com other than to authorize client applications and obtain and refresh access tokens. Further communication with the Meetup.com API could be done with a library such as AFNetworking. This library is intentionally simple, but no doubt there is room for improvement. Contributions are welcome.

Demo App

Included in the project is a sample application to illustrate the flow of the authorization and refreshing of tokens.

meetupoauth2client's People

Contributors

mattconnolly avatar ioswes avatar

Stargazers

 avatar

Watchers

James Cloos avatar Yann Bodson avatar felipe munoz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.