Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth2 support #159

Merged
merged 53 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3bc8843
Add user agent implemtation
nasli Jul 10, 2017
735f5d2
Use custom setter for user agent instead default to support also with…
nasli Jul 11, 2017
b4cc768
Fix precated messages
nasli Jul 11, 2017
9553526
Add error codes
davivel Aug 11, 2017
13ad10b
Add OCCredentialsDto to library and unify methods to set credentials …
davivel Aug 18, 2017
5156538
Clean-up erro codes
davivel Aug 25, 2017
757342e
Fix typo breaking tests build
davivel Aug 25, 2017
8f3eac7
Add specific NSError for server in maintenance mode
davivel Sep 7, 2017
f3e8ad4
Add some more HTTP error codes as known constants
davivel Sep 13, 2017
1de571b
Add OAuth2 errors to UtilsFramework.getErrorById()
davivel Sep 13, 2017
4b5de10
Add refresh token to request
nasli Aug 11, 2017
dd0b249
Update occommunication to store refresh token and expires in
nasli Aug 25, 2017
9d7bc7c
Add retry n tiemes in all network requests
nasli Aug 25, 2017
23ba7f2
Use constant to ntimes retry variable
nasli Aug 25, 2017
7785619
Add new OAuth2 configuration class that manages all OAuth parameters.…
nasli Aug 29, 2017
1c173da
Update oauth manager class to retry a sucessfull new credentials. Add…
nasli Aug 30, 2017
fd7685d
Add protocol to store new credentials
nasli Aug 30, 2017
a1c239e
Update credentials to store new tokens
nasli Aug 31, 2017
2e77860
Add parameter identifier into credentials object
nasli Sep 1, 2017
ebc76ee
Set same userId for new credentials
nasli Sep 1, 2017
93c3ba8
Refresh token and store new credentials propertly
nasli Sep 6, 2017
680bdc4
Update git ignore file to avoid xcshareddata
nasli Sep 6, 2017
04f3f4f
Resume new retry operation and set auth header value instead add to f…
nasli Sep 6, 2017
3134037
Set redirection block also for retries.
nasli Sep 6, 2017
5004bfd
Refactor uploads to retry ntimes
nasli Sep 7, 2017
8cfdee4
Remove not used retry
nasli Sep 7, 2017
1af7472
Fix base url.
nasli Sep 7, 2017
a9db816
Add silently retries into downloads network tasks
nasli Sep 13, 2017
e8565c4
Fix network lib issue that report delegate location previous the fail…
nasli Sep 13, 2017
624428d
Remove property not longer needed
nasli Sep 22, 2017
9cd5bf6
Use credentials object directly since is no longer needed the full co…
nasli Sep 22, 2017
35fc856
Rename some OAuth methods with accurate description
nasli Sep 22, 2017
3eb39dc
Use default message with more information for user
nasli Sep 22, 2017
081d6a9
Remove unnecessary class and update references
nasli Sep 25, 2017
feef0d9
Update store credentials method
nasli Sep 25, 2017
6ceb273
Merge pull request #162 from owncloud/refresh_oauth_token_library
davivel Sep 27, 2017
b745241
Move get auth data to the lib
nasli Sep 26, 2017
69d2c1d
Complete parameters of access token request, lost in traslation
davivel Sep 28, 2017
cc14f97
Prevent cast of nil in completion handler
davivel Sep 28, 2017
35a3801
Fix delegate methods handling redirections and authentication challen…
davivel Sep 28, 2017
eed53c5
Add protocol for optional check of user-accepted server certificates
davivel Sep 28, 2017
6b29fc2
Merge pull request #163 from owncloud/move_get_access_token_to_lib_li…
nasli Oct 4, 2017
15ce0f1
Not encode uri
nasli Oct 4, 2017
f6cbe66
Retry any request after it was cancelled by the system
nasli Oct 6, 2017
c8a6a27
Test cancelled request
nasli Oct 6, 2017
077b3e5
remove detect cancelled error code
nasli Oct 6, 2017
88447df
Fix for server OAuth refresh token responses without required data
nasli Oct 11, 2017
6993f5b
Refactor get user data and display name. Add displayName to credentia…
nasli Oct 16, 2017
d57639d
Not use handle error class in display name requests
nasli Oct 23, 2017
b434c57
Fix return request
nasli Oct 30, 2017
53ea3ed
Add NSCopying protocol into capabilities class
nasli Oct 30, 2017
9cb56fb
Test adding cookies to avoid reject from F5
nasli Oct 18, 2017
16bc3fb
Merge pull request #167 from owncloud/oauth_support_test_cookies_library
pablocarmu Nov 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Xcode
.DS_Store
*/build/*
_build/
*.pbxuser
!default.pbxuser
*.mode1v3
Expand All @@ -16,6 +17,8 @@ DerivedData
.idea/
*.hmap
*.xccheckout
*.pyc
xcshareddata/

#CocoaPods
Pods
5 changes: 3 additions & 2 deletions OCCommunicationLib/OCCommunicationLib/OCCapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#import <Foundation/Foundation.h>

@interface OCCapabilities : NSObject
@interface OCCapabilities : NSObject <NSCopying>

/*VERSION*/
@property (nonatomic) NSInteger versionMajor;
Expand Down Expand Up @@ -76,6 +76,7 @@
@property (nonatomic) BOOL isFileUndeleteEnabled;
@property (nonatomic) BOOL isFileVersioningEnabled;


