Skip to content

Commit 4733a6c

Browse files
committed
added support for Google IdP
1 parent 07947e9 commit 4733a6c

File tree

9 files changed

+130
-40
lines changed

9 files changed

+130
-40
lines changed

Profile Manifest/com.twocanoes.xcreds.plist

+44
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,36 @@ A profile can consist of payloads with different version numbers. For example, c
243243

244244
</dict>
245245

246+
<dict>
247+
<key>pfm_name</key>
248+
<string>clientSecret</string>
249+
<key>pfm_type</key>
250+
<string>string</string>
251+
<key>pfm_title</key>
252+
<string>Client Secret</string>
253+
<key>pfm_description</key>
254+
<string>Client Secret sometimes required by identity provider.</string>
255+
256+
<!-- This value will be automatically set as the value until the user changes it. -->
257+
<key>pfm_default</key>
258+
<string></string>
259+
260+
</dict>
261+
<dict>
262+
<key>pfm_name</key>
263+
<string>scopes</string>
264+
<key>pfm_type</key>
265+
<string>string</string>
266+
<key>pfm_title</key>
267+
<string>Scopes</string>
268+
<key>pfm_description</key>
269+
<string>OIDC Scopes</string>
270+
271+
<!-- This value will be automatically set as the value until the user changes it. -->
272+
<key>pfm_default</key>
273+
<string>profile openid offline_access</string>
274+
275+
</dict>
246276

247277

248278
<dict>
@@ -300,6 +330,20 @@ A profile can consist of payloads with different version numbers. For example, c
300330
<true/>
301331
</dict>
302332

333+
<dict>
334+
<key>pfm_name</key>
335+
<string>shouldSetGoogleAccessTypeToOffline</string>
336+
<key>pfm_type</key>
337+
<string>boolean</string>
338+
<key>pfm_title</key>
339+
<string>Request Google Refresh Token</string>
340+
<key>pfm_description</key>
341+
<string>When using Google IdP, a refresh token may need be requested in a non-standard way.</string>
342+
<key>pfm_default</key>
343+
<false/>
344+
</dict>
345+
346+
303347
<dict>
304348
<key>pfm_name</key>
305349
<string>showDebug</string>

XCreds/PrefKeys.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
import Foundation
99

1010
enum PrefKeys: String {
11-
case clientID, clientSecret, discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours, showDebug, verifyPassword, shouldShowQuit, shouldShowPreferencesOnStart
11+
case clientID, clientSecret, discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours, showDebug, verifyPassword, shouldShowQuit, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline
1212
}

XCreds/TokenManager.swift

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class TokenManager {
7777

7878
}
7979
catch {
80-
print(String(data: data, encoding: .utf8) as Any)
8180
completion(true,false)
8281
return
8382
}

XCreds/WebView.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ class WebViewController: NSWindowController {
3434
if let scopesRaw = UserDefaults.standard.string(forKey: PrefKeys.scopes.rawValue) {
3535
scopes = scopesRaw.components(separatedBy: " ")
3636
}
37+
//
38+
var additionalParameters:[String:String]? = nil
3739

38-
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"])
40+
if UserDefaults.standard.bool(forKey: PrefKeys.shouldSetGoogleAccessTypeToOffline.rawValue) == true {
41+
additionalParameters = ["access_type":"offline", "prompt":"consent"]
42+
}
43+
44+
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 )
3945
webView.navigationDelegate = self
4046
oidcLite?.delegate = self
4147
oidcLite?.getEndpoints()
@@ -104,6 +110,10 @@ extension WebViewController: WKNavigationDelegate {
104110
// Google snarfing
105111
let javaScript = "document.querySelector('input[type=password]').value"
106112
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
113+
if let rawPass = response as? String {
114+
self.password=rawPass
115+
}
116+
107117
// if let rawPass = response as? String,
108118
// rawPass != "" {
109119
// let alert = NSAlert.init()

XCreds/defaults.plist

+2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@
1616
<true/>
1717
<key>shouldShowPreferencesOnStart</key>
1818
<false/>
19+
<key>shouldSetGoogleAccessTypeToOffline</key>
20+
<false/>
1921
</dict>
2022
</plist>

xCreds.xcodeproj/project.pbxproj

+36-19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
767116B3284B045800CCD6FF /* KeychainUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 767116B2284B045800CCD6FF /* KeychainUtil.swift */; };
2323
76D7ADFB284EB15100332EBC /* TCSUnifiedLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D7ADF9284EB15000332EBC /* TCSUnifiedLogger.m */; };
2424
76D7ADFE284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D7ADFC284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m */; };
25+
76DD6D17285997F300A700ED /* OIDCLite in Frameworks */ = {isa = PBXBuildFile; productRef = 76DD6D16285997F300A700ED /* OIDCLite */; };
2526
76EE069E27FD1D00009E0F3A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE069D27FD1D00009E0F3A /* AppDelegate.swift */; };
2627
76EE06A027FD1D01009E0F3A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 76EE069F27FD1D01009E0F3A /* Assets.xcassets */; };
2728
76EE06A327FD1D01009E0F3A /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 76EE06A127FD1D01009E0F3A /* MainMenu.xib */; };
@@ -36,7 +37,6 @@
3637
76EE06BC27FD1EFE009E0F3A /* PrefsMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE06BB27FD1EFE009E0F3A /* PrefsMenuItem.swift */; };
3738
76EE06BE27FD1F13009E0F3A /* CheckTokenMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE06BD27FD1F13009E0F3A /* CheckTokenMenuItem.swift */; };
3839
76EE06C227FD1F50009E0F3A /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE06C127FD1F50009E0F3A /* MainMenu.swift */; };
39-
76EE06C527FD1FB2009E0F3A /* OIDCLite in Frameworks */ = {isa = PBXBuildFile; productRef = 76EE06C427FD1FB2009E0F3A /* OIDCLite */; };
4040
/* End PBXBuildFile section */
4141

4242
/* Begin PBXFileReference section */
@@ -59,6 +59,7 @@
5959
76D7ADFA284EB15100332EBC /* TCSUnifiedLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TCSUnifiedLogger.h; sourceTree = "<group>"; };
6060
76D7ADFC284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+TCSRealHomeFolder.m"; sourceTree = "<group>"; };
6161
76D7ADFD284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+TCSRealHomeFolder.h"; sourceTree = "<group>"; };
62+
76DD6D122859978F00A700ED /* OIDCLite */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = OIDCLite; path = ../OIDCLite; sourceTree = "<group>"; };
6263
76EE069A27FD1D00009E0F3A /* XCreds.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XCreds.app; sourceTree = BUILT_PRODUCTS_DIR; };
6364
76EE069D27FD1D00009E0F3A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
6465
76EE069F27FD1D01009E0F3A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -83,18 +84,35 @@
8384
isa = PBXFrameworksBuildPhase;
8485
buildActionMask = 2147483647;
8586
files = (
86-
76EE06C527FD1FB2009E0F3A /* OIDCLite in Frameworks */,
87+
76DD6D17285997F300A700ED /* OIDCLite in Frameworks */,
8788
);
8889
runOnlyForDeploymentPostprocessing = 0;
8990
};
9091
/* End PBXFrameworksBuildPhase section */
9192

9293
/* Begin PBXGroup section */
94+
76DD6D112859978F00A700ED /* Packages */ = {
95+
isa = PBXGroup;
96+
children = (
97+
76DD6D122859978F00A700ED /* OIDCLite */,
98+
);
99+
name = Packages;
100+
sourceTree = "<group>";
101+
};
102+
76DD6D15285997F300A700ED /* Frameworks */ = {
103+
isa = PBXGroup;
104+
children = (
105+
);
106+
name = Frameworks;
107+
sourceTree = "<group>";
108+
};
93109
76EE069127FD1D00009E0F3A = {
94110
isa = PBXGroup;
95111
children = (
112+
76DD6D112859978F00A700ED /* Packages */,
96113
76EE069C27FD1D00009E0F3A /* XCreds */,
97114
76EE069B27FD1D00009E0F3A /* Products */,
115+
76DD6D15285997F300A700ED /* Frameworks */,
98116
);
99117
sourceTree = "<group>";
100118
};
@@ -162,10 +180,11 @@
162180
buildRules = (
163181
);
164182
dependencies = (
183+
76DD6D14285997DA00A700ED /* PBXTargetDependency */,
165184
);
166185
name = XCreds;
167186
packageProductDependencies = (
168-
76EE06C427FD1FB2009E0F3A /* OIDCLite */,
187+
76DD6D16285997F300A700ED /* OIDCLite */,
169188
);
170189
productName = xCreds;
171190
productReference = 76EE069A27FD1D00009E0F3A /* XCreds.app */;
@@ -196,7 +215,6 @@
196215
);
197216
mainGroup = 76EE069127FD1D00009E0F3A;
198217
packageReferences = (
199-
76EE06C327FD1FB2009E0F3A /* XCRemoteSwiftPackageReference "OIDCLite" */,
200218
);
201219
productRefGroup = 76EE069B27FD1D00009E0F3A /* Products */;
202220
projectDirPath = "";
@@ -256,6 +274,13 @@
256274
};
257275
/* End PBXSourcesBuildPhase section */
258276

