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

Delegate objects are nullified in dealloc() method #163

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
12 changes: 9 additions & 3 deletions NXOAuth2Account+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
// the full licence.
//

#import "NXOAuth2Account.h"
#import <OAuth2Client/NXOAuth2Account.h>

@protocol NXApplication;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep in line with the framework this should be called NXOAuth2Application


@interface NXOAuth2Account (Private)

@property (nonatomic, readonly) id<NXApplication> application;

- (instancetype)initAccountWithOAuthClient:(NXOAuth2Client *)oauthClient
accountType:(NSString *)accountType;
accountType:(NSString *)accountType
application:(id<NXApplication>)app;

- (instancetype)initAccountWithAccessToken:(NXOAuth2AccessToken *)accessToken
accountType:(NSString *)accountType;
accountType:(NSString *)accountType
application:(id<NXApplication>)app /*NS_DESIGNATED_INITIALIZER*/ NS_REQUIRES_SUPER;

@end
237 changes: 137 additions & 100 deletions OAuth2Client.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions OAuth2Client/NXApplication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NXApplication.h
// OAuth2Client
//
// Created by Oleksandr Dodatko on 2/2/15.
// Copyright (c) 2015 nxtbgthng. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol NXApplication <NSObject>

-(BOOL)openURL:(NSURL*)url;

@end
33 changes: 33 additions & 0 deletions OAuth2Client/NXOAuth2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// NXOAuth2.h
// OAuth2Client
//
// Created by Ullrich Schäfer on 13.09.10.
//
// Copyright 2010 nxtbgthng. All rights reserved.
//
// Licenced under the new BSD-licence.
// See README.md in this repository for
// the full licence.
//


#import <OAuth2Client/NXApplication.h>
#import <OAuth2Client/NXOAuth2Client.h>
#import <OAuth2Client/NXOAuth2ClientDelegate.h>
#import <OAuth2Client/NXOAuth2AccessToken.h>
#import <OAuth2Client/NXOAuth2Connection.h>
#import <OAuth2Client/NXOAuth2ConnectionDelegate.h>
#import <OAuth2Client/NXOAuth2TrustDelegate.h>
#import <OAuth2Client/NXOAuth2Constants.h>
#import <OAuth2Client/NXOAuth2FileStreamWrapper.h>
#import <OAuth2Client/NXOAuth2PostBodyStream.h>
#import <OAuth2Client/NXOAuth2AccountStore.h>
#import <OAuth2Client/NXOAuth2Account.h>
#import <OAuth2Client/NXOAuth2Request.h>

#pragma mark Helpers

#import <OAuth2Client/NSURL+NXOAuth2.h>
#import <OAuth2Client/NSString+NXOAuth2.h>
#import <OAuth2Client/NSData+NXOAuth2.h>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

#import <Foundation/Foundation.h>

#import "NXOAuth2TrustDelegate.h"

@class NXOAuth2Account;
@class NXOAuth2Connection;
@protocol NXApplication;


#pragma mark Notifications

Expand Down Expand Up @@ -75,7 +76,13 @@ typedef void(^NXOAuth2PreparedAuthorizationURLHandler)(NSURL *preparedURL);
NSMutableDictionary *trustedCertificatesHandler;
}

+ (instancetype)sharedStore;
+(instancetype)sharedStoreForApplication:(id<NXApplication>)uiApplication;
-(instancetype)init NS_UNAVAILABLE;
+(instancetype)new NS_UNAVAILABLE;

// Private API
//-(instancetype)initWithApplication:(id<NXApplication>)uiApplication NS_DESIGNATED_INITIALIZER NS_REQUIRES_SUPER __attribute((nonnull));


#pragma mark Accessors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
//

#import <Foundation/Foundation.h>

#import "NXOAuth2ClientDelegate.h"
#import "NXOAuth2ConnectionDelegate.h"
#import <OAuth2Client/NXOAuth2ConnectionDelegate.h>

extern NSString * const NXOAuth2ClientConnectionContextTokenRequest;
extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;

@class NXOAuth2Connection, NXOAuth2AccessToken;
@class NXOAuth2Connection;
@class NXOAuth2AccessToken;
@protocol NXOAuth2ClientDelegate;

/*!
* The OAuth 2.0 client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// the full licence.
//

#import "NXOAuth2Constants.h"
#import "NXOAuth2TrustDelegate.h"

#import <OAuth2Client/NXOAuth2TrustDelegate.h>

@class NXOAuth2Client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//

#import <Foundation/Foundation.h>
#import <OAuth2Client/NXOAuth2RequestCallbacks.h>

#import "NXOAuth2Constants.h"

@class NXOAuth2Client;
@protocol NXOAuth2ConnectionDelegate;
Expand Down Expand Up @@ -46,10 +46,6 @@ extern NSString * const NXOAuth2ConnectionDidStartNotification;
extern NSString * const NXOAuth2ConnectionDidEndNotification;


typedef void(^NXOAuth2ConnectionResponseHandler)(NSURLResponse *response, NSData *responseData, NSError *error);
typedef void(^NXOAuth2ConnectionSendingProgressHandler)(unsigned long long bytesSend, unsigned long long bytesTotal);


@interface NXOAuth2Connection : NSObject {
@private
NSURLConnection *connection;
Expand Down Expand Up @@ -87,11 +83,11 @@ typedef void(^NXOAuth2ConnectionSendingProgressHandler)(unsigned long long bytes
@property (nonatomic, strong) NSDictionary *userInfo;
@property (nonatomic, strong, readonly) NXOAuth2Client *client;

- (instancetype) initWithRequest:(NSMutableURLRequest *)request
requestParameters:(NSDictionary *)requestParameters
oauthClient:(NXOAuth2Client *)client
sendingProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)sendingProgressHandler
responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;
- (instancetype)initWithRequest:(NSMutableURLRequest *)request
requestParameters:(NSDictionary *)requestParameters
oauthClient:(NXOAuth2Client *)client
sendingProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)sendingProgressHandler
responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler;

- (instancetype)initWithRequest:(NSMutableURLRequest *)request
requestParameters:(NSDictionary *)requestParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
// the full licence.
//

#import "NXOAuth2Constants.h"
#import "NXOAuth2TrustDelegate.h"

#import <Foundation/Foundation.h>
#import <OAuth2Client/NXOAuth2TrustDelegate.h>

@class NXOAuth2Connection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

- (instancetype)initWithParameters:(NSDictionary *)postParameters;

@property (readonly) NSString *boundary;
@property (readonly) unsigned long long length;
@property (readonly, nonatomic) NSString *boundary;
@property (readonly, nonatomic) unsigned long long length;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
//

#import <Foundation/Foundation.h>

#import "NXOAuth2Connection.h"
#import <OAuth2Client/NXOAuth2RequestCallbacks.h>

@class NXOAuth2Account;
@class NXOAuth2Connection;

@interface NXOAuth2Request : NSObject {
@private
Expand Down
19 changes: 19 additions & 0 deletions OAuth2Client/NXOAuth2RequestCallbacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// NXOAuth2RequestCallbacks.h
// OAuth2Client
//
// Created by Oleksandr Dodatko on 2/2/15.
// Copyright (c) 2015 nxtbgthng. All rights reserved.
//

#ifndef OAuth2Client_NXOAuth2RequestCallbacks_h
#define OAuth2Client_NXOAuth2RequestCallbacks_h


#import <Foundation/Foundation.h>

typedef void(^NXOAuth2ConnectionResponseHandler)(NSURLResponse *response, NSData *responseData, NSError *error);
typedef void(^NXOAuth2ConnectionSendingProgressHandler)(unsigned long long bytesSend, unsigned long long bytesTotal);


#endif
31 changes: 0 additions & 31 deletions Sources/OAuth2Client/NXOAuth2.h

This file was deleted.

4 changes: 3 additions & 1 deletion Sources/OAuth2Client/NXOAuth2AccessToken.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ + (instancetype)tokenWithResponseBody:(NSString *)theResponseBody tokenType:(NSS
if (jsonSerializationClass) {
NSError *error = nil;
NSData *data = [theResponseBody dataUsingEncoding:NSUTF8StringEncoding];
jsonDict = [jsonSerializationClass JSONObjectWithData:data options:0 error:&error];
jsonDict = [jsonSerializationClass JSONObjectWithData:data
options:(NSJSONReadingOptions)0
error:&error];
} else {
// do we really need a JSON dependency? We can easily split this up ourselfs
NSString *normalizedResponseBody = [[[theResponseBody stringByReplacingOccurrencesOfString:@"{" withString:@""]
Expand Down
43 changes: 35 additions & 8 deletions Sources/OAuth2Client/NXOAuth2Account.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#pragma mark -

@interface NXOAuth2Account () <NXOAuth2ClientDelegate, NXOAuth2TrustDelegate>

@property (nonatomic, readwrite) id<NXApplication> application;

@end

#pragma mark -
Expand All @@ -41,20 +44,34 @@ @implementation NXOAuth2Account (Private)

#pragma mark Lifecycle

- (instancetype)initAccountWithOAuthClient:(NXOAuth2Client *)anOAuthClient accountType:(NSString *)anAccountType;
-(void)dealloc
{
if (self == self->oauthClient.delegate)
{
self->oauthClient.delegate = nil;
}
}

- (instancetype)initAccountWithOAuthClient:(NXOAuth2Client *)anOAuthClient
accountType:(NSString *)anAccountType
application:(id<NXApplication>)app
{
self = [self initAccountWithAccessToken:anOAuthClient.accessToken
accountType:anAccountType];
accountType:anAccountType
application: app];
if (self) {
oauthClient = anOAuthClient;
}
return self;
}

- (instancetype)initAccountWithAccessToken:(NXOAuth2AccessToken *)anAccessToken accountType:(NSString *)anAccountType;
- (instancetype)initAccountWithAccessToken:(NXOAuth2AccessToken *)anAccessToken
accountType:(NSString *)anAccountType
application:(id<NXApplication>)app
{
self = [super init];
if (self) {
if (nil != self) {
self.application = app;
accountType = anAccountType;
accessToken = anAccessToken;
oauthClient.delegate = self;
Expand All @@ -79,11 +96,21 @@ @implementation NXOAuth2Account

#pragma mark Accessors

- (NXOAuth2Client *)oauthClient;
-(NXOAuth2AccountStore*)sharedAccountStore
{
id<NXApplication> app = self.application;
NXOAuth2AccountStore* accountStore = [NXOAuth2AccountStore sharedStoreForApplication: app];

return accountStore;
}

-(NXOAuth2Client *)oauthClient
{
@synchronized (oauthClient) {
if (oauthClient == nil) {
NSDictionary *configuration = [[NXOAuth2AccountStore sharedStore] configurationForAccountType:self.accountType];

NXOAuth2AccountStore* accountStore = [self sharedAccountStore];
NSDictionary *configuration = [accountStore configurationForAccountType:self.accountType];

NSString *clientID = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationClientID];
NSString *clientSecret = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationSecret];
Expand Down Expand Up @@ -137,7 +164,7 @@ - (NSString *)description;

-(NXOAuth2TrustMode)connection:(NXOAuth2Connection *)connection trustModeForHostname:(NSString *)hostname;
{
NXOAuth2TrustModeHandler handler = [[NXOAuth2AccountStore sharedStore] trustModeHandlerForAccountType:self.accountType];
NXOAuth2TrustModeHandler handler = [[self sharedAccountStore] trustModeHandlerForAccountType:self.accountType];
if (handler) {
return handler(connection, hostname);
} else {
Expand All @@ -147,7 +174,7 @@ -(NXOAuth2TrustMode)connection:(NXOAuth2Connection *)connection trustModeForHost

-(NSArray *)connection:(NXOAuth2Connection *)connection trustedCertificatesForHostname:(NSString *)hostname;
{
NXOAuth2TrustedCertificatesHandler handler = [[NXOAuth2AccountStore sharedStore] trustedCertificatesHandlerForAccountType:self.accountType];
NXOAuth2TrustedCertificatesHandler handler = [[self sharedAccountStore] trustedCertificatesHandlerForAccountType:self.accountType];
return handler(hostname);
}

Expand Down
Loading