mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-03 13:13:55 +00:00
redo auth with user+password
* needs to be basic auth * use base64 encoder from HockeyCoach
This commit is contained in:
parent
3aeeae8e98
commit
c44c923819
@ -312,13 +312,10 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
||||
completion:(void (^)(BOOL, NSError *))completion {
|
||||
NSParameterAssert(email && email.length);
|
||||
NSParameterAssert(self.authenticationType == BITAuthenticatorAuthTypeEmail || (password && password.length));
|
||||
NSString *authenticationPath = [self authenticationPath];
|
||||
NSDictionary *params = [self parametersForAuthenticationEmail:email password:password];
|
||||
|
||||
NSURLRequest* request = [self requestForAuthenticationEmail:email password:password];
|
||||
__weak typeof (self) weakSelf = self;
|
||||
[self.hockeyAppClient postPath:authenticationPath
|
||||
parameters:params
|
||||
completion:^(BITHTTPOperation *operation, id response, NSError *error) {
|
||||
BITHTTPOperation *operation = [self.hockeyAppClient operationWithURLRequest:request
|
||||
completion:^(BITHTTPOperation *operation, id response, NSError *error) {
|
||||
typeof (self) strongSelf = weakSelf;
|
||||
if(nil == response) {
|
||||
NSError *error = [NSError errorWithDomain:kBITAuthenticatorErrorDomain
|
||||
@ -356,21 +353,33 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
[self.hockeyAppClient enqeueHTTPOperation:operation];
|
||||
}
|
||||
|
||||
- (NSDictionary *) parametersForAuthenticationEmail:(NSString*) email password:(NSString*) password {
|
||||
if(BITAuthenticatorAuthTypeEmailAndPassword == self.authenticationType) {
|
||||
return @{ @"user" : [NSString stringWithFormat:@"%@:%@", email, password] };
|
||||
} else {
|
||||
- (NSURLRequest *) requestForAuthenticationEmail:(NSString*) email password:(NSString*) password {
|
||||
NSString *authenticationPath = [self authenticationPath];
|
||||
NSDictionary *params = nil;
|
||||
|
||||
if(BITAuthenticatorAuthTypeEmail == self.authenticationType) {
|
||||
NSString *authCode = BITHockeyMD5([NSString stringWithFormat:@"%@%@",
|
||||
self.authenticationSecret ? : @"",
|
||||
email ? : @""]);
|
||||
return @{
|
||||
params = @{
|
||||
@"email" : email ? : @"",
|
||||
@"authcode" : authCode.lowercaseString,
|
||||
};
|
||||
}
|
||||
|
||||
NSMutableURLRequest *request = [self.hockeyAppClient requestWithMethod:@"POST"
|
||||
path:authenticationPath
|
||||
parameters:params];
|
||||
if(BITAuthenticatorAuthTypeEmailAndPassword == self.authenticationType) {
|
||||
NSString *authStr = [NSString stringWithFormat:@"%@:%@", email, password];
|
||||
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
|
||||
NSString *authValue = [NSString stringWithFormat:@"Basic %@", bit_base64String(authData, authData.length)];
|
||||
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
- (NSString *) authenticationPath {
|
||||
|
||||
@ -32,6 +32,8 @@
|
||||
/* NSString helpers */
|
||||
NSString *bit_URLEncodedString(NSString *inputString);
|
||||
NSString *bit_URLDecodedString(NSString *inputString);
|
||||
NSString *bit_base64String(NSData * data, unsigned long length);
|
||||
|
||||
NSComparisonResult bit_versionCompare(NSString *stringA, NSString *stringB);
|
||||
NSString *bit_encodeAppIdentifier(NSString *inputString);
|
||||
NSString *bit_appName(NSString *placeHolderString);
|
||||
|
||||
@ -32,6 +32,12 @@
|
||||
#import "HockeySDKPrivate.h"
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
static char base64EncodingTable[64] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
#pragma mark NSString helpers
|
||||
|
||||
@ -52,6 +58,61 @@ NSString *bit_URLDecodedString(NSString *inputString) {
|
||||
);
|
||||
}
|
||||
|
||||
NSString *bit_base64String(NSData * data, unsigned long length) {
|
||||
unsigned long ixtext, lentext;
|
||||
long ctremaining;
|
||||
unsigned char input[3], output[4];
|
||||
short i, charsonline = 0, ctcopy;
|
||||
const unsigned char *raw;
|
||||
NSMutableString *result;
|
||||
|
||||
lentext = [data length];
|
||||
if (lentext < 1)
|
||||
return @"";
|
||||
result = [NSMutableString stringWithCapacity: lentext];
|
||||
raw = [data bytes];
|
||||
ixtext = 0;
|
||||
|
||||
while (true) {
|
||||
ctremaining = (long)(lentext - ixtext);
|
||||
if (ctremaining <= 0)
|
||||
break;
|
||||
for (unsigned long y = 0; y < 3; y++) {
|
||||
unsigned long ix = (ixtext + y);
|
||||
if (ix < lentext)
|
||||
input[y] = raw[ix];
|
||||
else
|
||||
input[y] = 0;
|
||||
}
|
||||
output[0] = (input[0] & 0xFC) >> 2;
|
||||
output[1] = (unsigned char)((input[0] & 0x03) << 4) | ((input[1] & 0xF0) >> 4);
|
||||
output[2] = (unsigned char)((input[1] & 0x0F) << 2) | ((input[2] & 0xC0) >> 6);
|
||||
output[3] = input[2] & 0x3F;
|
||||
ctcopy = 4;
|
||||
switch (ctremaining) {
|
||||
case 1:
|
||||
ctcopy = 2;
|
||||
break;
|
||||
case 2:
|
||||
ctcopy = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < ctcopy; i++)
|
||||
[result appendString: [NSString stringWithFormat: @"%c", base64EncodingTable[output[i]]]];
|
||||
|
||||
for (i = ctcopy; i < 4; i++)
|
||||
[result appendString: @"="];
|
||||
|
||||
ixtext += 3;
|
||||
charsonline += 4;
|
||||
|
||||
if ((length > 0) && (charsonline >= length))
|
||||
charsonline = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NSComparisonResult bit_versionCompare(NSString *stringA, NSString *stringB) {
|
||||
// Extract plain version number from self
|
||||
NSString *plainSelf = stringA;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user