mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
If we get a 401 error from the ZeroTier service in the macOS UI, try re-copying the auth token
This commit is contained in:
parent
6bb19e7947
commit
d72eee6cf7
2 changed files with 40 additions and 1 deletions
|
@ -26,6 +26,7 @@
|
||||||
NSString *baseURL;
|
NSString *baseURL;
|
||||||
NSURLSession *session;
|
NSURLSession *session;
|
||||||
BOOL _isQuitting;
|
BOOL _isQuitting;
|
||||||
|
BOOL _resetKey;
|
||||||
}
|
}
|
||||||
+ (ServiceCom*)sharedInstance;
|
+ (ServiceCom*)sharedInstance;
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
baseURL = @"http://127.0.0.1:9993";
|
baseURL = @"http://127.0.0.1:9993";
|
||||||
session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
|
session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
|
||||||
_isQuitting = NO;
|
_isQuitting = NO;
|
||||||
|
_resetKey = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -54,6 +55,37 @@
|
||||||
- (NSString*)key:(NSError* __autoreleasing *)err
|
- (NSString*)key:(NSError* __autoreleasing *)err
|
||||||
{
|
{
|
||||||
static NSString *k = nil;
|
static NSString *k = nil;
|
||||||
|
static NSUInteger resetCount = 10;
|
||||||
|
|
||||||
|
if (_resetKey && k != nil) {
|
||||||
|
k = nil;
|
||||||
|
++resetCount;
|
||||||
|
NSLog(@"ResetCount: %lu", (unsigned long)resetCount);
|
||||||
|
if (resetCount > 10) {
|
||||||
|
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||||
|
NSAlert *alert = [NSAlert alertWithMessageText:@"Error obtaining Auth Token"
|
||||||
|
defaultButton:@"Quit"
|
||||||
|
alternateButton:@"Retry"
|
||||||
|
otherButton:nil
|
||||||
|
informativeTextWithFormat:@"Please ensure ZeroTier is installed correctly"];
|
||||||
|
alert.alertStyle = NSCriticalAlertStyle;
|
||||||
|
|
||||||
|
NSModalResponse res;
|
||||||
|
if (!_isQuitting) {
|
||||||
|
res = [alert runModal];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res == 1) {
|
||||||
|
_isQuitting = YES;
|
||||||
|
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
return @"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (k == nil) {
|
if (k == nil) {
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
|
@ -67,11 +99,13 @@
|
||||||
appSupportDir = [[appSupportDir URLByAppendingPathComponent:@"ZeroTier"] URLByAppendingPathComponent:@"One"];
|
appSupportDir = [[appSupportDir URLByAppendingPathComponent:@"ZeroTier"] URLByAppendingPathComponent:@"One"];
|
||||||
NSURL *authtokenURL = [appSupportDir URLByAppendingPathComponent:@"authtoken.secret"];
|
NSURL *authtokenURL = [appSupportDir URLByAppendingPathComponent:@"authtoken.secret"];
|
||||||
|
|
||||||
if ([[NSFileManager defaultManager] fileExistsAtPath:[authtokenURL path]]) {
|
if (!_resetKey && [[NSFileManager defaultManager] fileExistsAtPath:[authtokenURL path]]) {
|
||||||
k = [NSString stringWithContentsOfURL:authtokenURL
|
k = [NSString stringWithContentsOfURL:authtokenURL
|
||||||
encoding:NSUTF8StringEncoding
|
encoding:NSUTF8StringEncoding
|
||||||
error:&error];
|
error:&error];
|
||||||
|
|
||||||
|
k = [k stringByReplacingOccurrencesOfString:@"\n" withString:@""];
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
NSLog(@"Error: %@", error);
|
NSLog(@"Error: %@", error);
|
||||||
k = nil;
|
k = nil;
|
||||||
|
@ -80,6 +114,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
_resetKey = NO;
|
||||||
NSURL *sysAppSupportDir = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:false error:nil];
|
NSURL *sysAppSupportDir = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:false error:nil];
|
||||||
|
|
||||||
sysAppSupportDir = [[sysAppSupportDir URLByAppendingPathComponent:@"ZeroTier"] URLByAppendingPathComponent:@"One"];
|
sysAppSupportDir = [[sysAppSupportDir URLByAppendingPathComponent:@"ZeroTier"] URLByAppendingPathComponent:@"One"];
|
||||||
|
@ -249,6 +284,9 @@
|
||||||
|
|
||||||
completionHandler(networks);
|
completionHandler(networks);
|
||||||
}
|
}
|
||||||
|
else if (status == 401) {
|
||||||
|
self->_resetKey = YES;
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
[task resume];
|
[task resume];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue