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

Commit 70ac422

Browse files
authored
Implement existing Google-SignIn flow in the demo app (#709)
2 parents ccf121a + 8401321 commit 70ac422

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

Demo/AuthenticatorDemo/AppDelegate.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import UIKit
33
@main
44
class AppDelegate: UIResponder, UIApplicationDelegate {
55

6+
// This is a property defined in `UIApplicationDelegate`. In modern UIKit apps,
7+
// `UISceneConfiguration` is responsible for creating and holding the window.
8+
//
9+
// However, we need to set this anyway because SVProgressHUD accesses it internally and will
10+
// crash the app if the value it finds is nil.
11+
var window: UIWindow?
12+
613
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
714
return true
815
}

Demo/AuthenticatorDemo/Info.plist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>CFBundleURLTypes</key>
6+
<array>
7+
<dict>
8+
<key>CFBundleTypeRole</key>
9+
<string>Editor</string>
10+
<key>CFBundleURLSchemes</key>
11+
<array>
12+
<string>com.googleusercontent.apps.108380595987-ujhrhknecrqli756i72gkcs4aaia6nhb</string>
13+
</array>
14+
</dict>
15+
</array>
516
<key>UIApplicationSceneManifest</key>
617
<dict>
718
<key>UIApplicationSupportsMultipleScenes</key>

Demo/AuthenticatorDemo/SceneDelegate.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1010
window = UIWindow(windowScene: scene)
1111
window?.rootViewController = UINavigationController(rootViewController: ViewController())
1212
window?.makeKeyAndVisible()
13+
14+
// We need to set this relationship to avoid a crash when using SVProgressHUD.
15+
(UIApplication.shared.delegate as? AppDelegate)?.window = window
1316
}
1417
}

Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ extension ViewController {
2525
enableSignInWithApple: false,
2626
enableSignupWithGoogle: true,
2727
enableUnifiedAuth: true,
28-
enableUnifiedCarousel: true
28+
enableUnifiedCarousel: true,
29+
// Notice that this is required as well as `enableSignupWithGoogle` to show the
30+
// option to login with Google.
31+
enableSocialLogin: true
2932
),
3033
style: WordPressAuthenticatorStyle(
3134
// Primary (normal and highlight) is the color of buttons such as "Log in or signup

WordPressAuthenticator/Unified Auth/GoogleAuthenticator.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ private extension GoogleAuthenticator {
231231
}
232232

233233
// Initiate unified path by attempting to login first.
234+
//
235+
// `SVProgressHUD.show()` will crash in an app that doesn't have a window property in its
236+
// `UIApplicationDelegate`, such as those created via the Xcode templates circa version 12
237+
// onwards.
234238
SVProgressHUD.show()
235239
loginFacade.loginToWordPressDotCom(withSocialIDToken: token, service: SocialServiceName.google.rawValue)
236240
}

0 commit comments

Comments
 (0)