Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions samples/swift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ This sample uses [email/password](https://firebase.google.com/docs/auth/ios/pass
and [Facebook](https://firebase.google.com/docs/auth/ios/facebook-login)
auth, so make sure those are enabled in Firebase console.

The auth example requires a little more setup (adding url schemes, etc)
since it depends on the various keys and tokens for the different auth
services your app will support. Take a look at the [Auth README](../../FirebaseUI/Auth/README.md)
for more information.

10 changes: 9 additions & 1 deletion samples/swift/uidemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
8DABC98A1D3D82D600453807 /* MenuViewController.swift */,
8DABC9AA1D3D947300453807 /* SampleCell.swift */,
8DABC9A81D3D872C00453807 /* Sample.swift */,
8D16073D1D492B200069E4F5 /* AuthViewController.swift */,
8DD17C951D4BCC6500E850E4 /* AuthSample */,
8D643F0F1D4827F10081F979 /* ChatSample */,
8DABC98C1D3D82D600453807 /* Main.storyboard */,
8DABC98F1D3D82D600453807 /* Assets.xcassets */,
Expand All @@ -119,6 +119,14 @@
path = uidemoTests;
sourceTree = "<group>";
};
8DD17C951D4BCC6500E850E4 /* AuthSample */ = {
isa = PBXGroup;
children = (
8D16073D1D492B200069E4F5 /* AuthViewController.swift */,
);
name = AuthSample;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down
10 changes: 10 additions & 0 deletions samples/swift/uidemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import UIKit
import Firebase
import FirebaseAuthUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -32,5 +33,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
FIRApp.configure()
return true
}

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String?
if FIRAuthUI.authUI()?.handleOpenURL(url, sourceApplication: sourceApplication) ?? false {
return true
}
// other URL handling goes here.
return false
}
}

104 changes: 104 additions & 0 deletions samples/swift/uidemo/AuthViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,112 @@
//

import UIKit
import Firebase
import FirebaseAuthUI
import FirebaseGoogleAuthUI
import FirebaseFacebookAuthUI

let kFirebaseTermsOfService = NSURL(string: "https://firebase.google.com/terms/")!

// Your Google app's client ID, which can be found in the GoogleService-Info.plist file
// and is stored in the `clientID` property of your FIRApp options.
// Firebase Google auth is built on top of Google sign-in, so you'll have to add a URL
// scheme to your project as outlined at the bottom of this reference:
// https://developers.google.com/identity/sign-in/ios/start-integrating
let kGoogleAppClientID = (FIRApp.defaultApp()?.options.clientID)!

// Your Facebook App ID, which can be found on developers.facebook.com.
let kFacebookAppID = "your fb app ID here"

/// A view controller displaying a basic sign-in flow using FIRAuthUI.
class AuthViewController: UIViewController {
// Before running this sample, make sure you've correctly configured
// the appropriate authentication methods in Firebase console. For more
// info, see the Auth README at ../../FirebaseUI/Auth/README.md
// and https://firebase.google.com/docs/auth/

private var authStateDidChangeHandle: FIRAuthStateDidChangeListenerHandle?

private(set) var auth: FIRAuth? = FIRAuth.auth()
private(set) var authUI: FIRAuthUI? = FIRAuthUI.authUI()

@IBOutlet private var signOutButton: UIButton!
@IBOutlet private var startButton: UIButton!

@IBOutlet private var signedInLabel: UILabel!
@IBOutlet private var nameLabel: UILabel!
@IBOutlet private var emailLabel: UILabel!
@IBOutlet private var uidLabel: UILabel!

@IBOutlet var topConstraint: NSLayoutConstraint!

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

// If you haven't set up your authentications correctly these buttons
// will still appear in the UI, but they'll crash the app when tapped.
let providers: [FIRAuthProviderUI] = [
FIRGoogleAuthUI(clientID: kGoogleAppClientID)!,
FIRFacebookAuthUI(appID: kFacebookAppID)!,
]
self.authUI?.signInProviders = providers

// This is listed as `TOSURL` in the objc source,
// but it's `termsOfServiceURL` in the current pod version.
self.authUI?.termsOfServiceURL = kFirebaseTermsOfService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely resolve this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's termsOfServiceURL in pod version of objc source too. Most likely pod version and github versions are not the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find! Yeah, we should fix this then, and make sure we're testing against the source version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the sample to be against the source version? Pod version is going to be what everyone encounters as they start using the lib.


self.authStateDidChangeHandle =
self.auth?.addAuthStateDidChangeListener(self.updateUI(auth:user:))
}

