Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add comments to ANAuthenticator explaining how to use it

  • Loading branch information...
commit 2a6808f5e1dd32da19b5ff84ae581bfa51521364 1 parent 02c51a1
Brent Royal-Gordon authored
Showing with 55 additions and 0 deletions.
  1. +55 −0 ANAuthenticator.h
View
55 ANAuthenticator.h
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "AppNetKit.h"
+// Use an array of these constants to specify the scopes you want to request.
extern NSString * const ANScopeStream;
extern NSString * const ANScopeEmail;
extern NSString * const ANScopeWritePost;
@@ -24,6 +25,22 @@ extern NSString * const ANScopeExport;
#pragma mark OAuth authentication flow
+//
+// OAuth browser-based authentication. Use these methods if you want to show an App.net-controlled web page with username and password fields.
+//
+// Basic usage:
+//
+// 1. Set the clientID and redirectURL.
+//
+// 2. Call -URLToAuthenticateForScopes: or URLToAuthorizeForScopes: to get an HTTP URL.
+//
+// 3. Show that URL in a web view or in the user's default browser.
+//
+// 4. If you're using a web view, register as the web view's delegate and test each URL they navigate to with -isRedirectURL:. If you're using the user's browser, make sure the redirectURL has a URL scheme that will open your app, and test URLs your app is opened with with -isRedirectURL:.
+//
+// 5. Once you've determined you have a redirect URL on your hands, extract the access token and error message from it with -accessTokenFromRedirectURL:error:.
+//
+
@property (strong,nonatomic) NSURL * redirectURL;
@property (assign,nonatomic) BOOL omitsPaymentOptions;
@@ -35,6 +52,44 @@ extern NSString * const ANScopeExport;
#pragma mark Password authentication flow
+//
+// Password authentication. Use these methods if you want to display your own login user interface.
+//
+// Usage:
+//
+// 1. Set the passwordGrantSecret to the one the App.net guys gave you. This is not listed anywhere online; you have to email the staff and ask them to generate one for you. Also set the clientID to the one listed online.
+//
+// 2. Show a UI with username and password fields, information about which scopes your app will be requesting, and a login button.
+//
+// 3. When the user hits the login button, call -accessTokenForScopes:withUsername:password:completion:, and show some sort of progress indicator on screen.
+//
+// 4. The completion handler will be called with either an accessToken for the account or an error.
+//
+// Quick example:
+/*
+ ANAuthenticator.sharedAuthenticator.clientID = myClientID;
+ ANAuthenticator.sharedAuthenticator.passwordGrantSecret = mySecret;
+
+ [progressIndicator startAnimating];
+
+ [ANAuthenticator.sharedAuthenticator accessTokenForScopes:@[ ANScopeStream, ANScopeWritePost ] withUsername:usernameField.text password:passwordField.text completion:^(NSString * accessToken, id rep, NSError * error) {
+ [progressIndicator stopAnimating];
+
+ if(!accessToken) {
+ [self showErrorToUser:error];
+ return;
+ }
+
+ MyAccount * newAccount = [MyAccount new];
+ newAccount.token = accessToken;
+ [newAccount save];
+
+ [self showTheAppForAccount:newAccount];
+ }];
+*/
+// App.net has certain requirements for your app if you use password auth. Make sure you follow them! See this page for details: <https://github.com/appdotnet/api-spec/blob/master/password_auth.md>
+//
+
@property (strong,nonatomic) NSString * passwordGrantSecret;
- (void)accessTokenForScopes:(NSArray *)scopes withUsername:(NSString *)username password:(NSString *)password completion:(void (^)(NSString *accessToken, id rep, NSError * error))completion;
Please sign in to comment.
Something went wrong with that request. Please try again.