Skip to content

Commit

Permalink
Merge pull request #23 from ricardopereira/realtime-tests
Browse files Browse the repository at this point in the history
Merged Yavor work, refactoring and RSA1 tests
  • Loading branch information
mattheworiordan committed Oct 8, 2015
2 parents 006d61b + 212f64e commit 2f08729
Show file tree
Hide file tree
Showing 106 changed files with 4,865 additions and 3,545 deletions.
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Created by https://www.gitignore.io/api/objective-c

### Objective-C ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

### Objective-C Patch ###
*.xcscmblueprint

2 changes: 2 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ target 'ablySpec' do

pod 'Quick', '~> 0.3.0'
pod 'Nimble', '~> 1.0.0'
# Helpers
pod 'Runes', '~> 2.0.0'
pod 'SwiftyJSON', '~> 2.2.1'
end
3 changes: 3 additions & 0 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
PODS:
- Nimble (1.0.0)
- Quick (0.3.1)
- Runes (2.0.0)
- SocketRocket (0.3.1-beta2)
- SwiftyJSON (2.2.1)

DEPENDENCIES:
- Nimble (~> 1.0.0)
- Quick (~> 0.3.0)
- Runes (~> 2.0.0)
- SocketRocket (~> 0.3.1-beta2)
- SwiftyJSON (~> 2.2.1)

SPEC CHECKSUMS:
Nimble: 8bee528e5fcc403653076545db562d2b5db7bb87
Quick: 824572d3d198d51e52cf4aa722cebf7e59952a35
Runes: 4fe81355f4620b76b02176222d264b33e60dba51
SocketRocket: 7284ab9370a06c99aba92b2fe3a32aedd0f9a6fa
SwiftyJSON: ae2d0a3d68025d136602a33c4ee215091ced3e33

Expand Down
23 changes: 23 additions & 0 deletions ably-ios/ARTAuth+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ARTAuth+Private.h
// ably
//
// Created by Ricardo Pereira on 03/10/2015.
// Copyright (c) 2015 Ably. All rights reserved.
//

#import "ARTAuth.h"

ART_ASSUME_NONNULL_BEGIN

@interface ARTAuth (Private)

- (ARTAuthOptions *)mergeOptions:(ARTAuthOptions *)customOptions;
- (ARTAuthTokenParams *)mergeParams:(ARTAuthTokenParams *)customParams;

- (NSURL *)buildURL:(ARTAuthOptions *)options withParams:(ARTAuthTokenParams *)params;
- (NSMutableURLRequest *)buildRequest:(ARTAuthOptions *)options withParams:(ARTAuthTokenParams *)params;

@end

ART_ASSUME_NONNULL_END
114 changes: 38 additions & 76 deletions ably-ios/ARTAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,94 +7,56 @@
//

#import <Foundation/Foundation.h>
#import <ably/ARTHttp.h>
#import <ably/ARTTypes.h>
#import "ARTTypes.h"
#import "ARTLog.h"

@class ARTRest;

@class ARTLog;
@interface ARTTokenDetails : NSObject

@property (readonly, strong, nonatomic) NSString *token;
@property (readonly, assign, nonatomic) int64_t expires;
@property (readonly, assign, nonatomic) int64_t issued;
@property (readonly, strong, nonatomic) NSString *capability;
@property (readonly, strong, nonatomic) NSString *clientId;

- (instancetype)init UNAVAILABLE_ATTRIBUTE;

- (instancetype)initWithId:(NSString *)id expires:(int64_t)expires issued:(int64_t)issued capability:(NSString *)capability clientId:(NSString *)clientId;

@end

@interface ARTAuthTokenParams : NSObject

@property (readonly, strong, nonatomic) NSString *keyName;
@property (readonly, assign, nonatomic) int64_t ttl;
@property (readonly, strong, nonatomic) NSString *capability;
@property (readonly, strong, nonatomic) NSString *clientId;
@property (readonly, assign, nonatomic) int64_t timestamp;
@property (readonly, strong, nonatomic) NSString *nonce;
@property (readonly, strong, nonatomic) NSString *mac;


- (instancetype)init UNAVAILABLE_ATTRIBUTE;
@class ARTClientOptions;
@class ARTAuthOptions;
@class ARTAuthTokenParams;
@class ARTAuthTokenDetails;
@class ARTAuthTokenRequest;

- (instancetype)initWithId:(NSString *)id ttl:(int64_t)ttl capability:(NSString *)capability clientId:(NSString *)clientId timestamp:(int64_t)timestamp nonce:(NSString *)nonce mac:(NSString *)mac;
ART_ASSUME_NONNULL_BEGIN

-(NSDictionary *) asDictionary;
@end
#pragma mark - ARTAuth

