All Projects → bdbergeron → Bdboauth1manager

bdbergeron / Bdboauth1manager

Licence: mit
OAuth 1.0a library for AFNetworking 2.x

Projects that are alternatives of or similar to Bdboauth1manager

Node Oauth2 Server Mongo Example
Working oauth2 server with mongodb storage and minimal configuration
Stars: ✭ 76 (-24.75%)
Mutual labels:  oauth
Finagle Oauth2
OAuth2 Server-Side Provider for Finagle
Stars: ✭ 84 (-16.83%)
Mutual labels:  oauth
Ring Oauth2
OAuth 2.0 client middleware for Ring
Stars: ✭ 93 (-7.92%)
Mutual labels:  oauth
Ueberauth github
GitHub OAuth2 Strategy for Überauth
Stars: ✭ 80 (-20.79%)
Mutual labels:  oauth
Weixin
[READ ONLY] Subtree split of the SocialiteProviders/Weixin Provider (see SocialiteProviders/Providers)
Stars: ✭ 84 (-16.83%)
Mutual labels:  oauth
Docker Cloud Platform
使用Docker构建云平台,Docker云平台系列共三讲,Docker基础、Docker进阶、基于Docker的云平台方案。OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 86 (-14.85%)
Mutual labels:  oauth
Patreon Python
Interact with the Patreon API via OAuth
Stars: ✭ 72 (-28.71%)
Mutual labels:  oauth
Ng Boot Oauth
oauth2 demo with angularjs and springboot
Stars: ✭ 99 (-1.98%)
Mutual labels:  oauth
Ueberauth
An Elixir Authentication System for Plug-based Web Applications
Stars: ✭ 1,259 (+1146.53%)
Mutual labels:  oauth
Nextjs Starter
A starter project for Next.js with authentication
Stars: ✭ 1,313 (+1200%)
Mutual labels:  oauth
Zhihu Oauth
尝试解析出知乎官方未开放的 OAuth2 接口,并提供优雅的使用方式,作为 zhihu-py3 项目的替代者,目前还在实验阶段
Stars: ✭ 1,237 (+1124.75%)
Mutual labels:  oauth
Indielogin.com
Sign in with your domain name
Stars: ✭ 84 (-16.83%)
Mutual labels:  oauth
Connect
The SymfonyConnect official API SDK
Stars: ✭ 86 (-14.85%)
Mutual labels:  oauth
Httpie Oauth
OAuth plugin for HTTPie
Stars: ✭ 78 (-22.77%)
Mutual labels:  oauth
Nginx Openid Connect
Reference implementation of OpenID Connect integration for NGINX Plus
Stars: ✭ 96 (-4.95%)
Mutual labels:  oauth
Stormpath Sdk Php
PHP SDK for the Stormpath User Management and Authentication REST+JSON API
Stars: ✭ 72 (-28.71%)
Mutual labels:  oauth
Accounts
Fullstack authentication and accounts-management for Javascript.
Stars: ✭ 1,266 (+1153.47%)
Mutual labels:  oauth
Warden Github Rails
Use GitHub as authorization and more. Use organizations and teams as means of authorization by simply wrapping your rails routes in a block. Also useful to get a user's details through OAuth.
Stars: ✭ 100 (-0.99%)
Mutual labels:  oauth
Vue Authenticate
Simple Vue.js authentication library
Stars: ✭ 1,350 (+1236.63%)
Mutual labels:  oauth
Androidoauth
A simple way to authenticate with Google and Facebook using OAuth 2.0 in Android
Stars: ✭ 88 (-12.87%)
Mutual labels:  oauth

BDBOAuth1Manager

BDBOAuth1Manager is an OAuth 1.0a library for AFNetworking 2.x.

Usage

BDBOAuth1Manager consists of three core classes: BDBOAuth1RequestSerializer, BDBOAuth1RequestOperationManger, and BDBOAuth1SessionManager. Below I will provide a quick overview of each, but to really see how the three classes work together, take a look at the included demo apps. One is a simple Twitter client and the other a simple Flickr photo gallery, but they show how to get started using BDBOAuth1Manager in your projects.

BDBOAuth1RequestOperationManger

BDBOAuth1RequestOperationManger is a subclass of AFHTTPRequestOperationManager that provides methods to facilitate the OAuth 1 authentication flow.

@property (nonatomic) BDBOAuth1RequestSerializer *requestSerializer;

