Skip to content

Commit

Permalink
added support for Google IdP
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Jun 15, 2022
1 parent 07947e9 commit 4733a6c
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 40 deletions.
44 changes: 44 additions & 0 deletions Profile Manifest/com.twocanoes.xcreds.plist
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,36 @@ A profile can consist of payloads with different version numbers. For example, c

</dict>

<dict>
<key>pfm_name</key>
<string>clientSecret</string>
<key>pfm_type</key>
<string>string</string>
<key>pfm_title</key>
<string>Client Secret</string>
<key>pfm_description</key>
<string>Client Secret sometimes required by identity provider.</string>

<!-- This value will be automatically set as the value until the user changes it. -->
<key>pfm_default</key>
<string></string>

</dict>
<dict>
<key>pfm_name</key>
<string>scopes</string>
<key>pfm_type</key>
<string>string</string>
<key>pfm_title</key>
<string>Scopes</string>
<key>pfm_description</key>
<string>OIDC Scopes</string>

<!-- This value will be automatically set as the value until the user changes it. -->
<key>pfm_default</key>
<string>profile openid offline_access</string>

</dict>


<dict>
Expand Down Expand Up @@ -300,6 +330,20 @@ A profile can consist of payloads with different version numbers. For example, c
<true/>
</dict>

<dict>
<key>pfm_name</key>
<string>shouldSetGoogleAccessTypeToOffline</string>
<key>pfm_type</key>
<string>boolean</string>
<key>pfm_title</key>
<string>Request Google Refresh Token</string>
<key>pfm_description</key>
<string>When using Google IdP, a refresh token may need be requested in a non-standard way.</string>
<key>pfm_default</key>
<false/>
</dict>


<dict>
<key>pfm_name</key>
<string>showDebug</string>
Expand Down
2 changes: 1 addition & 1 deletion XCreds/PrefKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

