Giter Site home page Giter Site logo

simpleauth's Introduction

SimpleAuth

SimpleAuth is designed to do the hard work of social account login on iOS. It is designed with a small set of public APIs backed by a set of "providers" the implement the functionality needed to communicate with a given service.

I plan to ship the following providers at launch:

I also have plans to provide:

  • Twitter web
  • Twitter xauth
  • Facebook web
  • Tumblr

The API for creating providers is likewise simple but it is not concrete yet. Every provider will be in its own git repository and CocoaPod so that you can install just the components you need.

Providers will be able to set fallbacks such that attempting to login with Facebook will fallback to Facebook web if no system account is present.

Usage

Configuring and using SimpleAuth is easy:

// Somewhere in your app boot process
[SimpleAuth configuration][@"twitter"] = @{
    @"consumer_key" : @"KEY",
    @"consumer_secret" : @"SECRET"
};
// Run the login process
[SimpleAuth authorize:@"twitter" completion:^(id responseObject, NSHTTPURLResponse *response, NSError *error) {
    NSLog(@"%@", responseObject);
}];

Implementing a Provider

Building your own provider is fairly straightforward. There are a handful of methods you'll need to implement:

Register your provider with SimpleAuth:

+ (void)load {
    @autoreleasepool {
        [SimpleAuth registerProviderClass:self];
    }
}

Let SimpleAuth know what type of provider you are registering:

+ (NSString *)type {
    return @"facebook";
}

Optionally, you may return a set of default options for all authorization options to use:

+ (NSDictionary *)defaultOptions {
    return @{
        @"permissions" : @[ @"email" ]
    };
}

Finally, provide a method for handling authorization:

- (void)authorizeWithCompletion:(SimpleAuthRequestHandler)completion {
	// Use values in self.options to customize behavior
	// Perform authentication
	// Call the completion
}

Challenges

The biggest challenge I face at this point is enabling customization of the authentication process. Almost all of the above providers require presenting UI to the user. Twitter requires an action sheet for selecting an account from all present system accounts and Instagram requires a web view controller. I need a generic mechanism that can allow the caller to change the behavior of presented UI.

License

SimpleAuth is released under the MIT license.

Thanks

Special thanks to my friend @soffes for advising on the SimpleAuth API design.

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.