- (void)encodeWithCoder:(NSCoder *)aCoder;
- (id)initWithCoder:(NSCoder *)aDecoder;

@end
119 changes: 119 additions & 0 deletions OCCommunicationLib/OCCommunicationLib/OCCapabilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,125 @@ - (id)init {
return self;
}

#pragma mark - NSCopying

-(id) copyWithZone:(NSZone *)zone {
OCCapabilities *capCopy = [[OCCapabilities alloc]init];
capCopy.versionMajor = self.versionMajor;
capCopy.versionMinor = self.versionMinor;
capCopy.versionMicro = self.versionMicro;
capCopy.versionString = self.versionString;
capCopy.versionEdition = self.versionEdition;

capCopy.corePollInterval = self.corePollInterval;

capCopy.isFilesSharingAPIEnabled = self.isFilesSharingAPIEnabled;

capCopy.isFilesSharingShareLinkEnabled = self.isFilesSharingShareLinkEnabled;

capCopy.isFilesSharingPasswordEnforcedEnabled = self.isFilesSharingPasswordEnforcedEnabled;

capCopy.isFilesSharingExpireDateByDefaultEnabled = self.isFilesSharingExpireDateByDefaultEnabled;
capCopy.isFilesSharingExpireDateEnforceEnabled = self.isFilesSharingExpireDateEnforceEnabled;
capCopy.filesSharingExpireDateDaysNumber = self.filesSharingExpireDateDaysNumber;

capCopy.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled = self.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled;
capCopy.isFilesSharingAllowPublicUploadsEnabled = self.isFilesSharingAllowPublicUploadsEnabled;
capCopy.isFilesSharingSupportsUploadOnlyEnabled = self.isFilesSharingSupportsUploadOnlyEnabled;
capCopy.isFilesSharingAllowUserCreateMultiplePublicLinksEnabled = self.isFilesSharingAllowUserCreateMultiplePublicLinksEnabled;

capCopy.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled = self.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled;
capCopy.isFilesSharingReSharingEnabled = self.isFilesSharingReSharingEnabled;

capCopy.isFilesSharingAllowUserSendSharesToOtherServersEnabled = self.isFilesSharingAllowUserSendSharesToOtherServersEnabled;
capCopy.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled = self.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled;

capCopy.isFileBigFileChunkingEnabled = self.isFileBigFileChunkingEnabled;
capCopy.isFileUndeleteEnabled = self.isFileUndeleteEnabled;
capCopy.isFileVersioningEnabled = self.isFileVersioningEnabled;

return capCopy;
}

