Skip to content

Commit

Permalink
added better loading at start
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Aug 6, 2022
1 parent 27be415 commit 1223e39
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 74 deletions.
2 changes: 1 addition & 1 deletion XCreds/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"author" : "xcode",
"version" : 1
}
}
}
6 changes: 2 additions & 4 deletions XCreds/TokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,28 @@ class TokenManager {
private var oidcLocal:OIDCLite?
func oidc() -> OIDCLite {
var scopes: [String]?

var additionalParameters:[String:String]? = nil
var clientSecret:String?

if let oidcPrivate = oidcLocal {
oidcPrivate.getEndpoints()

return oidcPrivate
}
if let clientSecretRaw = UserDefaults.standard.string(forKey: PrefKeys.clientSecret.rawValue),
clientSecretRaw != "" {
clientSecret = clientSecretRaw
}

if let scopesRaw = UserDefaults.standard.string(forKey: PrefKeys.scopes.rawValue) {
scopes = scopesRaw.components(separatedBy: " ")
}
//

if UserDefaults.standard.bool(forKey: PrefKeys.shouldSetGoogleAccessTypeToOffline.rawValue) == true {
additionalParameters = ["access_type":"offline", "prompt":"consent"]
}

let oidcLite = OIDCLite(discoveryURL: UserDefaults.standard.string(forKey: PrefKeys.discoveryURL.rawValue) ?? "NONE", clientID: UserDefaults.standard.string(forKey: PrefKeys.clientID.rawValue) ?? "NONE", clientSecret: clientSecret, redirectURI: UserDefaults.standard.string(forKey: PrefKeys.redirectURI.rawValue), scopes: scopes, additionalParameters:additionalParameters )
oidcLite.getEndpoints()

oidcLocal = oidcLite
return oidcLite

Expand Down
49 changes: 18 additions & 31 deletions XCreds/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,28 @@ class WebViewController: NSWindowController {

var password:String?
func loadPage() {
//
// var scopes: [String]?
// var clientSecret: String?
//
// if let clientSecretRaw = UserDefaults.standard.string(forKey: PrefKeys.clientSecret.rawValue),
// clientSecretRaw != "" {
// clientSecret = clientSecretRaw
// }
//
// if let scopesRaw = UserDefaults.standard.string(forKey: PrefKeys.scopes.rawValue) {
// scopes = scopesRaw.components(separatedBy: " ")
// }
// //
// var additionalParameters:[String:String]? = nil
//
// if UserDefaults.standard.bool(forKey: PrefKeys.shouldSetGoogleAccessTypeToOffline.rawValue) == true {
// additionalParameters = ["access_type":"offline", "prompt":"consent"]
// }
// TCSLogWithMark("redirect URI: \(UserDefaults.standard.string(forKey: PrefKeys.redirectURI.rawValue) ?? "NONE")")
// oidcLite = OIDCLite(discoveryURL: UserDefaults.standard.string(forKey: PrefKeys.discoveryURL.rawValue) ?? "NONE", clientID: UserDefaults.standard.string(forKey: PrefKeys.clientID.rawValue) ?? "NONE", clientSecret: clientSecret, redirectURI: UserDefaults.standard.string(forKey: PrefKeys.redirectURI.rawValue), scopes: scopes, additionalParameters:additionalParameters )
// webView.navigationDelegate = self
// oidcLite?.delegate = self
// oidcLite?.getEndpoints()
//
// if let tokenEndpoint = oidcLite?.OIDCTokenEndpoint {
// UserDefaults.standard.set(tokenEndpoint, forKey: PrefKeys.tokenEndpoint.rawValue)
// }
webView.navigationDelegate = self


webView.navigationDelegate = self
TokenManager.shared.oidc().delegate = self
clearCookies()

if let url = TokenManager.shared.oidc().createLoginURL() {
TCSLogWithMark()
self.webView.load(URLRequest(url: url))
}
else {
let allBundles = Bundle.allBundles
for currentBundle in allBundles {
TCSLogWithMark(currentBundle.bundlePath)
if currentBundle.bundlePath.contains("XCreds") {
TCSLogWithMark()
let loadPageURL = currentBundle.url(forResource: "loadpage", withExtension: "html")
TCSLogWithMark(loadPageURL?.debugDescription ?? "none")
self.webView.load(URLRequest(url:loadPageURL!))
break

}
}
}
}

@IBAction func clickCancel(_ sender: Any) {
Expand Down Expand Up @@ -195,7 +182,7 @@ 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
let redirectURI = TokenManager.shared.oidc().redirectURI
TCSLogWithMark("redirectURI: \(redirectURI)")
TCSLogWithMark("URL: \(webView.url?.absoluteString ?? "NONE")")
if (webView.url?.absoluteString.starts(with: (redirectURI))) ?? false {
Expand Down
4 changes: 1 addition & 3 deletions XCredsLoginPlugIn/LoginWindow/AuthorizationDBManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class AuthorizationDBManager: NSObject {
let positionOfOldRight = consoleRights.firstIndex(of: right)

guard let positionOfOldRight = positionOfOldRight else {
TCSLogWithMark("error positionOfOldRight")
return false
}

Expand All @@ -112,7 +111,6 @@ class AuthorizationDBManager: NSObject {
let positionOfOldRight = consoleRights.firstIndex(of: right)

guard let positionOfOldRight = positionOfOldRight else {
TCSLogWithMark("error positionOfOldRight")

return false
}
Expand All @@ -137,7 +135,7 @@ class AuthorizationDBManager: NSObject {
}
func insertRight(newRight:String, afterRight right:String) -> Bool {
var consoleRights = consoleRights()
TCSLogWithMark("finding right \(right)")
// TCSLogWithMark("finding right \(right)")

let positionOfRight = consoleRights.firstIndex(of: right)

Expand Down
41 changes: 28 additions & 13 deletions XCredsLoginPlugIn/LoginWindow/LoginWindowControls.xib
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="sxl-0U-ne5">
<rect key="frame" x="0.0" y="24" width="872" height="78"/>
<rect key="frame" x="0.0" y="14" width="872" height="88"/>
<subviews>
<gridView xPlacement="leading" yPlacement="bottom" rowAlignment="none" translatesAutoresizingMaskIntoConstraints="NO" id="e8b-BH-Acs">
<rect key="frame" x="175" y="10" width="522" height="48"/>
<rect key="frame" x="122" y="10" width="628" height="48"/>
<rows>
<gridRow id="XHx-7d-YkX"/>
</rows>
<columns>
<gridColumn width="120" trailingPadding="6" id="1Cd-fS-KBP"/>
<gridColumn width="120" trailingPadding="6" id="cUX-O2-zNV"/>
<gridColumn width="120" trailingPadding="6" id="gHc-Pk-tz7"/>
<gridColumn width="120" trailingPadding="6" id="wvm-rM-lRK"/>
<gridColumn width="116" trailingPadding="6" id="1Cd-fS-KBP"/>
<gridColumn width="116" trailingPadding="6" id="cUX-O2-zNV"/>
<gridColumn width="116" trailingPadding="6" id="gHc-Pk-tz7"/>
<gridColumn width="116" trailingPadding="6" id="wvm-rM-lRK"/>
<gridColumn width="116" id="zJd-bC-xff"/>
</columns>
<gridCells>
<gridCell row="XHx-7d-YkX" column="1Cd-fS-KBP" xPlacement="center" id="VEY-Lk-Q6B">
<button key="contentView" translatesAutoresizingMaskIntoConstraints="NO" id="DDT-al-AEa">
<rect key="frame" x="13" y="0.0" width="94" height="48"/>
<rect key="frame" x="11" y="0.0" width="94" height="48"/>
<buttonCell key="cell" type="bevel" title="Configure WiFi" bezelStyle="regularSquare" image="wifi" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="tgY-Vk-PkQ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -55,7 +56,7 @@
</gridCell>
<gridCell row="XHx-7d-YkX" column="cUX-O2-zNV" xPlacement="center" id="2Gc-hy-IjQ">
<button key="contentView" imageHugsTitle="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6f9-0z-Xqg">
<rect key="frame" x="159" y="0.0" width="65" height="48"/>
<rect key="frame" x="154" y="0.0" width="65" height="48"/>
<buttonCell key="cell" type="bevel" title="Shutdown" bezelStyle="rounded" image="ShutdownX" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="WRj-LR-MaW">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -68,7 +69,7 @@
</gridCell>
<gridCell row="XHx-7d-YkX" column="gHc-Pk-tz7" xPlacement="center" id="ggR-Qe-YoB">
<button key="contentView" translatesAutoresizingMaskIntoConstraints="NO" id="HyD-ug-de2">
<rect key="frame" x="299" y="0.0" width="48" height="48"/>
<rect key="frame" x="290" y="0.0" width="48" height="48"/>
<buttonCell key="cell" type="bevel" title="Restart" bezelStyle="rounded" image="RestartX" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="UQm-h8-fbd">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -81,7 +82,7 @@
</gridCell>
<gridCell row="XHx-7d-YkX" column="wvm-rM-lRK" xPlacement="center" id="yab-0z-xmZ">
<button key="contentView" translatesAutoresizingMaskIntoConstraints="NO" id="2By-DW-YEU">
<rect key="frame" x="396" y="0.0" width="119" height="48"/>
<rect key="frame" x="384" y="0.0" width="116" height="48"/>
<buttonCell key="cell" type="bevel" title="Mac Login Window" bezelStyle="rounded" image="loginwindow" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="c0y-fU-B6x">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -92,14 +93,27 @@
</connections>
</button>
</gridCell>
<gridCell row="XHx-7d-YkX" column="zJd-bC-xff" xPlacement="center" id="2FB-3X-XD3">
<button key="contentView" translatesAutoresizingMaskIntoConstraints="NO" id="KMl-IG-aMO">
<rect key="frame" x="512" y="0.0" width="116" height="48"/>
<buttonCell key="cell" type="bevel" title="Refresh" bezelStyle="rounded" image="refresh symbol" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="whe-sk-uox">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<color key="contentTintColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<action selector="refreshButtonPressed:" target="-2" id="ztv-D5-zej"/>
</connections>
</button>
</gridCell>
</gridCells>
</gridView>
</subviews>
<constraints>
<constraint firstItem="e8b-BH-Acs" firstAttribute="centerX" secondItem="sxl-0U-ne5" secondAttribute="centerX" id="JSn-6y-aQi"/>
<constraint firstAttribute="bottom" secondItem="e8b-BH-Acs" secondAttribute="bottom" constant="10" id="LbL-3W-fqZ"/>
<constraint firstAttribute="height" constant="78" id="cmM-6M-FrE"/>
<constraint firstItem="e8b-BH-Acs" firstAttribute="top" secondItem="sxl-0U-ne5" secondAttribute="top" constant="20" symbolic="YES" id="ecP-lc-Til"/>
<constraint firstAttribute="height" constant="88" id="cmM-6M-FrE"/>
<constraint firstItem="e8b-BH-Acs" firstAttribute="top" secondItem="sxl-0U-ne5" secondAttribute="top" constant="30" id="ecP-lc-Til"/>
</constraints>
</customView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="CZW-Aq-1af">
Expand All @@ -120,7 +134,7 @@
</textField>
</subviews>
<constraints>
<constraint firstItem="sxl-0U-ne5" firstAttribute="centerY" secondItem="Tpj-ss-EMv" secondAttribute="centerY" constant="-4.5" id="2Wq-KM-ceX"/>
<constraint firstItem="sxl-0U-ne5" firstAttribute="centerY" secondItem="Tpj-ss-EMv" secondAttribute="centerY" constant="0.5" id="2Wq-KM-ceX"/>
<constraint firstAttribute="trailing" secondItem="j8S-sz-JYh" secondAttribute="trailing" id="G2y-HN-hus"/>
<constraint firstAttribute="bottom" secondItem="CZW-Aq-1af" secondAttribute="bottom" constant="2" id="GqF-H9-jma"/>
<constraint firstAttribute="trailing" secondItem="sxl-0U-ne5" secondAttribute="trailing" id="HvD-9w-Gp7"/>
Expand All @@ -138,6 +152,7 @@
<image name="RestartX" width="32" height="32"/>
<image name="ShutdownX" width="32" height="32"/>
<image name="loginwindow" width="41" height="31.5"/>
<image name="refresh symbol" width="989" height="989"/>
<image name="wifi" width="32" height="32"/>
</resources>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LoginWindowControlsWindowController: NSWindowController {
@IBOutlet weak var wifiGridColumn: NSGridColumn?
let uiLog = "uiLog"
@IBOutlet weak var versionTextField: NSTextField?

var loadPageURL:URL?
var wifiWindowController:WifiWindowController?
override func windowDidLoad() {
super.windowDidLoad()
Expand Down Expand Up @@ -130,6 +130,17 @@ class LoginWindowControlsWindowController: NSWindowController {
// windowContentView.addSubview(wifiView)
}

@IBAction func refreshButtonPressed(_ sender: Any) {
TCSLogWithMark("refreshButtonPressed")
guard let delegate = delegate else {
TCSLogWithMark("No delegate set for shutdown")
return
}
TCSLogWithMark("refreshing")

delegate.reload()

}

@IBAction func restartClick(_ sender: Any) {
TCSLogWithMark("Setting restart user")
Expand Down
5 changes: 4 additions & 1 deletion XCredsLoginPlugIn/Mechanisms/XCredsLoginMechanism.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import Cocoa
super.init(mechanism: mechanism)

}

override func reload() {
TCSLogWithMark("reload in controller")
webViewController.loadPage()
}

@objc override func run() {
TCSLogWithMark("\(#function) \(#file):\(#line)")
Expand Down
20 changes: 20 additions & 0 deletions XCredsLoginPlugIn/loadpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<style>
.center-screen {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
min-height: 100vh;
}
</style>
</head>
<body>
<div class="center-screen">
<h1>Please Wait....</h1>
</div>
</body>
</html>
14 changes: 7 additions & 7 deletions app_to_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ set -x
a=123
BUILD_DIR="/tmp/xcreds"
DERIVED_DATA_DIR="${BUILD_DIR}/DerivedData"

REMOTE_MAC="test.local"

agvtool bump
xcodebuild -scheme "XCreds" -configuration "Release" -derivedDataPath "${DERIVED_DATA_DIR}"

ssh root@simac.local 'bash -c "if [ -e "/Applications/XCreds.app" ] ; then echo removing; rm -rf "/Applications/XCreds.app"; fi"'
ssh root@"${REMOTE_MAC}" 'bash -c "if [ -e "/Applications/XCreds.app" ] ; then echo removing; rm -rf "/Applications/XCreds.app"; fi"'

scp -r "${DERIVED_DATA_DIR}"/Build/Products/Release/XCreds.app root@simac.local:/Applications/
scp -r "${DERIVED_DATA_DIR}"/Build/Products/Release/XCreds.app root@"${REMOTE_MAC}":/Applications/

#ssh -J [email protected] [email protected] reboot || exit 0

ssh root@simac.local /Applications/XCreds.app/Contents/Resources/xcreds_login.sh -r
ssh root@"${REMOTE_MAC}" /Applications/XCreds.app/Contents/Resources/xcreds_login.sh -r

ssh root@simac.local /Applications/XCreds.app/Contents/Resources/xcreds_login.sh -i
ssh root@"${REMOTE_MAC}" /Applications/XCreds.app/Contents/Resources/xcreds_login.sh -i

ssh root@simac.local killall -9 SecurityAgent || echo "unable to kill"
#ssh root@simac.local reboot
#ssh root@"${REMOTE_MAC}" killall -9 SecurityAgent || echo "unable to kill"
ssh root@"${REMOTE_MAC}" reboot
7 changes: 4 additions & 3 deletions push_to_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
set -x
SECURITY_PLUGIN_PATH="/Library/Security/SecurityAgentPlugins/XCredsLoginPlugin.bundle"

REMOTE_MAC="test.local"
echo running ssh
ssh -J [email protected] root@test001.local rm -rf "${SECURITY_PLUGIN_PATH}"
ssh "root@${REMOTE_MAC}" rm -rf "${SECURITY_PLUGIN_PATH}"

echo copying files
scp -r -J [email protected] "${BUILD_ROOT}/Release/XCredsLoginPlugin.bundle" root@test001.local:"${SECURITY_PLUGIN_PATH}"
scp -r "${BUILD_ROOT}/Release/XCredsLoginPlugin.bundle" "root@${REMOTE_MAC}":"${SECURITY_PLUGIN_PATH}"

ssh -J [email protected] root@test001.local killall -9 SecurityAgent
ssh "root@${REMOTE_MAC}" killall -9 SecurityAgent

exit 0
Loading

0 comments on commit 1223e39

Please sign in to comment.