Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit ccf121a

Browse files
authored
Add email login to demo app (#706)
2 parents 816bb34 + 487132f commit ccf121a

File tree

12 files changed

+471
-10
lines changed

12 files changed

+471
-10
lines changed

.configure

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"project_name": "WordPressAuthenticator-iOS",
3+
"branch": "trunk",
4+
"pinned_hash": "d71ccb4011793d363fbef513903867dfc672e09a",
5+
"files_to_copy": [
6+
{
7+
"file": "iOS/WordPressAuthenticator-Demo/Secrets.swift",
8+
"destination": "~/.configure/wordpress-authenticator-ios-demo/secrets/Secrets.swift",
9+
"encrypt": true
10+
}
11+
],
12+
"file_dependencies": [
13+
14+
]
15+
}

.configure-files/Secrets.swift.enc

576 Bytes
Binary file not shown.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ fastlane/test_output
3737

3838
# SwiftLint Remote Config Cache
3939
.swiftlint/RemoteConfigCache
40+
41+
# All encrypted secrets should be stored under .configure-files
42+
# Everything without a .enc extension is ignored
43+
.configure-files/*
44+
!.configure-files/*.enc
45+
# If the user created a local secrets file, ignore it
46+
Demo/Secrets.swift

Demo/AuthenticatorDemo.xcodeproj/project.pbxproj

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,50 @@
66
objectVersion = 56;
77
objects = {
88

9+
/* Begin PBXAggregateTarget section */
10+
3F27A54E291AE3CF0000996B /* GenerateCredentials */ = {
11+
isa = PBXAggregateTarget;
12+
buildConfigurationList = 3F27A54F291AE3CF0000996B /* Build configuration list for PBXAggregateTarget "GenerateCredentials" */;
13+
buildPhases = (
14+
3F27A552291AE3D60000996B /* Generate Credentials */,
15+
);
16+
dependencies = (
17+
);
18+
name = GenerateCredentials;
19+
productName = GenerateCredentials;
20+
};
21+
/* End PBXAggregateTarget section */
22+
923
/* Begin PBXBuildFile section */
1024
0B9084355AE56CADE54CE018 /* Pods_AuthenticatorDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF02C0C8B7B005AAE3C08BD9 /* Pods_AuthenticatorDemo.framework */; };
25+
3F27A556291AE5F00000996B /* Secrets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F27A555291AE5F00000996B /* Secrets.swift */; };
1126
3F55C3A8292BAAE0002923B1 /* CellConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F55C3A7292BAAE0002923B1 /* CellConfiguration.swift */; };
1227
3F55C3AD292BAB23002923B1 /* UIViewController+Presentation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F55C3AB292BAB23002923B1 /* UIViewController+Presentation.swift */; };
1328
3F55C3AE292BAB23002923B1 /* UIAlertController+Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F55C3AC292BAB23002923B1 /* UIAlertController+Utils.swift */; };
1429
3F55C3B0292BAB54002923B1 /* WKWebView+UserAgent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F55C3AF292BAB54002923B1 /* WKWebView+UserAgent.swift */; };
30+
3F55C3B9292BAD5E002923B1 /* ViewController+WordPressAuthenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F27A55F291E421C0000996B /* ViewController+WordPressAuthenticator.swift */; };
31+
3F55C3BA292BAD61002923B1 /* ViewController+WordPressAuthenticationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F27A55D291E41CC0000996B /* ViewController+WordPressAuthenticationDelegate.swift */; };
1532
3FB5B6EF2912420E00F40408 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FB5B6EE2912420E00F40408 /* AppDelegate.swift */; };
1633
3FB5B6F12912420E00F40408 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FB5B6F02912420E00F40408 /* SceneDelegate.swift */; };
1734
3FB5B6F32912420E00F40408 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FB5B6F22912420E00F40408 /* ViewController.swift */; };
1835
3FB5B6F82912420F00F40408 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3FB5B6F72912420F00F40408 /* Assets.xcassets */; };
1936
3FB5B6FB2912420F00F40408 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3FB5B6F92912420F00F40408 /* LaunchScreen.storyboard */; };
2037
/* End PBXBuildFile section */
2138