#pragma mark - NSSecureCoding

+ (BOOL)supportsSecureCoding {
return YES;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInteger:self.versionMajor forKey:@"versionMajor"];
[aCoder encodeInteger:self.versionMinor forKey:@"versionMinor"];
[aCoder encodeInteger:self.versionMicro forKey:@"versionMicro"];
[aCoder encodeObject:self.versionString forKey:@"versionString"];
[aCoder encodeObject:self.versionEdition forKey:@"versionEdition"];

[aCoder encodeInteger:self.corePollInterval forKey:@"corePollInterval"];

[aCoder encodeBool:self.isFilesSharingAPIEnabled forKey:@"isFilesSharingAPIEnabled"];

[aCoder encodeBool:self.isFilesSharingShareLinkEnabled forKey:@"isFilesSharingShareLinkEnabled"];

[aCoder encodeBool:self.isFilesSharingPasswordEnforcedEnabled forKey:@"isFilesSharingPasswordEnforcedEnabled"];

[aCoder encodeBool:self.isFilesSharingExpireDateByDefaultEnabled forKey:@"isFilesSharingExpireDateByDefaultEnabled"];
[aCoder encodeBool:self.isFilesSharingExpireDateEnforceEnabled forKey:@"isFilesSharingExpireDateEnforceEnabled"];
[aCoder encodeInteger:self.filesSharingExpireDateDaysNumber forKey:@"filesSharingExpireDateDaysNumber"];

[aCoder encodeBool:self.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled forKey:@"isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled"];
[aCoder encodeBool:self.isFilesSharingAllowPublicUploadsEnabled forKey:@"isFilesSharingAllowPublicUploadsEnabled"];
[aCoder encodeBool:self.isFilesSharingSupportsUploadOnlyEnabled forKey:@"isFilesSharingSupportsUploadOnlyEnabled"];
[aCoder encodeBool:self.isFilesSharingAllowUserCreateMultiplePublicLinksEnabled forKey:@"isFilesSharingAllowUserCreateMultiplePublicLinksEnabled"];

[aCoder encodeBool:self.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled forKey:@"isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled"];
[aCoder encodeBool:self.isFilesSharingReSharingEnabled forKey:@"isFilesSharingReSharingEnabled"];

[aCoder encodeBool:self.isFilesSharingAllowUserSendSharesToOtherServersEnabled forKey:@"isFilesSharingAllowUserSendSharesToOtherServersEnabled"];
[aCoder encodeBool:self.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled forKey:@"isFilesSharingAllowUserReceiveSharesToOtherServersEnabled"];

[aCoder encodeBool:self.isFileBigFileChunkingEnabled forKey:@"isFileBigFileChunkingEnabled"];
[aCoder encodeBool:self.isFileUndeleteEnabled forKey:@"isFileUndeleteEnabled"];
[aCoder encodeBool:self.isFileVersioningEnabled forKey:@"isFileVersioningEnabled"];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [self init]) {
self.versionMajor = [aDecoder decodeIntegerForKey:@"versionMajor"];
self.versionMinor = [aDecoder decodeIntegerForKey:@"versionMinor"];
self.versionMicro = [aDecoder decodeIntegerForKey:@"versionMicro"];
self.versionString = [aDecoder decodeObjectForKey:@"versionString"];
self.versionEdition = [aDecoder decodeObjectForKey:@"versionEdition"];

self.corePollInterval = [aDecoder decodeIntegerForKey:@"corePollInterval"];

self.isFilesSharingAPIEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAPIEnabled"];

self.isFilesSharingShareLinkEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingShareLinkEnabled"];

self.isFilesSharingPasswordEnforcedEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingPasswordEnforcedEnabled"];

self.isFilesSharingExpireDateByDefaultEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingExpireDateByDefaultEnabled"];
self.isFilesSharingExpireDateEnforceEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingExpireDateEnforceEnabled"];
self.filesSharingExpireDateDaysNumber = [aDecoder decodeIntegerForKey:@"filesSharingExpireDateDaysNumber"];

self.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled"];
self.isFilesSharingAllowPublicUploadsEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowPublicUploadsEnabled"];
self.isFilesSharingSupportsUploadOnlyEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingSupportsUploadOnlyEnabled"];
self.isFilesSharingAllowUserCreateMultiplePublicLinksEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserCreateMultiplePublicLinksEnabled"];

self.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled"];
self.isFilesSharingReSharingEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingReSharingEnabled"];

self.isFilesSharingAllowUserSendSharesToOtherServersEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserSendSharesToOtherServersEnabled"];
self.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingAllowUserReceiveSharesToOtherServersEnabled"];

self.isFileBigFileChunkingEnabled = [aDecoder decodeBoolForKey:@"isFilesSharingReSharingEnabled"];
self.isFileUndeleteEnabled = [aDecoder decodeBoolForKey:@"isFileUndeleteEnabled"];
self.isFileVersioningEnabled = [aDecoder decodeBoolForKey:@"isFileVersioningEnabled"];
}
return self;
}

