Dropbox authentication with OAuth2 implemented

This commit is contained in:
2016-03-30 01:31:18 +02:00
parent 71eea899e0
commit 54229c04fc
12 changed files with 134 additions and 8 deletions
+2
View File
@@ -6,10 +6,12 @@
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import "DropboxV2ObjC.h"
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property(strong, nonatomic) UIWindow *window;
@property(strong, nonatomic) DropboxV2ObjC *dbClient;
@end
+8
View File
@@ -13,6 +13,7 @@
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_dbClient = [[DropboxV2ObjC alloc] init];
return YES;
}
@@ -50,4 +51,11 @@
// appropriate. See also applicationDidEnterBackground:.
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// Display text
[_dbClient authorizeUserWithToke:url];
return YES;
}
@end
+4 -1
View File
@@ -89,6 +89,9 @@
<constraint firstAttribute="width" constant="147" id="30a-wW-H5A"/>
</constraints>
<state key="normal" title="Connect to Dropbox"/>
<connections>
<action selector="dbConnect:" destination="NBp-hT-qnu" eventType="touchUpInside" id="Sjs-Vk-aFg"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="n9p-C2-IND">
<rect key="frame" x="91" y="110" width="138" height="30"/>
@@ -1047,6 +1050,6 @@
<image name="triFlip" width="15" height="21"/>
</resources>
<inferredMetricsTieBreakers>
<segue reference="PbX-LR-FGE"/>
<segue reference="Thn-Z7-qri"/>
</inferredMetricsTieBreakers>
</document>
+21
View File
@@ -0,0 +1,21 @@
//
// DropboxV2ObjC.h
// FMC Planner 2
//
// Created by Kilian Hofmann on 29.03.16.
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DropboxV2ObjC : NSObject
@property(strong, nonatomic) NSString *token;
@property(strong, nonatomic) NSString *rootDirectory;
- (BOOL)authorizeUserWithToke:(NSURL *)token;
- (NSData *)downloadFromDropbox;
- (void)uploadToDropbox:(NSData *)data;
- (NSArray *)contentsOfPath:(NSString *)path;
@end
+35
View File
@@ -0,0 +1,35 @@
//
// DropboxV2ObjC.m
// FMC Planner 2
//
// Created by Kilian Hofmann on 29.03.16.
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import "DropboxV2ObjC.h"
@implementation DropboxV2ObjC
- (DropboxV2ObjC *)init {
self = [super init];
self.rootDirectory = @"/Apps/FMC Planner 2/";
return self;
}
- (BOOL)authorizeUserWithToke:(NSURL *)token {
NSScanner *scan = [NSScanner scannerWithString:[token absoluteString]];
NSString *error = [[NSString alloc] init];
[scan scanUpToString:@"&error=" intoString:&error];
if (![error isEqualToString:[token absoluteString]]) {
return false;
}
// No error, refine token
NSString *tokenUnrefined = [[NSString alloc] init];
[scan scanUpToString:@"&" intoString:&tokenUnrefined];
NSString *tokenRefined = [tokenUnrefined substringFromIndex:21];
_token = tokenRefined;
return true;
}
@end
+15 -2
View File
@@ -18,8 +18,23 @@
<string>1.0 DEV</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>x-fmc</string>
</array>
<key>CFBundleURLName</key>
<string>com.weebly.alikja.fmc-planner-2</string>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>dbapi-2</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
@@ -40,8 +55,6 @@
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
-1
View File
@@ -60,7 +60,6 @@
.row]]];
cell.textLabel.text = [data valueForKey:@"MENU@LSKR1"];
}
return cell;
}
@@ -6,6 +6,8 @@
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import "AppDelegate.h"
#import "DropboxV2ObjC.h"
#import "SharedDeclerations.h"
#import "TableViewController.h"
#import "ViewController.h"
@@ -15,4 +17,6 @@
@property(strong, nonatomic) ViewController *main;
- (IBAction)dbConnect:(UIButton *)sender;
@end
+17 -1
View File
@@ -5,7 +5,6 @@
// Created by Kilian Hofmann on 26.03.16.
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import "ViewControllerServiceMenu.h"
@implementation ViewControllerServiceMenu
@@ -30,4 +29,21 @@
((TableViewController *)[segue destinationViewController]).main = _main;
}
- (IBAction)dbConnect:(UIButton *)sender {
DropboxV2ObjC *db_client =
((AppDelegate *)[[UIApplication sharedApplication] delegate]).dbClient;
UIViewController *webController = [[UIViewController alloc] init];
webController.title = @"Dropbox";
UIWebView *web = [[UIWebView alloc] initWithFrame:webController.view.frame];
[webController.view addSubview:web];
[self.navigationController pushViewController:webController animated:YES];
[web loadRequest:
[NSURLRequest
requestWithURL:
[NSURL URLWithString:@"https://dropbox.com/1/oauth2/"
@"authorize?response_type=token&"
@"client_id=7q5bwtmi2h2iszh&redirect_"
@"uri=x-fmc:/"]]];
}
@end
+4 -3
View File
@@ -6,11 +6,12 @@
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import <UIKit/UIKit.h>
int main(int argc, char * argv[]) {
int main(int argc, char *argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([AppDelegate class]));
}
}