Commit bb2fc675 authored by Soomin Lee's avatar Soomin Lee Committed by Jean-Baptiste Kempf

Migrate GTM-OAuth2 to GTMAppAuth for GDrive authentication

Google has deprecated GTM-OAuth2 and has replaced it with GTMAppAuth.
This patch migrates the use of GTM-OAuth2 library.
Additionally GTMAppAuth needs a new clientID for iOS clients.
Therefore for this patch to work correctly, kVLCGoogleDriveClientID and kVLCGoogleRedirectURI
needs to be setted in VLCGoogleDriveConstants.h as well as GoogleAuth in iOS-Info.plist
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 9191c017
......@@ -16,13 +16,13 @@ pod 'box-ios-sdk-v2', :git => 'git://github.com/fkuehne/box-ios-sdk-v2.git' #has
pod 'CocoaHTTPServer', :git => 'git://github.com/fkuehne/CocoaHTTPServer.git' # has our fixes
pod 'RESideMenu', '~>4.0.7'
pod 'GoogleAPIClient/Drive'
pod 'GTMOAuth2'
pod 'VLC-LXReorderableCollectionViewFlowLayout', '0.1.3v'
pod 'VLC-WhiteRaccoon'
pod 'VLC-LiveSDK', '5.7.0x'
pod 'VLC-Dropbox-v1-SDK', '1.3.14w'
pod 'MediaLibraryKit-unstable'
pod 'MobileVLCKit-unstable', '3.0.0a10'
pod 'GTMAppAuth'
end
......@@ -38,7 +38,6 @@ pod 'box-ios-sdk-v2', :git => 'git://github.com/fkuehne/box-ios-sdk-v2.git' #has
pod 'CocoaHTTPServer', :git => 'git://github.com/fkuehne/CocoaHTTPServer.git' # has our fixes
pod 'RESideMenu', '~>4.0.7'
pod 'GoogleAPIClient/Drive'
pod 'GTMOAuth2'
pod 'VLC-LXReorderableCollectionViewFlowLayout', '0.1.3v'
pod 'VLC-WhiteRaccoon'
pod 'VLC-LiveSDK', '5.7.0x'
......@@ -60,7 +59,6 @@ pod 'box-ios-sdk-v2', :git => 'git://github.com/fkuehne/box-ios-sdk-v2.git' #has
pod 'CocoaHTTPServer', :git => 'git://github.com/fkuehne/CocoaHTTPServer.git' # has our fixes
pod 'RESideMenu', '~>4.0.7'
pod 'GoogleAPIClient/Drive'
pod 'GTMOAuth2'
pod 'VLC-LXReorderableCollectionViewFlowLayout', '0.1.3v'
pod 'VLC-WhiteRaccoon'
pod 'VLC-LiveSDK', '5.7.0x'
......
......@@ -232,6 +232,16 @@
<string>vlc-x-callback</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>GoogleAuth</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.CLIENT</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>280.0</string>
......
......@@ -17,6 +17,7 @@
#import "VLCMenuTableViewController.h"
#import "VLCDownloadViewController.h"
#import "VLCWatchCommunication.h"
#import <AppAuth/AppAuth.h>
@class VLCLibraryViewController;
......@@ -32,4 +33,6 @@ extern NSString *const VLCDropboxSessionWasAuthorized;
@property (nonatomic, readonly) BOOL passcodeValidated;
@property (atomic, strong) id<OIDAuthorizationFlowSession> currentGoogleAuthorizationFlow;
@end
......@@ -12,6 +12,7 @@
* Carola Nitz <nitz.carola # googlemail.com>
* Tamas Timar <ttimar.vlc # gmail.com>
* Tobias Conradi <videolan # tobias-conradi.de>
* Soomin Lee <TheHungryBu # gmail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
......@@ -296,6 +297,12 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
return YES;
}
//Handles Google Authorization flow.
if ([_currentGoogleAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
_currentGoogleAuthorizationFlow = nil;
return YES;
}
if (_libraryViewController && url != nil) {
APLog(@"%@ requested %@ to be opened", sourceApplication, url);
......
......@@ -10,8 +10,13 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#define kVLCGoogleDriveClientID @"775640710334.apps.googleusercontent.com"
//TODO: Add ClientID
//ClientID formating: @"xyz.apps.googleusercontent.com"
#define kVLCGoogleDriveClientID @""
#define kKeychainItemName @"vlc-ios"
//TODO: Add RedirectURI
//RedirectURI formating: @"com.googleusercontent.apps.xyz:/oauthredirect"
#define kVLCGoogleRedirectURI @""
#warning Google Drive app secret missing, login will fail
#define kVLCGoogleDriveClientSecret @""
//#define kVLCGoogleDriveAppKey @"a60fc6qj9zdg7bw"
......
......@@ -7,6 +7,7 @@
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
* Felix Paul Kühne <fkuehne # videolan.org>
* Soomin Lee <TheHungryBu # gmail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
......@@ -17,8 +18,8 @@
#import "VLCMediaFileDiscoverer.h"
#import <XKKeychain/XKKeychain.h>
#import "GTMOAuth2ViewControllerTouch.h"
#import "GTMOAuth2SignIn.h"
#import <AppAuth/AppAuth.h>
#import <GTMAppAuth/GTMAppAuth.h>
@interface VLCGoogleDriveController ()
{
......@@ -60,7 +61,7 @@
{
[self restoreFromSharedCredentials];
self.driveService = [GTLServiceDrive new];
self.driveService.authorizer = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName clientID:kVLCGoogleDriveClientID clientSecret:kVLCGoogleDriveClientSecret];
self.driveService.authorizer = [GTMAppAuthFetcherAuthorization authorizationFromKeychainForName:kKeychainItemName];
}
- (void)stopSession
......@@ -72,7 +73,6 @@
- (void)logout
{
[GTMOAuth2ViewControllerTouch removeAuthFromKeychainForName:kKeychainItemName];
self.driveService.authorizer = nil;
NSUbiquitousKeyValueStore *ubiquitousStore = [NSUbiquitousKeyValueStore defaultStore];
[ubiquitousStore setString:nil forKey:kVLCStoreGDriveCredentials];
......@@ -87,7 +87,9 @@
if (!self.driveService) {
[self startSession];
}
BOOL ret = [((GTMOAuth2Authentication *)self.driveService.authorizer) canAuthorize];
BOOL ret = [(GTMAppAuthFetcherAuthorization *)self.driveService.authorizer canAuthorize];
if (ret) {
[self shareCredentials];
}
......@@ -207,7 +209,7 @@
- (void)streamFile:(GTLDriveFile *)file
{
NSString *token = ((GTMOAuth2Authentication *)self.driveService.authorizer).accessToken;
NSString *token = [((GTMAppAuthFetcherAuthorization *)self.driveService.authorizer).authState.lastTokenResponse accessToken];
NSString *urlString = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?alt=media&access_token=%@",
file.identifier, token];
......
......@@ -7,6 +7,7 @@
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
* Felix Paul Kühne <fkuehne # videolan.org>
* Soomin Lee <TheHungryBu # gmail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
......@@ -17,15 +18,14 @@
#import "UIDevice+VLC.h"
#import "VLCCloudStorageTableViewCell.h"
#import "GTMOAuth2ViewControllerTouch.h"
#import "GTMOAuth2SignIn.h"
#import <AppAuth/AppAuth.h>
#import <GTMAppAuth/GTMAppAuth.h>
@interface VLCGoogleDriveTableViewController () <VLCCloudStorageTableViewCell>
{
VLCGoogleDriveController *_googleDriveController;
GTLDriveFile *_selectedFile;
GTMOAuth2ViewControllerTouch *_authController;
}
@end
......@@ -66,31 +66,6 @@
}
}
- (GTMOAuth2ViewControllerTouch *)createAuthController
{
_authController = [GTMOAuth2ViewControllerTouch controllerWithScope:kGTLAuthScopeDrive
clientID:kVLCGoogleDriveClientID
clientSecret:kVLCGoogleDriveClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
return _authController;
}
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)authResult error:(NSError *)error
{
self.authorizationInProgress = NO;
if (error != nil) {
APLog(@"%s: error: %@", __PRETTY_FUNCTION__, error);
_googleDriveController.driveService.authorizer = nil;
} else {
_googleDriveController.driveService.authorizer = authResult;
}
[self updateViewAfterSessionChange];
[self.activityIndicator startAnimating];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
......@@ -180,8 +155,33 @@
- (IBAction)loginAction:(id)sender
{
if (![_googleDriveController isAuthorized]) {
self.authorizationInProgress = YES;
[self.navigationController pushViewController:[self createAuthController] animated:YES];
// Build the request with the clientID and scopes.
OIDAuthorizationRequest *request = [[OIDAuthorizationRequest alloc] initWithConfiguration:[GTMAppAuthFetcherAuthorization configurationForGoogle]
clientId:kVLCGoogleDriveClientID
clientSecret:kVLCGoogleDriveClientSecret
scopes:@[OIDScopeOpenID, kGTLAuthScopeDrive]
redirectURL:[NSURL URLWithString:kVLCGoogleRedirectURI]
responseType:OIDResponseTypeCode
additionalParameters:nil];
// Perform the previously built request and saving the current authorization flow.
((VLCAppDelegate *)[UIApplication sharedApplication].delegate).currentGoogleAuthorizationFlow = [OIDAuthState authStateByPresentingAuthorizationRequest:request presentingViewController:self
callback:^(OIDAuthState *_Nullable authState, NSError *_Nullable error) {
self.authorizationInProgress = NO;
if (authState) {
// Upon successful completion...
_googleDriveController.driveService.authorizer = [[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:authState];
[self updateViewAfterSessionChange];
[self.activityIndicator startAnimating];
} else {
_googleDriveController.driveService.authorizer = nil;
}
}];
} else {
[_googleDriveController logout];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment