Skip to content

Commit

Permalink
Revert "support getting password with get and adfs"
Browse files Browse the repository at this point in the history
This reverts commit 494fdf7.
  • Loading branch information
twocanoes committed Aug 30, 2022
1 parent 494fdf7 commit 425bda9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 49 deletions.
76 changes: 39 additions & 37 deletions XCreds/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,36 @@ extension WebViewController: WKNavigationDelegate {
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
TCSLogWithMark("DecidePolicyFor: \(navigationAction.request.url?.absoluteString ?? "None")")


let customURL = UserDefaults.standard.value(forKey: PrefKeys.customURL.rawValue)
let customPasswordElementID = UserDefaults.standard.value(forKey: PrefKeys.customPasswordElementID.rawValue) as? String ?? "passwordInput"
if let customURL = customURL as? String, navigationAction.request.url?.host == customURL {
TCSLogWithMark("customURL")
TCSLogWithMark(customURL.sanitized())

let javaScript = "document.getElementById('\(customPasswordElementID.sanitized())').value"
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
if let rawPass = response as? String {
TCSLogWithMark("Setting password")

self.password=rawPass
}
else {
TCSLogWithMark("No password found")
return
}
})

}

// if it's a POST let's see what we're posting...
else if navigationAction.request.httpMethod == "POST" {
if navigationAction.request.httpMethod == "POST" {
TCSLogWithMark("POST")
if let customURL = customURL as? String, navigationAction.request.url?.host == customURL {
TCSLogWithMark(customURL.sanitized())

let javaScript = "document.getElementById('\(customPasswordElementID.sanitized())').value"
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
if let rawPass = response as? String {
self.password=rawPass
}
else {
TCSLogWithMark("No password found")
return
}
})

}

// Azure snarfing
if navigationAction.request.url?.host == "login.microsoftonline.com" {
else if navigationAction.request.url?.host == "login.microsoftonline.com" {
TCSLogWithMark("Azure")

var javaScript = "document.getElementById('i0118').value"
///passwordInput
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
if let rawPass = response as? String {
TCSLogWithMark("Setting password")
self.password=rawPass
}
else {
Expand All @@ -120,7 +116,6 @@ extension WebViewController: WKNavigationDelegate {
javaScript = "document.getElementById('confirmNewPassword').value"
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
if let rawPass = response as? String {
TCSLogWithMark("Setting password")
self.password=rawPass
}
else {
Expand All @@ -133,7 +128,6 @@ extension WebViewController: WKNavigationDelegate {
let javaScript = "document.querySelector('input[type=password]').value"
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
if let rawPass = response as? String {
TCSLogWithMark("Setting password")
self.password=rawPass
}
else {
Expand Down Expand Up @@ -165,6 +159,13 @@ extension WebViewController: WKNavigationDelegate {
else {
TCSLogWithMark(navigationAction.request.httpMethod ?? "Unknown method")
TCSLogWithMark("path = \(navigationAction.request.url?.path ?? "no path")");

// let javaScript = "document.documentElement.outerHTML.toString()"
// webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
// TCSLogWithMark(response as? String ?? "No HTML")
// })


}

decisionHandler(.allow)
Expand All @@ -181,21 +182,22 @@ extension WebViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
TCSLogWithMark("WebDel:: Did Receive Redirect for: \(webView.url?.absoluteString ?? "None")")

let redirectURI = TokenManager.shared.oidc().redirectURI
TCSLogWithMark("redirectURI: \(redirectURI)")
TCSLogWithMark("URL: \(webView.url?.absoluteString ?? "NONE")")
if (webView.url?.absoluteString.starts(with: (redirectURI))) ?? false {
var code = ""
let fullCommand = webView.url?.absoluteString ?? ""
let pathParts = fullCommand.components(separatedBy: "&")
for part in pathParts {
if part.contains("code=") {
code = part.replacingOccurrences(of: redirectURI + "?" , with: "").replacingOccurrences(of: "code=", with: "")
TokenManager.shared.oidc().getToken(code: code)
return
let redirectURI = TokenManager.shared.oidc().redirectURI
TCSLogWithMark("redirectURI: \(redirectURI)")
TCSLogWithMark("URL: \(webView.url?.absoluteString ?? "NONE")")
if (webView.url?.absoluteString.starts(with: (redirectURI))) ?? false {
var code = ""
let fullCommand = webView.url?.absoluteString ?? ""
let pathParts = fullCommand.components(separatedBy: "&")
for part in pathParts {
if part.contains("code=") {
code = part.replacingOccurrences(of: redirectURI + "?" , with: "").replacingOccurrences(of: "code=", with: "")
TokenManager.shared.oidc().getToken(code: code)
return
}
}
}
}

}

private func queryToDict(query: String) -> [String:String]? {
Expand Down
24 changes: 12 additions & 12 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3262;
CURRENT_PROJECT_VERSION = 3261;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -898,7 +898,7 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MARKETING_VERSION = 2.1;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.twocanoes.XCredsLoginPlugin;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -916,7 +916,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3262;
CURRENT_PROJECT_VERSION = 3261;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -929,7 +929,7 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MARKETING_VERSION = 2.1;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.twocanoes.XCredsLoginPlugin;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -975,7 +975,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3262;
CURRENT_PROJECT_VERSION = 3261;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -987,7 +987,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 2.1;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.twocanoes.XCreds-Login-Overlay";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -1005,7 +1005,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3262;
CURRENT_PROJECT_VERSION = 3261;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1017,7 +1017,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 2.1;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.twocanoes.XCreds-Login-Overlay";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1148,7 +1148,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3262;
CURRENT_PROJECT_VERSION = 3261;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1160,7 +1160,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 2.1;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.twocanoes.xcreds;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -1177,7 +1177,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3262;
CURRENT_PROJECT_VERSION = 3261;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1189,7 +1189,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 2.1;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.twocanoes.xcreds;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Binary file not shown.

0 comments on commit 425bda9

Please sign in to comment.