277+
/* Begin PBXTargetDependency section */
278+
76DD6D14285997DA00A700ED /* PBXTargetDependency */ = {
279+
isa = PBXTargetDependency;
280+
productRef = 76DD6D13285997DA00A700ED /* OIDCLite */;
281+
};
282+
/* End PBXTargetDependency section */
283+
259284
/* Begin PBXVariantGroup section */
260285
76EE06A127FD1D01009E0F3A /* MainMenu.xib */ = {
261286
isa = PBXVariantGroup;
@@ -389,7 +414,7 @@
389414
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
390415
CODE_SIGN_STYLE = Automatic;
391416
COMBINE_HIDPI_IMAGES = YES;
392-
CURRENT_PROJECT_VERSION = 1271;
417+
CURRENT_PROJECT_VERSION = 1272;
393418
DEVELOPMENT_TEAM = UXP6YEHSPW;
394419
ENABLE_HARDENED_RUNTIME = YES;
395420
GENERATE_INFOPLIST_FILE = YES;
@@ -418,7 +443,7 @@
418443
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
419444
CODE_SIGN_STYLE = Automatic;
420445
COMBINE_HIDPI_IMAGES = YES;
421-
CURRENT_PROJECT_VERSION = 1271;
446+
CURRENT_PROJECT_VERSION = 1272;
422447
DEVELOPMENT_TEAM = UXP6YEHSPW;
423448
ENABLE_HARDENED_RUNTIME = YES;
424449
GENERATE_INFOPLIST_FILE = YES;
@@ -462,21 +487,13 @@
462487
};
463488
/* End XCConfigurationList section */
464489

465-
/* Begin XCRemoteSwiftPackageReference section */
466-
76EE06C327FD1FB2009E0F3A /* XCRemoteSwiftPackageReference "OIDCLite" */ = {
467-
isa = XCRemoteSwiftPackageReference;
468-
repositoryURL = "https://gitlab.com/Mactroll/OIDCLite";
469-
requirement = {
470-
branch = main;
471-
kind = branch;
472-
};
473-
};
474-
/* End XCRemoteSwiftPackageReference section */
475-
476490
/* Begin XCSwiftPackageProductDependency section */
477-
76EE06C427FD1FB2009E0F3A /* OIDCLite */ = {
491+
76DD6D13285997DA00A700ED /* OIDCLite */ = {
492+
isa = XCSwiftPackageProductDependency;
493+
productName = OIDCLite;
494+
};
495+
76DD6D16285997F300A700ED /* OIDCLite */ = {
478496
isa = XCSwiftPackageProductDependency;
479-
package = 76EE06C327FD1FB2009E0F3A /* XCRemoteSwiftPackageReference "OIDCLite" */;
480497
productName = OIDCLite;
481498
};
482499
/* End XCSwiftPackageProductDependency section */

xCreds.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

-14
This file was deleted.

xCreds.xcodeproj/xcuserdata/tperfitt.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

+36-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,48 @@
77
<BreakpointProxy
88
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
99
<BreakpointContent
10-
uuid = "F439B3AE-173C-4CE3-BF3D-0169C5BDEC44"
10+
uuid = "48A88CA2-4444-42B1-BCE3-97813394F16C"
1111
shouldBeEnabled = "Yes"
1212
ignoreCount = "0"
1313
continueAfterRunningActions = "No"
1414
filePath = "XCreds/WebView.swift"
1515
startingColumnNumber = "9223372036854775807"
1616
endingColumnNumber = "9223372036854775807"
17-
startingLineNumber = "187"
18-
endingLineNumber = "187"
19-
landmarkName = "webView(_:didReceiveServerRedirectForProvisionalNavigation:)"
17+
startingLineNumber = "40"
18+
endingLineNumber = "40"
19+
landmarkName = "run()"
20+
landmarkType = "7">
21+
</BreakpointContent>
22+
</BreakpointProxy>
23+
<BreakpointProxy
24+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
25+
<BreakpointContent
26+
uuid = "D98980F5-796F-4A70-AFB4-5F39580E84F7"
27+
shouldBeEnabled = "Yes"
28+
ignoreCount = "0"
29+
continueAfterRunningActions = "No"
30+
filePath = "XCreds/TokenManager.swift"
31+
startingColumnNumber = "9223372036854775807"
32+
endingColumnNumber = "9223372036854775807"
33+
startingLineNumber = "59"
34+
endingLineNumber = "59"
35+
landmarkName = "getNewAccessToken(completion:)"
36+
landmarkType = "7">
37+
</BreakpointContent>
38+
</BreakpointProxy>
39+
<BreakpointProxy
40+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
41+
<BreakpointContent
42+
uuid = "F8B54C07-8147-4419-A30A-76F2FD91C289"
43+
shouldBeEnabled = "Yes"
44+
ignoreCount = "0"
45+
continueAfterRunningActions = "No"
46+
filePath = "XCreds/TokenManager.swift"
47+
startingColumnNumber = "9223372036854775807"
48+
endingColumnNumber = "9223372036854775807"
49+
startingLineNumber = "80"
50+
endingLineNumber = "80"
51+
landmarkName = "getNewAccessToken(completion:)"
2052
landmarkType = "7">
2153
</BreakpointContent>
2254
</BreakpointProxy>

0 commit comments

Comments
 (0)