39+
/* Begin PBXContainerItemProxy section */
40+
3F27A553291AE4030000996B /* PBXContainerItemProxy */ = {
41+
isa = PBXContainerItemProxy;
42+
containerPortal = 3FB5B6E32912420E00F40408 /* Project object */;
43+
proxyType = 1;
44+
remoteGlobalIDString = 3F27A54E291AE3CF0000996B;
45+
remoteInfo = GenerateCredentials;
46+
};
47+
/* End PBXContainerItemProxy section */
48+
2249
/* Begin PBXFileReference section */
50+
3F27A555291AE5F00000996B /* Secrets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Secrets.swift; path = ../Secrets.swift; sourceTree = BUILT_PRODUCTS_DIR; };
51+
3F27A55D291E41CC0000996B /* ViewController+WordPressAuthenticationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ViewController+WordPressAuthenticationDelegate.swift"; sourceTree = "<group>"; };
52+
3F27A55F291E421C0000996B /* ViewController+WordPressAuthenticator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ViewController+WordPressAuthenticator.swift"; sourceTree = "<group>"; };
2353
3F55C3A7292BAAE0002923B1 /* CellConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellConfiguration.swift; sourceTree = "<group>"; };
2454
3F55C3AB292BAB23002923B1 /* UIViewController+Presentation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Presentation.swift"; sourceTree = "<group>"; };
2555
3F55C3AC292BAB23002923B1 /* UIAlertController+Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertController+Utils.swift"; sourceTree = "<group>"; };
@@ -75,9 +105,12 @@
75105
3FB5B6FC2912420F00F40408 /* Info.plist */,
76106
3FB5B6F92912420F00F40408 /* LaunchScreen.storyboard */,
77107
3FB5B6F02912420E00F40408 /* SceneDelegate.swift */,
108+
3F27A555291AE5F00000996B /* Secrets.swift */,
78109
3F55C3AC292BAB23002923B1 /* UIAlertController+Utils.swift */,
79110
3F55C3AB292BAB23002923B1 /* UIViewController+Presentation.swift */,
80111
3FB5B6F22912420E00F40408 /* ViewController.swift */,
112+
3F27A55D291E41CC0000996B /* ViewController+WordPressAuthenticationDelegate.swift */,
113+
3F27A55F291E421C0000996B /* ViewController+WordPressAuthenticator.swift */,
81114
3F55C3AF292BAB54002923B1 /* WKWebView+UserAgent.swift */,
82115
);
83116
path = AuthenticatorDemo;
@@ -117,6 +150,7 @@
117150
buildRules = (
118151
);
119152
dependencies = (
153+
3F27A554291AE4030000996B /* PBXTargetDependency */,
120154
);
121155
name = AuthenticatorDemo;
122156
productName = AuthenticatorDemo;
@@ -133,6 +167,9 @@
133167
LastSwiftUpdateCheck = 1400;
134168
LastUpgradeCheck = 1400;
135169
TargetAttributes = {
170+
3F27A54E291AE3CF0000996B = {
171+
CreatedOnToolsVersion = 14.1;
172+
};
136173
3FB5B6EA2912420E00F40408 = {
137174
CreatedOnToolsVersion = 14.0.1;
138175
};
@@ -152,6 +189,7 @@
152189
projectRoot = "";
153190
targets = (
154191
3FB5B6EA2912420E00F40408 /* AuthenticatorDemo */,
192+
3F27A54E291AE3CF0000996B /* GenerateCredentials */,
155193
);
156194
};
157195
/* End PBXProject section */
@@ -169,6 +207,26 @@
169207
/* End PBXResourcesBuildPhase section */
170208