typedef id<ARTCancellable>(^ARTAuthCb)(void(^continuation)(ARTStatus *,ARTTokenDetails *));
typedef id<ARTCancellable>(^ARTSignedTokenRequestCb)(ARTAuthTokenParams *, void(^continuation)(ARTAuthTokenParams *));
typedef NS_ENUM(NSUInteger, ARTAuthMethod) {
ARTAuthMethodBasic,
ARTAuthMethodToken
};

@interface ARTAuthOptions : NSObject

@property (nonatomic, weak) ARTLog * logger;
@property (readwrite, strong, nonatomic) ARTAuthCb authCallback;
@property (readwrite, strong, nonatomic) ARTSignedTokenRequestCb signedTokenRequestCallback;
@property (readwrite, strong, nonatomic) ARTAuthTokenParams *tokenParams;
@property (readwrite, strong, nonatomic) NSURL *authUrl;
@property (readwrite, strong, nonatomic) NSString *keyName;
@property (readwrite, strong, nonatomic) NSString *keySecret;
@property (readwrite, strong, nonatomic) NSString *token;
@property (readwrite, strong, nonatomic) NSString *capability;
@property (readwrite, strong, nonatomic) NSString *nonce;
@property (readwrite, assign, nonatomic) int64_t ttl;
@property (readwrite, strong, nonatomic) NSDictionary *authHeaders;
@property (readwrite, strong, nonatomic) NSString *clientId;
@property (readwrite, assign, nonatomic) BOOL queryTime;
@property (readwrite, assign, nonatomic) BOOL useTokenAuth;
@property (readwrite, assign, nonatomic) ARTTokenDetails * tokenDetails;


- (instancetype)init;
- (instancetype)initWithKey:(NSString *)key;

+ (instancetype)options;
+ (instancetype)optionsWithKey:(NSString *)key;

- (instancetype)clone;

@end

@interface ARTAuth : NSObject

- (instancetype)initWithRest:(ARTRest *) rest options:(ARTAuthOptions *) options;
- (ARTAuthOptions *)getAuthOptions;
- (ARTAuthMethod)getAuthMethod;
@property (nonatomic, weak) ARTLog *logger;
@property (nonatomic, readonly, strong) ARTAuthOptions *options;
@property (nonatomic, readonly, strong) ARTAuthTokenDetails *tokenDetails;
@property (nonatomic, readonly, assign) ARTAuthMethod method;

- (instancetype)init:(ARTRest *)rest withOptions:(ARTClientOptions *)options;

/**
# (RSA8) Auth#requestToken
Implicitly creates a `TokenRequest` if required, and requests a token from Ably if required.
`TokenParams` and `AuthOptions` are optional.
When provided, the values supersede matching client library configured params and options.
- Parameter tokenParams: Token params (optional).
- Parameter authOptions: Authentication options (optional).
- Parameter callback: Completion callback (ARTAuthTokenDetails, NSError).
*/
- (void)requestToken:(art_nullable ARTAuthTokenParams *)tokenParams withOptions:(art_nullable ARTAuthOptions *)authOptions
callback:(void (^)(ARTAuthTokenDetails *__art_nullable tokenDetails, NSError *__art_nullable error))callback;

- (void)authorise:(art_nullable ARTAuthTokenParams *)tokenParams options:(art_nullable ARTAuthOptions *)options force:(BOOL)force
callback:(void (^)(ARTAuthTokenDetails *__art_nullable tokenDetails, NSError *__art_nullable error))callback;

- (void)createTokenRequest:(art_nullable ARTAuthTokenParams *)tokenParams options:(art_nullable ARTAuthOptions *)options
callback:(void (^)(ARTAuthTokenRequest *__art_nullable tokenRequest, NSError *__art_nullable error))callback;

- (ARTAuthTokenParams *) getTokenParams;
- (id<ARTCancellable>)authHeadersUseBasic:(BOOL)useBasic cb:(id<ARTCancellable>(^)(NSDictionary *))cb;
- (id<ARTCancellable>)authParams:(id<ARTCancellable>(^)(NSDictionary *))cb;
- (id<ARTCancellable>)requestToken:(id<ARTCancellable>(^)(ARTTokenDetails *))cb;
- (id<ARTCancellable>)authTokenForceReauth:(BOOL)force cb:(id<ARTCancellable>(^)(ARTTokenDetails *))cb;
- (void)attemptTokenFetch:(void (^)()) cb;
- (bool)canRequestToken;
@end

+ (ARTSignedTokenRequestCb)defaultSignedTokenRequestCallback:(ARTAuthOptions *)authOptions rest:(ARTRest *)rest;
@end
ART_ASSUME_NONNULL_END
Loading

0 comments on commit 2f08729

Please sign in to comment.