Roll back to a working build

This commit is contained in:
Adam Tunnic authored and GitHub committed 2021-04-28 18:09:35 -04:00
1 parent 979d1c3cda
commit 8cc0e10919
1 file changed
+35 -63
+35 -63
View File
@@ -2,7 +2,6 @@
#include <stdio.h>
#import <AuthenticationServices/AuthenticationServices.h>
#import <SafariServices/SafariServices.h>
#import "AppDelegate.h"
#import "LauncherViewController.h"
@@ -41,7 +40,7 @@ void loginAccountInput(UINavigationController *controller, int type, const char*
}
#pragma mark - LoginViewController
@interface LoginViewController () <ASWebAuthenticationPresentationContextProviding, SFSafariViewControllerDelegate>{
@interface LoginViewController () <ASWebAuthenticationPresentationContextProviding>{
}
@property (nonatomic, strong) ASWebAuthenticationSession *authVC;
@end
@@ -184,52 +183,46 @@ void loginAccountInput(UINavigationController *controller, int type, const char*
- (void)loginMicrosoft {
NSURL *url = [NSURL URLWithString:@"https://login.live.com/oauth20_authorize.srf?client_id=00000000402b5328&response_type=code&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL&redirect_url=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf"];
if(@available(iOS 13.0, *)) {
authVC =
[[ASWebAuthenticationSession alloc] initWithURL:url
callbackURLScheme:@"ms-xal-00000000402b5328"
completionHandler:^(NSURL * _Nullable callbackURL,
NSError * _Nullable error) {
if (callbackURL != nil) {
NSString *urlString = [callbackURL absoluteString];
NSLog(@"URL returned = %@", [callbackURL absoluteString]);
if ([urlString containsString:@"/auth/?code="] == YES) {
NSArray *components = [urlString componentsSeparatedByString:@"/auth/?code="];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
loginAccountInput(self.navigationController, TYPE_MICROSOFT, [components[1] UTF8String]);
});
} else {
NSArray *components = [urlString componentsSeparatedByString:@"/auth/?error="];
if ([components[1] hasPrefix:@"access_denied"] == NO) {
NSString *outError = [components[1]
stringByReplacingOccurrencesOfString:@"&error_description=" withString:@": "];
outError = [outError stringByRemovingPercentEncoding];
showDialog(self, @"Error", outError);
}
}
} else {
if (error.code != ASWebAuthenticationSessionErrorCodeCanceledLogin) {
showDialog(self, @"Error", error.localizedDescription);
}
}
}];
authVC =
[[ASWebAuthenticationSession alloc] initWithURL:url
callbackURLScheme:@"ms-xal-00000000402b5328"
completionHandler:^(NSURL * _Nullable callbackURL,
NSError * _Nullable error) {
if (callbackURL != nil) {
NSString *urlString = [callbackURL absoluteString];
NSLog(@"URL returned = %@", [callbackURL absoluteString]);
if (@available(iOS 13.0, *)) {
authVC.presentationContextProvider = self;
}
if ([urlString containsString:@"/auth/?code="] == YES) {
NSArray *components = [urlString componentsSeparatedByString:@"/auth/?code="];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
loginAccountInput(self.navigationController, TYPE_MICROSOFT, [components[1] UTF8String]);
});
} else {
NSArray *components = [urlString componentsSeparatedByString:@"/auth/?error="];
if ([components[1] hasPrefix:@"access_denied"] == NO) {
NSString *outError = [components[1]
stringByReplacingOccurrencesOfString:@"&error_description=" withString:@": "];
outError = [outError stringByRemovingPercentEncoding];
showDialog(self, @"Error", outError);
}
}
} else {
if (error.code != ASWebAuthenticationSessionErrorCodeCanceledLogin) {
showDialog(self, @"Error", error.localizedDescription);
}
}
}];
if ([authVC start] == NO) {
showDialog(self, @"Error", @"Unable to open Safari");
}
} else {
SFSafariViewController *vc = [[SFSafariViewController alloc] initWithURL:url];
vc.delegate = self;
[self presentViewController:vc animated:YES completion:nil];
if (@available(iOS 13.0, *)) {
authVC.presentationContextProvider = self;
}
if ([authVC start] == NO) {
showDialog(self, @"Error", @"Unable to open Safari");
}
}
- (void)loginOffline {
[self loginUsername:TYPE_OFFLINE];
}
@@ -295,27 +288,6 @@ void loginAccountInput(UINavigationController *controller, int type, const char*
[postDataTask resume];
}
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
if(@available(iOS 13.0, *)) {
} else {
[controller dismissViewControllerAnimated:true completion:nil];
}
}
- (void)msaLoginCallback:(NSNotification *)notification {
if(@available(iOS 13.0, *)) {
} else {
[self dismissViewControllerAnimated:YES completion:nil];
NSDictionary *dict = [notification userInfo];
NSURL *url = [dict objectForKey:@"url"];
NSArray *components = [[url absoluteString] componentsSeparatedByString:@"?code="];
// NSLog(@"URL returned = %@", components[1]);
loginAccountInput(self.navigationController, TYPE_MICROSOFT, "", [components[1] UTF8String]);
}
}
#pragma mark - ASWebAuthenticationPresentationContextProviding
- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session API_AVAILABLE(ios(13.0)){
return UIApplication.sharedApplication.keyWindow;