Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[auth-swift] Remove FDL dep and update sample readme #12864

Merged
merged 4 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

import FirebaseAuth
import FirebaseDynamicLinks
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
Expand Down Expand Up @@ -58,21 +57,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// MARK: - Firebase 🔥

private func handleIncomingDynamicLink(_ incomingURL: URL) {
DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { dynamicLink, error in
guard error == nil else {
return print("ⓧ Error in \(#function): \(error!.localizedDescription)")
}
let link = incomingURL.absoluteString

guard let link = dynamicLink?.url?.absoluteString else { return }
if AppManager.shared.auth().isSignIn(withEmailLink: link) {
// Save the link as it will be used in the next step to complete login
UserDefaults.standard.set(link, forKey: "Link")

if AppManager.shared.auth().isSignIn(withEmailLink: link) {
// Save the link as it will be used in the next step to complete login
UserDefaults.standard.set(link, forKey: "Link")

// Post a notification to the PasswordlessViewController to resume authentication
NotificationCenter.default
.post(Notification(name: Notification.Name("PasswordlessEmailNotificationSuccess")))
}
// Post a notification to the PasswordlessViewController to resume authentication
NotificationCenter.default
.post(Notification(name: Notification.Name("PasswordlessEmailNotificationSuccess")))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ class PasswordlessViewController: OtherAuthViewController {

// MARK: - Firebase 🔥

private let authorizedDomain: String = "ENTER AUTHORIZED DOMAIN"
private let authorizedDomain: String = "paulb888.page.link"

private func sendSignInLink(to email: String) {
let actionCodeSettings = ActionCodeSettings()
let stringURL = "https://\(authorizedDomain).firebaseapp.com/login?email=\(email)"

// Update "demo" to match the path defined in the dynamic link.
let stringURL = "https://\(authorizedDomain)/demo"
actionCodeSettings.url = URL(string: stringURL)
// The sign-in operation must be completed in the app.
actionCodeSettings.handleCodeInApp = true
Expand All @@ -47,6 +49,7 @@ class PasswordlessViewController: OtherAuthViewController {

// Set `email` property as it will be used to complete sign in after opening email link
self.email = email
print("successfully sent email")
}
}

Expand Down
3 changes: 0 additions & 3 deletions FirebaseAuth/Tests/SampleSwift/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ target 'AuthenticationExample' do

pod 'RecaptchaEnterprise', '~> 18.3'

### For Email Link/Passwordless Auth
pod 'FirebaseDynamicLinks', :path => '../../..'

## Pod for Sign in with Google
pod 'GoogleSignIn'

Expand Down
26 changes: 7 additions & 19 deletions FirebaseAuth/Tests/SampleSwift/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

# Firebase Auth Quickstart
# Firebase Swift Sample App

This Sample App is used for manual and automated Firebase Auth integration testing.

This Firebase quickstart is written in Swift and aims to showcase how Firebase Auth can help manage user authentication. You can read more about Firebase Auth [here](https://firebase.google.com/docs/auth)!

To view the older Objective-C and Swift quickstarts, view the [`LegacyAuthQuickstart`](https://github.com/firebase/quickstart-ios/blob/master/authentication/LegacyAuthQuickstart) directory.
It's implementation is based on the quickstart that can be found
[here](https://github.com/firebase/quickstart-ios/tree/main/authentication)

## Getting Started

Expand All @@ -16,11 +16,6 @@ Clone this project and `cd` into the `AuthenticationExample` directory. Run `pod

### Terminal commands to clone and open the project!
```bash

$ git clone https://github.com/firebase/quickstart-ios.git

$ cd authentication/

$ pod install --repo-update

$ open AuthenticationExample.xcworkspace
Expand Down Expand Up @@ -181,8 +176,6 @@ See the [Getting Started with Password-based Sign In guide](https://firebase.goo

Email Link authentication, which is also referred to as Passwordless authentication, works by sending a verification email to a user requesting to sign in. This verification email contains a special **Dynamic Link** that links the user back to your app, completing authentication in the process. In order to configure this method of authentication, we will use [Firebase Dynamic Links](https://firebase.google.com/docs/dynamic-links), which we will need to set up.

If this is your first time working with Dynamic Links, here's a great [introduction video](https://www.youtube.com/watch?v=KLBjAg6HvG0) from Firebase's Firecast series on YouTube. Note, we will outline most of the steps covered in this tutorial below!

#### Start by going to the [Firebase Console](https://console.firebase.google.com) and navigate to your project:
- Select the **Auth** panel and then click the **Sign In Method** tab.
- Click **Email/Password** and ensure it is enabled.
Expand All @@ -201,14 +194,14 @@ As we mentioned above, we will need to configure dynamic links for this auth flo
- Setup your short URL. Feel free to put whatever here, like "demo", "login, or "passwordless" for example. Click **Next**.
- For the Deep Link URL, configure the URL to look like:
> https://[insert an authorized domain]/login?email=email
>For the authorized domain ⬆, go to the the Authentication tab, then click the "Sign-in method", and scroll down to the "Authorized domains" section. Copy the domain that looks like `[the app's name].firebaseapp.com`. Paste this entire domain into the Deep Link we are creating above. You can also instead allowlist the dynamic links URL prefix and use that here as well.
>For the authorized domain ⬆, go to the the Authentication tab, then click the "Settings" tab, and select the "Authorized domains" section. Copy the domain that looks like `[the app's name].firebaseapp.com`. Paste this entire domain into the Deep Link we are creating above. You can also instead allowlist the dynamic links URL prefix and use that here as well.
- On step 3, **Define link behavior for iOS**, select **Open the deep link in your iOS App** and make sure your app is selected in the drop down.
- Configure the following steps as you please and then hit **Create**!

- Dynamic links use your app's bundle identifier as a url scheme by default. In Xcode, [add a custom URL scheme for your **bundle identifier**](https://developers.google.com/identity/sign-in/ios/start-integrating#add_a_url_scheme_to_your_project).
- Last todo! Navigate to [`sendSignInLink()`](https://github.com/firebase/quickstart-ios/blob/master/authentication/AuthenticationExample/View%20Controllers/Other%20Auth%20Method%20Controllers/PasswordlessViewController.swift#L39) in [`PasswordlessViewController.swift`](https://github.com/firebase/quickstart-ios/blob/master/authentication/AuthenticationExample/View%20Controllers/Other%20Auth%20Method%20Controllers/PasswordlessViewController.swift). Within the method, there is a `stringURL` constant. Paste in the long deeplink you created from the steps above for the `authroizedDomain` property above the method. It should look something like:
```swift
let stringURL = "https://\(authorizedDomain).firebaseapp.com/login?email=\(email)"
let stringURL = "https://\(authorizedDomain)/login"
```

- Run the app on your device or simulator.
Expand All @@ -231,11 +224,7 @@ When the user receives the verification email, they can open the link contained

private func handleIncomingDynamicLink(_ incomingURL: URL) {

DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in

// Handle the potential `error`

guard let link = dynamicLink?.url?.absoluteString else { return }
let link = incomingURL.absoluteString

// Here, we check if our dynamic link is a sign-link (the one we emailed our user!)
if Auth.auth().isSignIn(withEmailLink: link) {
Expand All @@ -245,7 +234,6 @@ private func handleIncomingDynamicLink(_ incomingURL: URL) {

// Post a notification to the PasswordlessViewController to resume authentication
NotificationCenter.default.post(Notification(name: Notification.Name("PasswordlessEmailNotificationSuccess")))
}
}
}
```
Expand Down
Loading