override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
if let handle = self.authStateDidChangeHandle {
self.auth?.removeAuthStateDidChangeListener(handle)
}
}

@IBAction func startPressed(sender: AnyObject) {
let controller = self.authUI!.authViewController()
self.presentViewController(controller, animated: true, completion: nil)
}

@IBAction func signOutPressed(sender: AnyObject) {
do {
try self.auth?.signOut()
} catch let error {
// Again, fatalError is not a graceful way to handle errors.
// This error is most likely a network error, so retrying here
// makes sense.
fatalError("Could not sign out: \(error)")
}
}

// Boilerplate
func updateUI(auth auth: FIRAuth, user: FIRUser?) {
if let user = user {
self.signOutButton.enabled = true
self.startButton.enabled = false

self.signedInLabel.text = "Signed in"
self.nameLabel.text = "Name: " + (user.displayName ?? "(null)")
self.emailLabel.text = "Email: " + (user.email ?? "(null)")
self.uidLabel.text = "UID: " + user.uid
} else {
self.signOutButton.enabled = false
self.startButton.enabled = true

self.signedInLabel.text = "Not signed in"
self.nameLabel.text = "Name"
self.emailLabel.text = "Email"
self.uidLabel.text = "UID"
}
}

override func viewWillLayoutSubviews() {
self.topConstraint.constant = self.topLayoutGuide.length
}