#pragma mark Initialization
- (instancetype)initWithBaseURL:(NSURL *)baseURL
                    consumerKey:(NSString *)consumerKey
                 consumerSecret:(NSString *)consumerSecret;

#pragma mark Authorization Status
@property (nonatomic, assign, readonly, getter = isAuthorized) BOOL authorized;

- (BOOL)deauthorize;

#pragma mark OAuth Handshake
- (void)fetchRequestTokenWithPath:(NSString *)requestPath
                           method:(NSString *)method
                      callbackURL:(NSURL *)callbackURL
                            scope:(NSString *)scope
                          success:(void (^)(BDBOAuth1Credential *requestToken))success
                          failure:(void (^)(NSError *error))failure;

- (void)fetchAccessTokenWithPath:(NSString *)accessPath
                          method:(NSString *)method
                    requestToken:(BDBOAuth1Credential *)requestToken
                         success:(void (^)(BDBOAuth1Credential *accessToken))success
                         failure:(void (^)(NSError *error))failure;

BDBOAuth1SessionManager

BDBOAuth1SessionManager is a subclass of AFHTTPSessionManager that has the same API as BDBOAuth1RequestOperationManger, which is described above.

If your deployment target is either iOS 6 or OS X 10.8, you must use BDBOAuth1RequestOperationManger, as the underlying NSURLSession that is used by AFHTTPSessionManager is a new addition to the iOS and OS X networking frameworks for iOS 7 and OS X 10.9.

BDBOAuth1RequestSerializer

BDBOAuth1RequestSerializer is a subclass of AFHTTPRequestSerializer that handles all the networking requests performed by BDBOAuth1RequestOperationManger and BDBOAuth1SessionManager. Both classes automatically handle the creation of this serializer, so you should never have to instantiate it on your own.

BDBOAuth1RequestSerializer also has built-in support for storing and retrieving an OAuth access token to/from the user's keychain, utilizing the service name to differentiate tokens. BDBOAuth1RequestOperationManger and BDBOAuth1SessionManager automatically set the service name to baseURL.host (e.g. api.twitter.com) when they are instantiated.

OAuth Handshake

The first step in performing the OAuth handshake is getting an OAuth request token for your application. This can be done with the fetchRequestTokenWithPath:method:callbackURL:scope:success:failure: method.

[self.networkManager fetchRequestTokenWithPath:@"/oauth/request_token"
                                        method:@"POST"
                                   callbackURL:[NSURL URLWithString:@"bdboauth://request"]
                                         scope:nil
                                       success:^(BDBOAuth1Credential *requestToken) {
                                           NSString *authURL = [NSString stringWithFormat:@"https://api.twitter.com/oauth/authorize?oauth_token=%@", requestToken.token];
                                           [[UIApplication sharedApplication] openURL:[NSURL URLWithString:authURL]];
                                       }
                                       failure:^(NSError *error) {
                                           NSLog(@"Error: %@", error.localizedDescription);
                                       }];

Creating a URL Type for OAuth Callbacks

When calling fetchRequestTokenWithPath:method:callbackURL:scope:success:failure:, you must provide a unique callback URL whose scheme corresponds to a URL type you've added to your project target. This allows the OAuth provider to return the user to your app after the user has authorized it. For example, if I add a URL type to my project with the scheme bdboauth, my application would then respond to all URL requests that begin with bdboauth:. If I pass bdboauth://request as the callback URL, the OAuth provider would call that URL and my application would resume.

URL Types Screenshot

Responding to the OAuth Callback URL

In order to respond to your application's URL scheme being called, you must implement the -application:openURL:sourceApplication:annotation method within your application delegate. You can do something like this:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
	if ([url.scheme isEqualToString:@"bdboauth"]) {
		if ([url.host isEqualToString:@"request"]) {
			NSDictionary *parameters = [url dictionaryFromQueryString];
			if (parameters[@"oauth_token"] && parameters[@"oauth_verifier"]) {
				[self.networkManager fetchAccessTokenWithPath:@"/oauth/access_token"
                	                                   method:@"POST"
                    	                         requestToken:[BDBOAuth1Credential credentialWithQueryString:url.query]
                        	                          success:^(BDBOAuth1Credential *accessToken) {
                            	                          [self.networkManager.requestSerializer saveAccessToken:accessToken];
                                	                  }];
			}
		}
		return YES;
	}
    return NO;
}

Credits

BDBOAuth1Manager was created by Bradley David Bergeron and influenced by AFOAuth1Client. Both AFNetworking and AFOAuth1Client are the awesome work of Mattt Thompson.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].