enum PrefKeys: String {
case clientID, clientSecret, discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours, showDebug, verifyPassword, shouldShowQuit, shouldShowPreferencesOnStart
case clientID, clientSecret, discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours, showDebug, verifyPassword, shouldShowQuit, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline
}
1 change: 0 additions & 1 deletion XCreds/TokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class TokenManager {

}
catch {
print(String(data: data, encoding: .utf8) as Any)
completion(true,false)
return
}
Expand Down
12 changes: 11 additions & 1 deletion XCreds/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ class WebViewController: NSWindowController {
if let scopesRaw = UserDefaults.standard.string(forKey: PrefKeys.scopes.rawValue) {
scopes = scopesRaw.components(separatedBy: " ")
}
//
var additionalParameters:[String:String]? = nil

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: ["profile", "openid", "offline_access"])
if UserDefaults.standard.bool(forKey: PrefKeys.shouldSetGoogleAccessTypeToOffline.rawValue) == true {
additionalParameters = ["access_type":"offline", "prompt":"consent"]
}

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()
Expand Down Expand Up @@ -104,6 +110,10 @@ extension WebViewController: WKNavigationDelegate {
// Google snarfing
let javaScript = "document.querySelector('input[type=password]').value"
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
if let rawPass = response as? String {
self.password=rawPass
}

// if let rawPass = response as? String,
// rawPass != "" {
// let alert = NSAlert.init()
Expand Down
2 changes: 2 additions & 0 deletions XCreds/defaults.plist
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
<true/>
<key>shouldShowPreferencesOnStart</key>
<false/>
<key>shouldSetGoogleAccessTypeToOffline</key>
<false/>
</dict>
</plist>
55 changes: 36 additions & 19 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
767116B3284B045800CCD6FF /* KeychainUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 767116B2284B045800CCD6FF /* KeychainUtil.swift */; };
76D7ADFB284EB15100332EBC /* TCSUnifiedLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D7ADF9284EB15000332EBC /* TCSUnifiedLogger.m */; };
76D7ADFE284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D7ADFC284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m */; };
76DD6D17285997F300A700ED /* OIDCLite in Frameworks */ = {isa = PBXBuildFile; productRef = 76DD6D16285997F300A700ED /* OIDCLite */; };
76EE069E27FD1D00009E0F3A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE069D27FD1D00009E0F3A /* AppDelegate.swift */; };
76EE06A027FD1D01009E0F3A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 76EE069F27FD1D01009E0F3A /* Assets.xcassets */; };
76EE06A327FD1D01009E0F3A /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 76EE06A127FD1D01009E0F3A /* MainMenu.xib */; };
Expand All @@ -36,7 +37,6 @@
76EE06BC27FD1EFE009E0F3A /* PrefsMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE06BB27FD1EFE009E0F3A /* PrefsMenuItem.swift */; };
76EE06BE27FD1F13009E0F3A /* CheckTokenMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE06BD27FD1F13009E0F3A /* CheckTokenMenuItem.swift */; };
76EE06C227FD1F50009E0F3A /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE06C127FD1F50009E0F3A /* MainMenu.swift */; };
76EE06C527FD1FB2009E0F3A /* OIDCLite in Frameworks */ = {isa = PBXBuildFile; productRef = 76EE06C427FD1FB2009E0F3A /* OIDCLite */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -59,6 +59,7 @@
76D7ADFA284EB15100332EBC /* TCSUnifiedLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TCSUnifiedLogger.h; sourceTree = "<group>"; };
76D7ADFC284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+TCSRealHomeFolder.m"; sourceTree = "<group>"; };
76D7ADFD284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+TCSRealHomeFolder.h"; sourceTree = "<group>"; };
76DD6D122859978F00A700ED /* OIDCLite */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = OIDCLite; path = ../OIDCLite; sourceTree = "<group>"; };
76EE069A27FD1D00009E0F3A /* XCreds.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XCreds.app; sourceTree = BUILT_PRODUCTS_DIR; };
76EE069D27FD1D00009E0F3A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
76EE069F27FD1D01009E0F3A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -83,18 +84,35 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
76EE06C527FD1FB2009E0F3A /* OIDCLite in Frameworks */,
76DD6D17285997F300A700ED /* OIDCLite in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
76DD6D112859978F00A700ED /* Packages */ = {
isa = PBXGroup;
children = (
76DD6D122859978F00A700ED /* OIDCLite */,
);
name = Packages;
sourceTree = "<group>";
};
76DD6D15285997F300A700ED /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
76EE069127FD1D00009E0F3A = {
isa = PBXGroup;
children = (
76DD6D112859978F00A700ED /* Packages */,
76EE069C27FD1D00009E0F3A /* XCreds */,
76EE069B27FD1D00009E0F3A /* Products */,
76DD6D15285997F300A700ED /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -162,10 +180,11 @@
buildRules = (
);
dependencies = (
76DD6D14285997DA00A700ED /* PBXTargetDependency */,
);
name = XCreds;
packageProductDependencies = (
76EE06C427FD1FB2009E0F3A /* OIDCLite */,
76DD6D16285997F300A700ED /* OIDCLite */,
);
productName = xCreds;
productReference = 76EE069A27FD1D00009E0F3A /* XCreds.app */;
Expand Down Expand Up @@ -196,7 +215,6 @@
);
mainGroup = 76EE069127FD1D00009E0F3A;
packageReferences = (
76EE06C327FD1FB2009E0F3A /* XCRemoteSwiftPackageReference "OIDCLite" */,
);
productRefGroup = 76EE069B27FD1D00009E0F3A /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -256,6 +274,13 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
76DD6D14285997DA00A700ED /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 76DD6D13285997DA00A700ED /* OIDCLite */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
76EE06A127FD1D01009E0F3A /* MainMenu.xib */ = {
isa = PBXVariantGroup;
Expand Down Expand Up @@ -389,7 +414,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1271;
CURRENT_PROJECT_VERSION = 1272;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -418,7 +443,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1271;
CURRENT_PROJECT_VERSION = 1272;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -462,21 +487,13 @@
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
76EE06C327FD1FB2009E0F3A /* XCRemoteSwiftPackageReference "OIDCLite" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://gitlab.com/Mactroll/OIDCLite";
requirement = {
branch = main;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
76EE06C427FD1FB2009E0F3A /* OIDCLite */ = {
76DD6D13285997DA00A700ED /* OIDCLite */ = {
isa = XCSwiftPackageProductDependency;
productName = OIDCLite;
};
76DD6D16285997F300A700ED /* OIDCLite */ = {
isa = XCSwiftPackageProductDependency;
package = 76EE06C327FD1FB2009E0F3A /* XCRemoteSwiftPackageReference "OIDCLite" */;
productName = OIDCLite;
};
/* End XCSwiftPackageProductDependency section */
Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,48 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "F439B3AE-173C-4CE3-BF3D-0169C5BDEC44"
uuid = "48A88CA2-4444-42B1-BCE3-97813394F16C"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/WebView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "187"
endingLineNumber = "187"
landmarkName = "webView(_:didReceiveServerRedirectForProvisionalNavigation:)"
startingLineNumber = "40"
endingLineNumber = "40"
landmarkName = "run()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "D98980F5-796F-4A70-AFB4-5F39580E84F7"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/TokenManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "59"
endingLineNumber = "59"
landmarkName = "getNewAccessToken(completion:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "F8B54C07-8147-4419-A30A-76F2FD91C289"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/TokenManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "80"
endingLineNumber = "80"
landmarkName = "getNewAccessToken(completion:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down

0 comments on commit 4733a6c

Please sign in to comment.