Dropbox authentication with OAuth2 implemented
This commit is contained in:
parent
71eea899e0
commit
54229c04fc
@ -16,6 +16,7 @@
|
||||
E22EE9DC1C9DB7B3001F5BC0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E22EE9DB1C9DB7B3001F5BC0 /* Assets.xcassets */; };
|
||||
E22EE9EA1C9DB7B4001F5BC0 /* FMC_Planner_2Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = E22EE9E91C9DB7B4001F5BC0 /* FMC_Planner_2Tests.m */; };
|
||||
E22EE9F51C9DB7B4001F5BC0 /* FMC_Planner_2UITests.m in Sources */ = {isa = PBXBuildFile; fileRef = E22EE9F41C9DB7B4001F5BC0 /* FMC_Planner_2UITests.m */; };
|
||||
E2549C761CAB2D3F00562602 /* DropboxV2ObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = E2549C751CAB2D3F00562602 /* DropboxV2ObjC.m */; };
|
||||
E2763C721CA6C8AE001E4EDA /* LSKs.plist in Resources */ = {isa = PBXBuildFile; fileRef = E2763C711CA6C8AE001E4EDA /* LSKs.plist */; };
|
||||
E2763C751CA6E777001E4EDA /* ViewControllerServiceMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = E2763C741CA6E777001E4EDA /* ViewControllerServiceMenu.m */; };
|
||||
E280F3A41CA7C71500DF2A05 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E280F3A31CA7C71500DF2A05 /* TableViewController.m */; };
|
||||
@ -64,6 +65,8 @@
|
||||
E22EE9F01C9DB7B4001F5BC0 /* FMC Planner 2UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "FMC Planner 2UITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
E22EE9F41C9DB7B4001F5BC0 /* FMC_Planner_2UITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FMC_Planner_2UITests.m; sourceTree = "<group>"; };
|
||||
E22EE9F61C9DB7B4001F5BC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
E2549C741CAB2D3F00562602 /* DropboxV2ObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DropboxV2ObjC.h; sourceTree = "<group>"; };
|
||||
E2549C751CAB2D3F00562602 /* DropboxV2ObjC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DropboxV2ObjC.m; sourceTree = "<group>"; };
|
||||
E2763C711CA6C8AE001E4EDA /* LSKs.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = LSKs.plist; sourceTree = "<group>"; };
|
||||
E2763C731CA6E777001E4EDA /* ViewControllerServiceMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewControllerServiceMenu.h; sourceTree = "<group>"; };
|
||||
E2763C741CA6E777001E4EDA /* ViewControllerServiceMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewControllerServiceMenu.m; sourceTree = "<group>"; };
|
||||
@ -170,6 +173,8 @@
|
||||
children = (
|
||||
E2A9270C1CA2FD6D00606E07 /* Implementation */,
|
||||
E2A9270B1CA2FD6000606E07 /* Header */,
|
||||
E2549C741CAB2D3F00562602 /* DropboxV2ObjC.h */,
|
||||
E2549C751CAB2D3F00562602 /* DropboxV2ObjC.m */,
|
||||
);
|
||||
name = ViewControllers;
|
||||
sourceTree = "<group>";
|
||||
@ -376,6 +381,7 @@
|
||||
files = (
|
||||
E22EE9D71C9DB7B3001F5BC0 /* ViewController.m in Sources */,
|
||||
E22EE9D41C9DB7B3001F5BC0 /* AppDelegate.m in Sources */,
|
||||
E2549C761CAB2D3F00562602 /* DropboxV2ObjC.m in Sources */,
|
||||
E22EE9D11C9DB7B3001F5BC0 /* main.m in Sources */,
|
||||
E2A927161CA30CEE00606E07 /* SharedDeclerations.m in Sources */,
|
||||
E227C7831C9F42AB00DE0CA4 /* ViewControllerKeyboard.m in Sources */,
|
||||
|
||||
@ -2,4 +2,22 @@
|
||||
<Bucket
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "FMC Planner 2/DropboxV2ObjC.m"
|
||||
timestampString = "480986473.401724"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "20"
|
||||
endingLineNumber = "20"
|
||||
landmarkName = "-authorizeUserWithToke:"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
FMC Planner 2/DropboxV2ObjC.h
Normal file
21
FMC Planner 2/DropboxV2ObjC.h
Normal 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
FMC Planner 2/DropboxV2ObjC.m
Normal file
35
FMC Planner 2/DropboxV2ObjC.m
Normal 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
|
||||
@ -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>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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]));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user