@end
113 changes: 71 additions & 42 deletions OCCommunicationLib/OCCommunicationLib/OCCommunication.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,19 @@

#import <Foundation/Foundation.h>
#import "OCServerFeatures.h"
#import "OCCredentialsDto.h"
#import "OCOAuth2Configuration.h"
#import "OCCredentialsStorage.h"
#import "OCTrustedCertificatesStore.h"

@class OCHTTPRequestOperation;
@class AFURLSessionManager;
@class AFSecurityPolicy;
@class OCCapabilities;

@protocol OCCredentialsStorageDelegate;

@interface OCCommunication : NSObject

//Type of credential
typedef enum {
credentialNotSet = -1,
credentialNormal = 0, //user, password
credentialCookie = 1,
credentialOauth = 2
} kindOfCredentialEnum;


typedef enum {
OCErrorUnknown = 90, //On all errors
OCErrorForbiddenCharacters = 100, //On create folder and rename
Expand All @@ -51,15 +46,27 @@ typedef enum {
OCErrorMovingFolderInsideItself = 112, //On move file or folder
OCErrorFileToUploadDoesNotExist = 120, //The file that we want upload does not exist
OCErrorForbiddenUnknown = 130, //For example, no write permissions to the target folder of an upload
OCErrorForbiddenWithSpecificMessage = 131 // For example, forbidden due to a firewall rule
OCErrorForbiddenWithSpecificMessage = 131, // For example, forbidden due to a firewall rule
OCErrorServerMaintenanceMode = 140,

OCErrorOAuth2Error = 1000,
OCErrorOAuth2ErrorAccessDenied = 1010,

OCErrorSslRecoverablePeerUnverified = 1100

} OCErrorEnum;


//Private properties
@property NSInteger kindOfCredential;
@property (nonatomic, strong) NSString *user;
@property (nonatomic, strong) NSString *password;
@property (nonatomic, strong) OCCredentialsDto *credDto;

@property (nonatomic, strong) NSString *userAgent;

@property (nonatomic, strong) OCOAuth2Configuration *oauth2Configuration;
@property (nonatomic, strong) id<OCCredentialsStorageDelegate> credentialsStorage;
@property (nonatomic, strong) id<OCTrustedCertificatesStore> trustedCertificatesStore;


//Public properties
@property (nonatomic, strong) NSMutableArray *downloadTaskNetworkQueueArray;

Expand Down Expand Up @@ -107,52 +114,39 @@ typedef enum {

#pragma mark - Credentials


///-----------------------------------
/// @name Set Credential With User
/// @name Set Credentials
///-----------------------------------

/**
* Method to set credentials with user and password
*
* @param user -> NSString username
* @param password -> NSString password
* @param credentials -> OCCredentialsDto credentials
*/
- (void) setCredentialsWithUser:(NSString*) user andPassword:(NSString*) password;


///-----------------------------------
/// @name Set Credential with cookie
///-----------------------------------

/**
* Method that set credentials with cookie.
* Used for SAML servers.
*
* @param cookie -> NSString cookie string
*/
- (void) setCredentialsWithCookie:(NSString*) cookie;
- (void) setCredentials:(OCCredentialsDto *) credentials;


///-----------------------------------
/// @name Set Credential with OAuth
/// @name Set User Agent
///-----------------------------------

/**
* Method to set credentials for OAuth with token
*
* @param token -> NSString token
*/
- (void) setCredentialsOauthWithToken:(NSString*) token;

/**
* @optional
*
* Method to set the user agent, in order to identify the client app to the server.
*
* @param userAgent -> String with the user agent. Ex. "iOS-ownCloud"
*/
- (void) setUserAgent:(NSString *)userAgent;
- (void) setValueOfUserAgent:(NSString *) userAgent;


- (void) setValueOauth2Configuration:(OCOAuth2Configuration *)oauth2Configuration;

- (void) setValueCredentialsStorage:(id<OCCredentialsStorageDelegate>)credentialsStorage;

- (void) setValueTrustedCertificatesStore:(id<OCTrustedCertificatesStore>)trustedCertificatesStore;

/*
* Method to update the a request with the current credentials
Expand Down Expand Up @@ -490,11 +484,44 @@ typedef enum {
successRequest:(void(^)(NSHTTPURLResponse *response, NSString *serverVersion, NSString *redirectedServer)) success
failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure;

///-----------------------------------
/// @name getUserDataOfServer
///-----------------------------------

/**
* Method to get the User data.
*
* @param path -> NSString server path
*
* @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
*/
- (void) getUserDataOfServer:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication
success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success
failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest;

///-----------------------------------
/// @name getUserDisplayNameOfServer
///-----------------------------------

/**
* Method to get the User display name.
*
* @param path -> NSString server path
*
* @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
*/
- (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication
success:(void(^)(NSHTTPURLResponse *response, NSString *displayName, NSString *redirectedServer))success
failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest;


///-----------------------------------
/// @name requestForUserNameByCookie
///-----------------------------------

/**
* DEPRECATED use - getUserDataOfServer:onCommunication: or getUserDisplayNameOfServer:onCommunication: instead
*
* Method to get the User name by the cookie of the session. Used with SAML servers.
*
* @param cookieString -> NSString The cookie of the session
Expand All @@ -507,14 +534,15 @@ typedef enum {

- (void) getUserNameByCookie:(NSString *) cookieString ofServerPath:(NSString *)path onCommunication:
(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success
failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failure;
failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failure
__deprecated_msg("Use - getUserDataOfServer:onCommunication: or getUserDisplayNameOfServer:onCommunication: instead");

///-----------------------------------
/// @name Get Features Supported By Server
///-----------------------------------

/**
* DEPRECATED use + getFeaturesSupportedByServerForVersion: instead
* DEPRECATED use - getFeaturesSupportedByServerForVersion: instead
*
* Method get the features supported by the path server using the version string.
*
Expand All @@ -536,7 +564,8 @@ typedef enum {

- (void) getFeaturesSupportedByServer:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
successRequest:(void(^)(NSHTTPURLResponse *response, BOOL hasShareSupport, BOOL hasShareeSupport, BOOL hasCookiesSupport, BOOL hasForbiddenCharactersSupport, BOOL hasCapabilitiesSupport, BOOL hasFedSharesOptionShareSupport, NSString *redirectedServer)) success
failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure __deprecated_msg("Use + getFeaturesSupportedByServerForVersion: instead");
failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure
__deprecated_msg("Use - getFeaturesSupportedByServerForVersion: instead");


///-----------------------------------
Expand Down
Loading