mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 11:20:18 +00:00
store the type of the token with the token itself
updater needs it as well and we actually don't want to send the wrong type to the server
This commit is contained in:
parent
d93da3ee32
commit
ea5452603b
@ -36,6 +36,7 @@
|
|||||||
#import "BITHockeyHelper.h"
|
#import "BITHockeyHelper.h"
|
||||||
|
|
||||||
static NSString* const kBITAuthenticatorAuthTokenKey = @"BITAuthenticatorAuthTokenKey";
|
static NSString* const kBITAuthenticatorAuthTokenKey = @"BITAuthenticatorAuthTokenKey";
|
||||||
|
static NSString* const kBITAuthenticatorAuthTokenTypeKey = @"BITAuthenticatorAuthTokenTypeKey";
|
||||||
static NSString* const kBITAuthenticatorAuthTokenVendorIdentifierKey = @"BITAuthenticatorAuthTokenVendorIdentifierKey";
|
static NSString* const kBITAuthenticatorAuthTokenVendorIdentifierKey = @"BITAuthenticatorAuthTokenVendorIdentifierKey";
|
||||||
static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthenticatorLastAuthenticatedVersionKey";
|
static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthenticatorLastAuthenticatedVersionKey";
|
||||||
static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticatorDidSkipOptionalLogin";
|
static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticatorDidSkipOptionalLogin";
|
||||||
@ -101,6 +102,15 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
|||||||
return bit_appAnonID();
|
return bit_appAnonID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*) installationIdentificationType {
|
||||||
|
NSString *authToken = self.authenticationToken;
|
||||||
|
if(nil == authToken) {
|
||||||
|
return @"udid";
|
||||||
|
} else {
|
||||||
|
return [self authenticationTokenType];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Validation
|
#pragma mark - Validation
|
||||||
- (void) validateInstallationWithCompletion:(tValidationCompletion) completion {
|
- (void) validateInstallationWithCompletion:(tValidationCompletion) completion {
|
||||||
if(nil == self.authenticationToken) {
|
if(nil == self.authenticationToken) {
|
||||||
@ -146,19 +156,8 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
|||||||
|
|
||||||
- (NSDictionary*) validationParameters {
|
- (NSDictionary*) validationParameters {
|
||||||
NSParameterAssert(self.authenticationToken);
|
NSParameterAssert(self.authenticationToken);
|
||||||
NSDictionary *params = nil;
|
NSParameterAssert(self.installationIdentificationType);
|
||||||
switch (self.authenticationType) {
|
return @{self.installationIdentificationType : self.authenticationToken};
|
||||||
case BITAuthenticatorAuthTypeEmail:
|
|
||||||
params = @{@"iuid" : self.authenticationToken};
|
|
||||||
break;
|
|
||||||
case BITAuthenticatorAuthTypeEmailAndPassword:
|
|
||||||
params = @{@"auid" : self.authenticationToken};
|
|
||||||
break;
|
|
||||||
case BITAuthenticatorAuthTypeUDIDProvider:
|
|
||||||
params = @{@"udid" : self.authenticationToken};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL) isValidationResponseValid:(id) response error:(NSError **) error {
|
+ (BOOL) isValidationResponseValid:(id) response error:(NSError **) error {
|
||||||
@ -269,7 +268,7 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
|||||||
- (void) didAuthenticateWithToken:(NSString*) token {
|
- (void) didAuthenticateWithToken:(NSString*) token {
|
||||||
[_authenticationController dismissModalViewControllerAnimated:YES];
|
[_authenticationController dismissModalViewControllerAnimated:YES];
|
||||||
_authenticationController = nil;
|
_authenticationController = nil;
|
||||||
self.authenticationToken = token;
|
[self setAuthenticationToken:token withType:[self.class stringForAuthenticationType:self.authenticationType]];
|
||||||
self.installationIdentificationValidated = YES;
|
self.installationIdentificationValidated = YES;
|
||||||
self.lastAuthenticatedVersion = [self executableUUID];
|
self.lastAuthenticatedVersion = [self executableUUID];
|
||||||
if(self.authenticationCompletionBlock) {
|
if(self.authenticationCompletionBlock) {
|
||||||
@ -277,12 +276,24 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
|||||||
self.authenticationCompletionBlock = nil;
|
self.authenticationCompletionBlock = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NSString*) stringForAuthenticationType:(BITAuthenticatorAuthType) authType {
|
||||||
|
switch (authType) {
|
||||||
|
case BITAuthenticatorAuthTypeEmail: return @"iuid";
|
||||||
|
case BITAuthenticatorAuthTypeEmailAndPassword: return @"auid";
|
||||||
|
case BITAuthenticatorAuthTypeUDIDProvider:
|
||||||
|
//fallthrough
|
||||||
|
default:
|
||||||
|
return @"udid";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
#pragma mark - AuthenticationViewControllerDelegate
|
#pragma mark - AuthenticationViewControllerDelegate
|
||||||
- (void) authenticationViewControllerDidSkip:(UIViewController *)viewController {
|
- (void) authenticationViewControllerDidSkip:(UIViewController *)viewController {
|
||||||
[viewController dismissModalViewControllerAnimated:YES];
|
[viewController dismissModalViewControllerAnimated:YES];
|
||||||
|
|
||||||
_authenticationController = nil;
|
_authenticationController = nil;
|
||||||
self.authenticationToken = nil;
|
[self setAuthenticationToken:nil withType:nil];
|
||||||
if(self.validationType == BITAuthenticatorValidationTypeOptional) {
|
if(self.validationType == BITAuthenticatorValidationTypeOptional) {
|
||||||
self.didSkipOptionalLogin = YES;
|
self.didSkipOptionalLogin = YES;
|
||||||
}
|
}
|
||||||
@ -439,7 +450,7 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
|||||||
[self didAuthenticateWithToken:udid];
|
[self didAuthenticateWithToken:udid];
|
||||||
} else {
|
} else {
|
||||||
//reset auth-token
|
//reset auth-token
|
||||||
self.authenticationToken = nil;
|
[self setAuthenticationToken:nil withType:nil];
|
||||||
|
|
||||||
if(self.validationType == BITAuthenticatorValidationTypeOptional) {
|
if(self.validationType == BITAuthenticatorValidationTypeOptional) {
|
||||||
//dismiss view-controller if login was optional
|
//dismiss view-controller if login was optional
|
||||||
@ -499,6 +510,7 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
|||||||
|
|
||||||
- (void) cleanupInternalStorage {
|
- (void) cleanupInternalStorage {
|
||||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
||||||
|
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenTypeKey];
|
||||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
||||||
[self removeKeyFromKeychain:kBITAuthenticatorDidSkipOptionalLogin];
|
[self removeKeyFromKeychain:kBITAuthenticatorDidSkipOptionalLogin];
|
||||||
[self setLastAuthenticatedVersion:nil];
|
[self setLastAuthenticatedVersion:nil];
|
||||||
@ -538,14 +550,16 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Property overrides
|
#pragma mark - Property overrides
|
||||||
- (void)setAuthenticationToken:(NSString *)authenticationToken {
|
- (void)setAuthenticationToken:(NSString *)authenticationToken withType:(NSString*) authenticationTokenType {
|
||||||
|
NSParameterAssert(nil == authenticationToken || nil != authenticationTokenType);
|
||||||
if(![self.authenticationToken isEqualToString:authenticationToken]) {
|
if(![self.authenticationToken isEqualToString:authenticationToken]) {
|
||||||
[self willChangeValueForKey:@"installationIdentification"];
|
[self willChangeValueForKey:@"installationIdentification"];
|
||||||
if(nil == authenticationToken) {
|
if(nil == authenticationToken) {
|
||||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
||||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenTypeKey];
|
||||||
} else {
|
} else {
|
||||||
[self addStringValueToKeychain:authenticationToken forKey:kBITAuthenticatorAuthTokenKey];
|
[self addStringValueToKeychain:authenticationToken forKey:kBITAuthenticatorAuthTokenKey];
|
||||||
|
[self addStringValueToKeychain:authenticationTokenType forKey:kBITAuthenticatorAuthTokenTypeKey];
|
||||||
NSString *identifierForVendor = self.currentDevice.identifierForVendor.UUIDString;
|
NSString *identifierForVendor = self.currentDevice.identifierForVendor.UUIDString;
|
||||||
[self addStringValueToKeychain:identifierForVendor forKey:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
[self addStringValueToKeychain:identifierForVendor forKey:kBITAuthenticatorAuthTokenVendorIdentifierKey];
|
||||||
}
|
}
|
||||||
@ -568,6 +582,11 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
|||||||
return authToken;
|
return authToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)authenticationTokenType {
|
||||||
|
NSString *authTokenType = [self stringValueFromKeychainForKey:kBITAuthenticatorAuthTokenTypeKey];
|
||||||
|
return authTokenType;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setLastAuthenticatedVersion:(NSString *)lastAuthenticatedVersion {
|
- (void)setLastAuthenticatedVersion:(NSString *)lastAuthenticatedVersion {
|
||||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||||
if(nil == lastAuthenticatedVersion){
|
if(nil == lastAuthenticatedVersion){
|
||||||
|
|||||||
@ -50,7 +50,13 @@
|
|||||||
* This is retrieved from the hockeyApp backend
|
* This is retrieved from the hockeyApp backend
|
||||||
* @see installationIdentifier
|
* @see installationIdentifier
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, copy) NSString *authenticationToken;
|
@property (nonatomic, readonly) NSString *authenticationToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* store the authentication token with the given type
|
||||||
|
* if authToken is not nil, authentikationTokenType must also be non nil
|
||||||
|
*/
|
||||||
|
- (void)setAuthenticationToken:(NSString *)authenticationToken withType:(NSString*) authenticationTokenType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* holds the identifier of the last version that was authenticated
|
* holds the identifier of the last version that was authenticated
|
||||||
@ -62,10 +68,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the type of installation identification for the current app installation
|
* Specifies the type of installation identification for the current app installation
|
||||||
*
|
|
||||||
* KVO'able
|
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly) BOOL installationIdentificationType;
|
@property (nonatomic, readonly) NSString *installationIdentificationType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removes all previously stored authentication tokens, UDIDs, etc
|
* removes all previously stored authentication tokens, UDIDs, etc
|
||||||
|
|||||||
@ -84,7 +84,7 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
|||||||
|
|
||||||
#pragma mark - Persistence Tests
|
#pragma mark - Persistence Tests
|
||||||
- (void) testThatAuthenticationTokenIsPersisted {
|
- (void) testThatAuthenticationTokenIsPersisted {
|
||||||
_sut.authenticationToken = @"SuperToken";
|
[_sut setAuthenticationToken:@"SuperToken" withType:@"udid"];
|
||||||
_sut = [[BITAuthenticator alloc] initWithAppIdentifier:nil isAppStoreEnvironemt:YES];
|
_sut = [[BITAuthenticator alloc] initWithAppIdentifier:nil isAppStoreEnvironemt:YES];
|
||||||
assertThat(_sut.authenticationToken, equalTo(@"SuperToken"));
|
assertThat(_sut.authenticationToken, equalTo(@"SuperToken"));
|
||||||
}
|
}
|
||||||
@ -96,13 +96,15 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) testThatCleanupWorks {
|
- (void) testThatCleanupWorks {
|
||||||
_sut.authenticationToken = @"MyToken";
|
[_sut setAuthenticationToken:@"MyToken" withType:@"udid"];
|
||||||
_sut.lastAuthenticatedVersion = @"1.2";
|
_sut.lastAuthenticatedVersion = @"1.2";
|
||||||
|
|
||||||
[_sut cleanupInternalStorage];
|
[_sut cleanupInternalStorage];
|
||||||
|
|
||||||
assertThat(_sut.authenticationToken, equalTo(nil));
|
assertThat(_sut.authenticationToken, equalTo(nil));
|
||||||
assertThat(_sut.lastAuthenticatedVersion, equalTo(nil));
|
assertThat(_sut.lastAuthenticatedVersion, equalTo(nil));
|
||||||
|
assertThat(_sut.installationIdentificationType, equalTo(@"udid"));
|
||||||
|
assertThatBool(_sut.didSkipOptionalLogin, equalToBool(NO));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) testThatSkipLoginIsPersisted {
|
- (void) testThatSkipLoginIsPersisted {
|
||||||
@ -121,7 +123,7 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) testIdentificationReturnsTheAuthTokenIfSet {
|
- (void) testIdentificationReturnsTheAuthTokenIfSet {
|
||||||
_sut.authenticationToken = @"PeterPan";
|
[_sut setAuthenticationToken:@"PeterPan" withType:@"udid"];
|
||||||
assertThat(_sut.installationIdentification, equalTo(@"PeterPan"));
|
assertThat(_sut.installationIdentification, equalTo(@"PeterPan"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +188,7 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
|||||||
- (void) testThatSuccessfulAuthenticationCallsTheBlock {
|
- (void) testThatSuccessfulAuthenticationCallsTheBlock {
|
||||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||||
_sut.delegate = delegateMock;
|
_sut.delegate = delegateMock;
|
||||||
_sut.authenticationToken = @"Test";
|
[_sut setAuthenticationToken:@"Test" withType:@"adid"];
|
||||||
__block BOOL didAuthenticate = NO;
|
__block BOOL didAuthenticate = NO;
|
||||||
[_sut authenticateWithCompletion:^(NSString *authenticationToken, NSError *error) {
|
[_sut authenticateWithCompletion:^(NSString *authenticationToken, NSError *error) {
|
||||||
if(authenticationToken) didAuthenticate = YES;
|
if(authenticationToken) didAuthenticate = YES;
|
||||||
@ -220,7 +222,7 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
|||||||
- (void) testThatCancelledAuthenticationResetsTheToken {
|
- (void) testThatCancelledAuthenticationResetsTheToken {
|
||||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||||
_sut.delegate = delegateMock;
|
_sut.delegate = delegateMock;
|
||||||
_sut.authenticationToken = @"Meh";
|
[_sut setAuthenticationToken:@"Meh" withType:@"bdid"];
|
||||||
|
|
||||||
//this will prepare everything and show the viewcontroller
|
//this will prepare everything and show the viewcontroller
|
||||||
[_sut authenticateWithCompletion:nil];
|
[_sut authenticateWithCompletion:nil];
|
||||||
@ -252,6 +254,38 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - InstallationIdentificationType
|
||||||
|
- (void) testThatEmailAuthSetsTheProperInstallationIdentificationType {
|
||||||
|
_sut.authenticationType = BITAuthenticatorAuthTypeEmail;
|
||||||
|
//fake delegate call from the viewcontroller
|
||||||
|
[_sut didAuthenticateWithToken:@"SuperToken"];
|
||||||
|
|
||||||
|
assertThat(_sut.installationIdentificationType, equalTo(@"iuid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatPasswordAuthSetsTheProperInstallationIdentificationType {
|
||||||
|
_sut.authenticationType = BITAuthenticatorAuthTypeEmailAndPassword;
|
||||||
|
//fake delegate call from the viewcontroller
|
||||||
|
[_sut didAuthenticateWithToken:@"SuperToken"];
|
||||||
|
|
||||||
|
assertThat(_sut.installationIdentificationType, equalTo(@"auid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatUDIDAuthSetsTheProperInstallationIdentificationType {
|
||||||
|
_sut.authenticationType = BITAuthenticatorAuthTypeUDIDProvider;
|
||||||
|
//fake delegate call from the viewcontroller
|
||||||
|
[_sut didAuthenticateWithToken:@"SuperToken"];
|
||||||
|
|
||||||
|
assertThat(_sut.installationIdentificationType, equalTo(@"udid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatDefaultAuthReturnsProperInstallationIdentificationType {
|
||||||
|
_sut.authenticationType = BITAuthenticatorAuthTypeEmailAndPassword;
|
||||||
|
//fake delegate call from the viewcontroller
|
||||||
|
[_sut authenticationViewControllerDidSkip:nil];
|
||||||
|
|
||||||
|
assertThat(_sut.installationIdentificationType, equalTo(@"udid"));
|
||||||
|
}
|
||||||
#pragma mark - validation tests
|
#pragma mark - validation tests
|
||||||
- (void) testThatValidationWithoutTokenWantsToShowTheAuthenticationViewController {
|
- (void) testThatValidationWithoutTokenWantsToShowTheAuthenticationViewController {
|
||||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user