171209
/* Begin PBXShellScriptBuildPhase section */
210+
3F27A552291AE3D60000996B /* Generate Credentials */ = {
211+
isa = PBXShellScriptBuildPhase;
212+
buildActionMask = 2147483647;
213+
files = (
214+
);
215+
inputFileListPaths = (
216+
"$(SRCROOT)/Build-Phases/GenerateCredentials.xcfilelist",
217+
);
218+
inputPaths = (
219+
);
220+
name = "Generate Credentials";
221+
outputFileListPaths = (
222+
);
223+
outputPaths = (
224+
"$(BUILD_DIR)/Secrets.swift",
225+
);
226+
runOnlyForDeploymentPostprocessing = 0;
227+
shellPath = /bin/sh;
228+
shellScript = "$SRCROOT/Build-Phases/GenerateCredentials.sh\n";
229+
};
172230
46F868D4B05D9FAC769EF4C5 /* [CP] Embed Pods Frameworks */ = {
173231
isa = PBXShellScriptBuildPhase;
174232
buildActionMask = 2147483647;
@@ -216,6 +274,9 @@
216274
buildActionMask = 2147483647;
217275
files = (
218276
3F55C3AD292BAB23002923B1 /* UIViewController+Presentation.swift in Sources */,
277+
3F55C3BA292BAD61002923B1 /* ViewController+WordPressAuthenticationDelegate.swift in Sources */,
278+
3F55C3B9292BAD5E002923B1 /* ViewController+WordPressAuthenticator.swift in Sources */,
279+
3F27A556291AE5F00000996B /* Secrets.swift in Sources */,
219280
3FB5B6F32912420E00F40408 /* ViewController.swift in Sources */,
220281
3FB5B6EF2912420E00F40408 /* AppDelegate.swift in Sources */,
221282
3F55C3A8292BAAE0002923B1 /* CellConfiguration.swift in Sources */,
@@ -227,6 +288,14 @@
227288
};
228289
/* End PBXSourcesBuildPhase section */
229290

291+
/* Begin PBXTargetDependency section */
292+
3F27A554291AE4030000996B /* PBXTargetDependency */ = {
293+
isa = PBXTargetDependency;
294+
target = 3F27A54E291AE3CF0000996B /* GenerateCredentials */;
295+
targetProxy = 3F27A553291AE4030000996B /* PBXContainerItemProxy */;
296+
};
297+
/* End PBXTargetDependency section */
298+
230299
/* Begin PBXVariantGroup section */
231300
3FB5B6F92912420F00F40408 /* LaunchScreen.storyboard */ = {
232301
isa = PBXVariantGroup;
@@ -239,6 +308,25 @@
239308
/* End PBXVariantGroup section */
240309

241310
/* Begin XCBuildConfiguration section */
311+
3F55C3B3292BABF8002923B1 /* Debug */ = {
312+
isa = XCBuildConfiguration;
313+
buildSettings = {
314+
COPY_PHASE_STRIP = NO;
315+
GCC_DYNAMIC_NO_PIC = NO;
316+
GCC_OPTIMIZATION_LEVEL = 0;
317+
PRODUCT_NAME = GenerateCredentials;
318+
};
319+
name = Debug;
320+
};
321+
3F55C3B4292BABF8002923B1 /* Release */ = {
322+
isa = XCBuildConfiguration;
323+
buildSettings = {
324+
COPY_PHASE_STRIP = YES;
325+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
326+
PRODUCT_NAME = GenerateCredentials;
327+
};
328+
name = Release;
329+
};
242330
3FB5B6FD2912420F00F40408 /* Debug */ = {
243331
isa = XCBuildConfiguration;
244332
buildSettings = {
@@ -410,6 +498,15 @@
410498
/* End XCBuildConfiguration section */
411499

412500
/* Begin XCConfigurationList section */
501+
3F27A54F291AE3CF0000996B /* Build configuration list for PBXAggregateTarget "GenerateCredentials" */ = {
502+
isa = XCConfigurationList;
503+
buildConfigurations = (
504+
3F55C3B3292BABF8002923B1 /* Debug */,
505+
3F55C3B4292BABF8002923B1 /* Release */,
506+
);
507+
defaultConfigurationIsVisible = 0;
508+
defaultConfigurationName = Release;
509+
};
413510
3FB5B6E62912420E00F40408 /* Build configuration list for PBXProject "AuthenticatorDemo" */ = {
414511
isa = XCConfigurationList;
415512
buildConfigurations = (
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enum APICredentials {
2+
3+
// WordPress.com OAuth ClientID / Client Secret
4+
static let client = "0"
5+
static let secret = ""
6+
7+
// Google Login
8+
static let googleLoginClientId = ""
9+
static let googleLoginSchemeId = ""
10+
static let googleLoginServerClientId = ""
11+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import WordPressAuthenticator
2+
3+
extension ViewController: WordPressAuthenticatorDelegate {
4+
5+
var dismissActionEnabled: Bool { true }
6+
7+
var supportActionEnabled: Bool { true }
8+
9+
var wpcomTermsOfServiceEnabled: Bool { true }
10+
11+
var showSupportNotificationIndicator: Bool { true }
12+
13+
var supportEnabled: Bool { true }
14+
15+
var allowWPComLogin: Bool { true }
16+
17+
func createdWordPressComAccount(username: String, authToken: String) {
18+
print(username)
19+
print(authToken)
20+
}
21+
22+
func userAuthenticatedWithAppleUserID(_ appleUserID: String) {
23+
print(appleUserID)
24+
}
25+
26+
func presentSupportRequest(from sourceViewController: UIViewController, sourceTag: WordPressSupportSourceTag) {
27+
fatalError("TODO")
28+
}
29+
30+
func shouldPresentUsernamePasswordController(for siteInfo: WordPressComSiteInfo?, onCompletion: @escaping (WordPressAuthenticatorResult) -> Void) {
31+
fatalError("TODO")
32+
}
33+
34+
func presentLoginEpilogue(in navigationController: UINavigationController, for credentials: AuthenticatorCredentials, source: SignInSource?, onDismiss: @escaping () -> Void) {
35+
fatalError("TODO")
36+
}
37+
38+
func presentSignupEpilogue(in navigationController: UINavigationController, for credentials: AuthenticatorCredentials, service: SocialService?) {
39+
fatalError("TODO")
40+
}
41+
42+
func presentSupport(from sourceViewController: UIViewController, sourceTag: WordPressSupportSourceTag, lastStep: AuthenticatorAnalyticsTracker.Step, lastFlow: AuthenticatorAnalyticsTracker.Flow) {
43+
fatalError("TODO")
44+
}
45+
46+
func shouldPresentLoginEpilogue(isJetpackLogin: Bool) -> Bool {
47+
true
48+
}
49+
50+
func shouldHandleError(_ error: Error) -> Bool {
51+
print(error)
52+
return true
53+
}
54+
55+
func handleError(_ error: Error, onCompletion: @escaping (UIViewController) -> Void) {
56+
dismiss(animated: true) { [weak self] in
57+
self?.presentAlert(
58+
title: "Authentication Error",
59+
message: "\(error.localizedDescription)",
60+
onDismiss: {}
61+
)
62+
}
63+
}
64+
65+
func shouldPresentSignupEpilogue() -> Bool {
66+
true
67+
}
68+
69+
func sync(credentials: AuthenticatorCredentials, onCompletion: @escaping () -> Void) {
70+
dismiss(animated: true) { [weak self] in
71+
self?.presentAlert(
72+
title: "Authentication Successful",
73+
message: "Next step will be syncing credentials",
74+
onDismiss: {}
75+
)
76+
}
77+
}
78+
79+
func track(event: WPAnalyticsStat) {
80+
print(event)
81+
}
82+
83+
func track(event: WPAnalyticsStat, properties: [AnyHashable: Any]) {
84+
print(event)
85+
print(properties)
86+
}
87+
88+
func track(event: WPAnalyticsStat, error: Error) {
89+
print(event)
90+
print(error)
91+
}
92+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import WebKit
2+
import WordPressAuthenticator
3+
4+
extension ViewController {
5+
6+
func initializeWordPressAuthenticator() {
7+
// In a proper app, we'd want to split this call to keep the code readable. Here, it's
8+
// useful to keep it all in one block to show how insanely long it is.
9+
WordPressAuthenticator.initialize(
10+
configuration: WordPressAuthenticatorConfiguration(
11+
wpcomClientId: APICredentials.client,
12+
wpcomSecret: APICredentials.secret,
13+
wpcomScheme: "wordpress-authenticator-ios-demo",
14+
wpcomTermsOfServiceURL: "https://wordpress.com/tos/",
15+
wpcomBaseURL: "https://wordpress.com",
16+
wpcomAPIBaseURL: "https://public-api.wordpress.com/",
17+
googleLoginClientId: APICredentials.googleLoginClientId,
18+
googleLoginServerClientId: APICredentials.googleLoginServerClientId,
19+
googleLoginScheme: APICredentials.googleLoginSchemeId,
20+
userAgent: "\(WKWebView.userAgent)-wordpress-authenticator-demo-app",
21+
showLoginOptions: true,
22+
enableSignUp: true,
23+
// SIWA might require additional settings in the Developer Portal... Keeping it off
24+
// for the moment
25+
enableSignInWithApple: false,
26+
enableSignupWithGoogle: true,
27+
enableUnifiedAuth: true,
28+
enableUnifiedCarousel: true
29+
),
30+
style: WordPressAuthenticatorStyle(
31+
// Primary (normal and highlight) is the color of buttons such as "Log in or signup
32+
// with WordPress.com"
33+
primaryNormalBackgroundColor: .orange,
34+
primaryNormalBorderColor: .none,
35+
primaryHighlightBackgroundColor: .brown,
36+
primaryHighlightBorderColor: .none,
37+
// Secondary (normal and highlight) is the color of buttons such as "Enter your
38+
// existing site address" (the one just below "Log in or signup...") or "Continue
39+
// with Google".
40+
secondaryNormalBackgroundColor: .blue,
41+
secondaryNormalBorderColor: .black,
42+
secondaryHighlightBackgroundColor: .purple,
43+
secondaryHighlightBorderColor: .black,
44+
disabledBackgroundColor: .systemGray,
45+
disabledBorderColor: .systemGray,
46+
primaryTitleColor: .white,
47+
secondaryTitleColor: .white,
48+
disabledTitleColor: .white,
49+
disabledButtonActivityIndicatorColor: .label,
50+
textButtonColor: .red,
51+
textButtonHighlightColor: .red,
52+
instructionColor: .label,
53+
subheadlineColor: .secondaryLabel,
54+
placeholderColor: .red,
55+
viewControllerBackgroundColor: .red,
56+
textFieldBackgroundColor: .red,
57+
// The navBar settings here are ignored. Those in
58+
// `WordPressAuthenticatorUnifiedStyle` take precedence.
59+
navBarImage: UIImage(),
60+
navBarBadgeColor: .red,
61+
navBarBackgroundColor: .orange
62+
),
63+
unifiedStyle: WordPressAuthenticatorUnifiedStyle(
64+
borderColor: .separator,
65+
errorColor: .red,
66+
textColor: .label,
67+
textSubtleColor: .blue,
68+
textButtonColor: .purple,
69+
textButtonHighlightColor: .orange,
70+
viewControllerBackgroundColor: .systemBackground,
71+
navBarBackgroundColor: .blue,
72+
navButtonTextColor: .white,
73+
navTitleTextColor: .white
74+
)
75+
)
76+
}
77+
}

0 commit comments

Comments
 (0)