Permalink
Browse files

Oops, converted tabs to spaces

  • Loading branch information...
1 parent a2a8270 commit a5dc772d2abcb705b9db915a0b5e903d2f874aa9 @snej snej committed Jan 7, 2013
Showing with 135 additions and 135 deletions.
  1. +3 −3 Sources/BrowserIDViewController.h
  2. +22 −22 Sources/BrowserIDViewController.js
  3. +110 −110 Sources/BrowserIDViewController.m
@@ -43,12 +43,12 @@
@property (nonatomic,weak) id<BrowserIDViewControllerDelegate> delegate;
/** The URL of the site the user is logging into (i.e. the site you will send the assertion to).
- Required. */
+ Required. */
@property (nonatomic,strong) NSURL* origin;
/** An optional URL of a verification service provided by your applicatin's server-side counterpart.
- If this property is set, an assertion will be sent to this URL as the body of a POST request,
- and the response relayed to the delegate via its verification-related methods. */
+ If this property is set, an assertion will be sent to this URL as the body of a POST request,
+ and the response relayed to the delegate via its verification-related methods. */
@property (nonatomic,strong) NSURL* verifier;
/** After a successful login, this property will be set to the email address the user entered. */
@@ -2,30 +2,30 @@
window.onload = function()
{
- // The origin is setup when this code template is loaded in the native application
- var origin = "%@";
-
- var callbackToCocoa = function(name, value) {
- window.location = "BrowserIDViewController://" + name + "/callback?data=" + value;
- };
+ // The origin is setup when this code template is loaded in the native application
+ var origin = "%@";
+
+ var callbackToCocoa = function(name, value) {
+ window.location = "BrowserIDViewController://" + name + "/callback?data=" + value;
+ };
- var internalGetCallback = function(assertion) {
- if (!assertion) {
- // Not sure what to do here. I don't think there is a 'reason'?
- callbackToCocoa("assertionFailure", "");
- return;
- }
+ var internalGetCallback = function(assertion) {
+ if (!assertion) {
+ // Not sure what to do here. I don't think there is a 'reason'?
+ callbackToCocoa("assertionFailure", "");
+ return;
+ }
- // Parse the assertion to extract the email address the user entered:
- var parts = assertion.split(".");
- var signature = JSON.parse(window.atob(parts[1]));
- var email = signature.principal.email;
+ // Parse the assertion to extract the email address the user entered:
+ var parts = assertion.split(".");
+ var signature = JSON.parse(window.atob(parts[1]));
+ var email = signature.principal.email;
- callbackToCocoa("assertionReady",
- encodeURIComponent(assertion) + "&email=" + encodeURIComponent(email));
- };
+ callbackToCocoa("assertionReady",
+ encodeURIComponent(assertion) + "&email=" + encodeURIComponent(email));
+ };
- // Start the login process:
- var options = {};
- BrowserID.internal.get(origin, internalGetCallback, options);
+ // Start the login process:
+ var options = {};
+ BrowserID.internal.get(origin, internalGetCallback, options);
};
@@ -17,158 +17,158 @@ @implementation BrowserIDViewController
@synthesize emailAddress = _emailAddress;
- (UINavigationController*) presentModalInController: (UIViewController*)parentController {
- UINavigationController* navController = [[UINavigationController alloc]
- initWithRootViewController: self];
- if (navController == nil)
- return nil;
-
- if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
- navController.modalPresentationStyle = UIModalPresentationFormSheet;
- }
- [parentController presentViewController: navController animated: YES completion: nil];
- return navController;
+ UINavigationController* navController = [[UINavigationController alloc]
+ initWithRootViewController: self];
+ if (navController == nil)
+ return nil;
+
+ if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
+ navController.modalPresentationStyle = UIModalPresentationFormSheet;
+ }
+ [parentController presentViewController: navController animated: YES completion: nil];
+ return navController;
}
- (void) viewDidLoad
{
- [super viewDidLoad];
-
- self.title = NSLocalizedString(@"Log In With Persona", @"BrowserID login window title");
-
- UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithTitle: @"Cancel"
- style: UIBarButtonItemStylePlain target: self action: @selector(cancel)];
+ [super viewDidLoad];
+
+ self.title = NSLocalizedString(@"Log In With Persona", @"BrowserID login window title");
+
+ UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithTitle: @"Cancel"
+ style: UIBarButtonItemStylePlain target: self action: @selector(cancel)];
#if !__has_feature(objc_arc)
- [cancelButton autorelease];
+ [cancelButton autorelease];
#endif
- self.navigationItem.rightBarButtonItem = cancelButton;
+ self.navigationItem.rightBarButtonItem = cancelButton;
- _webView.delegate = self;
+ _webView.delegate = self;
- // Insert the code that will setup and handle the BrowserID callback.
+ // Insert the code that will setup and handle the BrowserID callback.
- NSString* injectedCodePath = [[NSBundle mainBundle] pathForResource: @"BrowserIDViewController" ofType: @"js"];
- NSString* injectedCodeTemplate = [NSString stringWithContentsOfFile: injectedCodePath encoding:NSUTF8StringEncoding error: nil];
- NSAssert(injectedCodeTemplate != nil, @"Could not load BrowserIDViewController.js");
+ NSString* injectedCodePath = [[NSBundle mainBundle] pathForResource: @"BrowserIDViewController" ofType: @"js"];
+ NSString* injectedCodeTemplate = [NSString stringWithContentsOfFile: injectedCodePath encoding:NSUTF8StringEncoding error: nil];
+ NSAssert(injectedCodeTemplate != nil, @"Could not load BrowserIDViewController.js");
- NSString* injectedCode = [NSString stringWithFormat: injectedCodeTemplate, _origin.absoluteString];
+ NSString* injectedCode = [NSString stringWithFormat: injectedCodeTemplate, _origin.absoluteString];
- [_webView stringByEvaluatingJavaScriptFromString: injectedCode];
+ [_webView stringByEvaluatingJavaScriptFromString: injectedCode];
}
- (void) viewWillAppear:(BOOL)animated
{
- [_webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: kBrowserIDSignInURL]]];
+ [_webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: kBrowserIDSignInURL]]];
}
- (void) viewDidUnload
{
- [super viewDidUnload];
+ [super viewDidUnload];
}
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- } else {
- return YES;
- }
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+ } else {
+ return YES;
+ }
}
#pragma mark -
- (IBAction) cancel
{
- [_webView stopLoading];
- [_delegate browserIDViewControllerDidCancel: self];
+ [_webView stopLoading];
+ [_delegate browserIDViewControllerDidCancel: self];
}
#pragma mark -
- (void) verifyAssertion: (NSString*) assertion
{
- // POST the assertion to the verification endpoint. Then report back to our delegate about the
- // results.
-
- id verifyCompletionHandler = ^(NSHTTPURLResponse* response, NSData* data, NSError* error)
- {
- if (error) {
- [_delegate browserIDViewController: self didFailVerificationWithError: error];
- } else {
- NSError* decodingError = nil;
- NSDictionary* receipt = [NSJSONSerialization JSONObjectWithData: data options: 0 error: &decodingError];
- if (decodingError) {
- [_delegate browserIDViewController: self didFailVerificationWithError: decodingError];
- } else {
- [_delegate browserIDViewController: self didSucceedVerificationWithReceipt: receipt];
- }
- }
- };
-
- NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL: self.verifier cachePolicy: NSURLCacheStorageAllowed timeoutInterval: 5.0];
+ // POST the assertion to the verification endpoint. Then report back to our delegate about the
+ // results.
+
+ id verifyCompletionHandler = ^(NSHTTPURLResponse* response, NSData* data, NSError* error)
+ {
+ if (error) {
+ [_delegate browserIDViewController: self didFailVerificationWithError: error];
+ } else {
+ NSError* decodingError = nil;
+ NSDictionary* receipt = [NSJSONSerialization JSONObjectWithData: data options: 0 error: &decodingError];
+ if (decodingError) {
+ [_delegate browserIDViewController: self didFailVerificationWithError: decodingError];
+ } else {
+ [_delegate browserIDViewController: self didSucceedVerificationWithReceipt: receipt];
+ }
+ }
+ };
+
+ NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL: self.verifier cachePolicy: NSURLCacheStorageAllowed timeoutInterval: 5.0];
#if !__has_feature(objc_arc)
- [request autorelease];
+ [request autorelease];
#endif
- [request setHTTPShouldHandleCookies: YES];
- [request setHTTPMethod: @"POST"];
- [request setHTTPBody: [assertion dataUsingEncoding: NSUTF8StringEncoding]];
- [request setValue: @"text/plain" forHTTPHeaderField: @"content-type"];
-
- [NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue]
- completionHandler: verifyCompletionHandler];
+ [request setHTTPShouldHandleCookies: YES];
+ [request setHTTPMethod: @"POST"];
+ [request setHTTPBody: [assertion dataUsingEncoding: NSUTF8StringEncoding]];
+ [request setValue: @"text/plain" forHTTPHeaderField: @"content-type"];
+
+ [NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue]
+ completionHandler: verifyCompletionHandler];
}
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
- NSURL* url = [request URL];
-
- // The JavaScript side (the code injected in viewDidLoad will make callbacks to this native code by requesting
- // a BrowserIDViewController://callbackname/callback?data=foo style URL. So we capture those here and relay
- // them to our delegate.
-
- if ([[[url scheme] lowercaseString] isEqualToString: @"browseridviewcontroller"])
- {
- NSString* message = url.host;
- NSString* param = [[url query] substringFromIndex: [@"data=" length]];
- NSLog(@"MESSAGE '%@', param '%@'", message, param);
- if ([message isEqualToString: @"assertionReady"]) {
- NSRange separator = [param rangeOfString: @"&email="];
- if (separator.length > 0) {
- NSString* email = [param substringFromIndex: NSMaxRange(separator)];
- param = [param substringToIndex: separator.location];
- self.emailAddress = [email stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
- }
- param = [param stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
- if (_verifier) {
- [self verifyAssertion: param];
- } else {
- [_delegate browserIDViewController: self didSucceedWithAssertion: param];
- }
- }
-
- else if ([message isEqualToString: @"assertionFailure"]) {
- [_delegate browserIDViewController: self didFailWithReason: param];
- }
-
- else if ([message isEqualToString: @"gotEmail"]) {
- self.emailAddress = param;
- }
-
- return NO;
- }
-
- // If the user clicked on a link that escapes the browserid dialog, then we open it in Safari
-
- else if ([[[url scheme] lowercaseString] isEqualToString: @"http"] || [[[url scheme] lowercaseString] isEqualToString: @"https"])
- {
- if ([[url absoluteString] isEqualToString: kBrowserIDSignInURL] == NO)
- {
- [[UIApplication sharedApplication] openURL: url];
- return NO;
- }
- }
-
- return YES;
+ NSURL* url = [request URL];
+
+ // The JavaScript side (the code injected in viewDidLoad will make callbacks to this native code by requesting
+ // a BrowserIDViewController://callbackname/callback?data=foo style URL. So we capture those here and relay
+ // them to our delegate.
+
+ if ([[[url scheme] lowercaseString] isEqualToString: @"browseridviewcontroller"])
+ {
+ NSString* message = url.host;
+ NSString* param = [[url query] substringFromIndex: [@"data=" length]];
+ NSLog(@"MESSAGE '%@', param '%@'", message, param);
+ if ([message isEqualToString: @"assertionReady"]) {
+ NSRange separator = [param rangeOfString: @"&email="];
+ if (separator.length > 0) {
+ NSString* email = [param substringFromIndex: NSMaxRange(separator)];
+ param = [param substringToIndex: separator.location];
+ self.emailAddress = [email stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
+ }
+ param = [param stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
+ if (_verifier) {
+ [self verifyAssertion: param];
+ } else {
+ [_delegate browserIDViewController: self didSucceedWithAssertion: param];
+ }
+ }
+
+ else if ([message isEqualToString: @"assertionFailure"]) {
+ [_delegate browserIDViewController: self didFailWithReason: param];
+ }
+
+ else if ([message isEqualToString: @"gotEmail"]) {
+ self.emailAddress = param;
+ }
+
+ return NO;
+ }
+
+ // If the user clicked on a link that escapes the browserid dialog, then we open it in Safari
+
+ else if ([[[url scheme] lowercaseString] isEqualToString: @"http"] || [[[url scheme] lowercaseString] isEqualToString: @"https"])
+ {
+ if ([[url absoluteString] isEqualToString: kBrowserIDSignInURL] == NO)
+ {
+ [[UIApplication sharedApplication] openURL: url];
+ return NO;
+ }
+ }
+
+ return YES;
}
@end

0 comments on commit a5dc772

Please sign in to comment.