static func fromStoryboard(storyboard: UIStoryboard = AppDelegate.mainStoryboard) -> AuthViewController {
return storyboard.instantiateViewControllerWithIdentifier("AuthViewController") as! AuthViewController
}
Expand Down
103 changes: 102 additions & 1 deletion samples/swift/uidemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,113 @@
<view key="view" contentMode="scaleToFill" id="u8r-Hb-5vC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YIe-fR-yWY">
<rect key="frame" x="0.0" y="0.0" width="600" height="124"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Not signed in" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8tB-Nb-Xcd">
<rect key="frame" x="8" y="8" width="101" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GCa-X7-ESu">
<rect key="frame" x="8" y="37" width="45" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Email" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iS6-ot-m8Y">
<rect key="frame" x="8" y="66" width="41" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="UID" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HWC-2D-ngV">
<rect key="frame" x="8" y="95" width="29" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="8tB-Nb-Xcd" firstAttribute="leading" secondItem="YIe-fR-yWY" secondAttribute="leading" constant="8" id="4aU-NI-SWp"/>
<constraint firstItem="GCa-X7-ESu" firstAttribute="leading" secondItem="YIe-fR-yWY" secondAttribute="leading" constant="8" id="G6w-I1-yW8"/>
<constraint firstItem="HWC-2D-ngV" firstAttribute="leading" secondItem="YIe-fR-yWY" secondAttribute="leading" constant="8" id="HpK-MN-Aah"/>
<constraint firstItem="8tB-Nb-Xcd" firstAttribute="top" secondItem="YIe-fR-yWY" secondAttribute="top" constant="8" id="kRM-op-ono"/>
<constraint firstItem="iS6-ot-m8Y" firstAttribute="leading" secondItem="YIe-fR-yWY" secondAttribute="leading" constant="8" id="pfj-AJ-isf"/>
<constraint firstItem="GCa-X7-ESu" firstAttribute="top" secondItem="8tB-Nb-Xcd" secondAttribute="bottom" constant="8" id="sHu-Hu-pCC"/>
<constraint firstItem="HWC-2D-ngV" firstAttribute="top" secondItem="iS6-ot-m8Y" secondAttribute="bottom" constant="8" id="tYm-BL-kX5"/>
<constraint firstAttribute="bottom" secondItem="HWC-2D-ngV" secondAttribute="bottom" constant="8" id="xRL-Is-zaO"/>
<constraint firstItem="iS6-ot-m8Y" firstAttribute="top" secondItem="GCa-X7-ESu" secondAttribute="bottom" constant="8" id="yO5-fo-ZdE"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3BK-PR-8FT">
<rect key="frame" x="300" y="124" width="300" height="476"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DqE-YA-5iK">
<rect key="frame" x="133" y="223" width="34" height="30"/>
<state key="normal" title="Start"/>
<connections>
<action selector="startPressed:" destination="Vgg-qQ-Fya" eventType="touchUpInside" id="7Sr-nn-gta"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="DqE-YA-5iK" firstAttribute="centerX" secondItem="3BK-PR-8FT" secondAttribute="centerX" id="Oon-KV-vcj"/>
<constraint firstItem="DqE-YA-5iK" firstAttribute="centerY" secondItem="3BK-PR-8FT" secondAttribute="centerY" id="wsw-LA-OmB"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="eNG-fu-0tI">
<rect key="frame" x="0.0" y="124" width="300" height="476"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="szM-ks-o6D">
<rect key="frame" x="121" y="223" width="57" height="30"/>
<state key="normal" title="Sign out"/>
<connections>
<action selector="signOutPressed:" destination="Vgg-qQ-Fya" eventType="touchUpInside" id="1Ht-pM-WqF"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="szM-ks-o6D" firstAttribute="centerX" secondItem="eNG-fu-0tI" secondAttribute="centerX" id="3eB-p7-5Rg"/>
<constraint firstItem="szM-ks-o6D" firstAttribute="centerY" secondItem="eNG-fu-0tI" secondAttribute="centerY" id="gjJ-Vj-I4W"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="YIe-fR-yWY" firstAttribute="leading" secondItem="u8r-Hb-5vC" secondAttribute="leading" id="AsX-Su-23M"/>
<constraint firstItem="fZA-s2-42O" firstAttribute="top" secondItem="3BK-PR-8FT" secondAttribute="bottom" id="H8Y-aW-eh5"/>
<constraint firstAttribute="trailing" secondItem="3BK-PR-8FT" secondAttribute="trailing" id="NrE-o8-tL3"/>
<constraint firstItem="3BK-PR-8FT" firstAttribute="leading" secondItem="eNG-fu-0tI" secondAttribute="trailing" id="OLY-AY-uJO"/>
<constraint firstItem="eNG-fu-0tI" firstAttribute="top" secondItem="YIe-fR-yWY" secondAttribute="bottom" id="PLX-9b-DWe"/>
<constraint firstItem="fZA-s2-42O" firstAttribute="top" secondItem="eNG-fu-0tI" secondAttribute="bottom" id="RIu-MK-e1w"/>
<constraint firstItem="3BK-PR-8FT" firstAttribute="leading" secondItem="eNG-fu-0tI" secondAttribute="trailing" id="SYR-4B-6DW"/>
<constraint firstItem="eNG-fu-0tI" firstAttribute="top" secondItem="YIe-fR-yWY" secondAttribute="bottom" id="cOi-oH-aAF"/>
<constraint firstItem="3BK-PR-8FT" firstAttribute="top" secondItem="YIe-fR-yWY" secondAttribute="bottom" id="dRr-3V-P72"/>
<constraint firstAttribute="trailing" secondItem="YIe-fR-yWY" secondAttribute="trailing" id="hSP-Ew-sl2"/>
<constraint firstItem="3BK-PR-8FT" firstAttribute="width" secondItem="eNG-fu-0tI" secondAttribute="width" id="kVf-7W-wTI"/>
<constraint firstItem="YIe-fR-yWY" firstAttribute="top" secondItem="u8r-Hb-5vC" secondAttribute="topMargin" id="qLi-uJ-bUD"/>
<constraint firstItem="eNG-fu-0tI" firstAttribute="leading" secondItem="u8r-Hb-5vC" secondAttribute="leading" id="ygi-rX-jiL"/>
</constraints>
</view>
<connections>
<outlet property="emailLabel" destination="iS6-ot-m8Y" id="06e-sc-qW4"/>
<outlet property="nameLabel" destination="GCa-X7-ESu" id="WxF-MQ-yxQ"/>
<outlet property="signOutButton" destination="szM-ks-o6D" id="g3p-ce-KzL"/>
<outlet property="signedInLabel" destination="8tB-Nb-Xcd" id="0lp-Oe-j2G"/>
<outlet property="startButton" destination="DqE-YA-5iK" id="Pr0-kI-YMB"/>
<outlet property="topConstraint" destination="qLi-uJ-bUD" id="L08-SW-Klp"/>
<outlet property="uidLabel" destination="HWC-2D-ngV" id="gMt-EM-7ob"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="LWq-2d-DPi" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2400" y="1023"/>
<point key="canvasLocation" x="2426" y="1003"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="D29-xs-Qyh">
Expand Down
26 changes: 26 additions & 0 deletions samples/swift/uidemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -18,6 +25,25 @@
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>REVERSED_CLIENT_ID</string>
</array>
</dict>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Facebook login needs custom URL schemes and LSApplicationQueriesSchemes.
In addtion to Auth README,
it would be helpful to provide the default settings.

it looks like the following:

<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>REVERSED_CLIENT_ID</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>FACEBOOK_APP_ID</string>
        </array>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added, thanks!

<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>FACEBOOK_APP_ID</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down