2023-08-07 11:55:59 -07:00
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import UIKit
/// Firebase Auth supported identity providers and other methods of authentication
2023-08-24 15:42:51 -07:00
enum AuthMenu : String {
case settings = "Settings"
2023-08-07 11:55:59 -07:00
case google = "google.com"
case apple = "apple.com"
case twitter = "twitter.com"
case microsoft = "microsoft.com"
case gitHub = "github.com"
case yahoo = "yahoo.com"
case facebook = "facebook.com"
case emailPassword = "password"
case passwordless = "emailLink"
case phoneNumber = "phone"
case anonymous
case custom
2023-10-26 14:58:09 -07:00
case initRecaptcha
2023-10-27 12:09:29 -07:00
case customAuthDomain
2023-08-07 11:55:59 -07:00
/// More intuitively named getter for `rawValue`.
var id : String { rawValue }
2023-08-24 15:42:51 -07:00
/// The UI friendly name of the `AuthMenu`. Used for display.
2023-08-07 11:55:59 -07:00
var name : String {
switch self {
2023-08-24 15:42:51 -07:00
case . settings :
return "Settings"
2023-08-07 11:55:59 -07:00
case . google :
return "Google"
case . apple :
return "Apple"
case . twitter :
return "Twitter"
case . microsoft :
return "Microsoft"
case . gitHub :
return "GitHub"
case . yahoo :
return "Yahoo"
case . facebook :
return "Facebook"
case . emailPassword :
return "Email & Password Login"
case . passwordless :
return "Email Link/Passwordless"
case . phoneNumber :
return "Phone Number"
case . anonymous :
return "Anonymous Authentication"
case . custom :
return "Custom Auth System"
2023-10-26 14:58:09 -07:00
case . initRecaptcha :
return "Initialize reCAPTCHA Enterprise"
2023-10-27 12:09:29 -07:00
case . customAuthDomain :
return "Set Custom Auth Domain"
2023-08-07 11:55:59 -07:00
}
}
2023-08-24 15:42:51 -07:00
/// Failable initializer to create an `AuthMenu` from it's corresponding `name` value.
/// - Parameter rawValue: String value representing `AuthMenu`'s name or type.
2023-08-07 11:55:59 -07:00
init ?( rawValue : String ) {
switch rawValue {
2023-08-24 15:42:51 -07:00
case "Settings" :
self = . settings
2023-08-07 11:55:59 -07:00
case "Google" :
self = . google
case "Apple" :
self = . apple
case "Twitter" :
self = . twitter
case "Microsoft" :
self = . microsoft
case "GitHub" :
self = . gitHub
case "Yahoo" :
self = . yahoo
case "Facebook" :
self = . facebook
case "Email & Password Login" :
self = . emailPassword
case "Email Link/Passwordless" :
self = . passwordless
case "Phone Number" :
self = . phoneNumber
case "Anonymous Authentication" :
self = . anonymous
case "Custom Auth System" :
self = . custom
2023-10-26 14:58:09 -07:00
case "Initialize reCAPTCHA Enterprise" :
self = . initRecaptcha
2023-10-27 12:09:29 -07:00
case "Set Custom Auth Domain" :
self = . customAuthDomain
2023-08-07 11:55:59 -07:00
default : return nil
}
}
}
// MARK: DataSourceProvidable
2023-08-24 15:42:51 -07:00
extension AuthMenu : DataSourceProvidable {
private static var providers : [ AuthMenu ] {
2023-08-07 11:55:59 -07:00
[. google , . apple , . twitter , . microsoft , . gitHub , . yahoo , . facebook ]
}
2023-08-24 15:42:51 -07:00
static var settingsSection : Section {
let header = "Auth Settings"
let item = Item ( title : settings . name , hasNestedContent : true )
return Section ( headerDescription : header , items : [ item ])
}
2023-08-07 11:55:59 -07:00
static var providerSection : Section {
let providers = self . providers . map { Item ( title : $0 . name ) }
let header = "Identity Providers"
let footer = "Choose a login flow from one of the identity providers above."
return Section ( headerDescription : header , footerDescription : footer , items : providers )
}
static var emailPasswordSection : Section {
let image = UIImage ( named : "firebaseIcon" )
2023-08-21 16:47:22 -07:00
let header = "Email and Password Login"
2023-08-07 11:55:59 -07:00
let item = Item ( title : emailPassword . name , hasNestedContent : true , image : image )
2023-08-21 16:47:22 -07:00
return Section ( headerDescription : header , items : [ item ])
2023-08-07 11:55:59 -07:00
}
static var otherSection : Section {
let lockSymbol = UIImage . systemImage ( "lock.slash.fill" , tintColor : . systemOrange )
let phoneSymbol = UIImage . systemImage ( "phone.fill" , tintColor : . systemOrange )
let anonSymbol = UIImage . systemImage ( "questionmark.circle.fill" , tintColor : . systemOrange )
let shieldSymbol = UIImage . systemImage ( "lock.shield.fill" , tintColor : . systemOrange )
let otherOptions = [
Item ( title : passwordless . name , image : lockSymbol ),
Item ( title : phoneNumber . name , image : phoneSymbol ),
Item ( title : anonymous . name , image : anonSymbol ),
Item ( title : custom . name , image : shieldSymbol ),
]
2023-08-21 16:47:22 -07:00
let header = "Other Authentication Methods"
return Section ( headerDescription : header , items : otherOptions )
2023-08-07 11:55:59 -07:00
}
2023-10-26 14:58:09 -07:00
static var recaptchaSection : Section {
let image = UIImage ( named : "firebaseIcon" )
let header = "Initialize reCAPTCHA Enterprise"
let item = Item ( title : initRecaptcha . name , hasNestedContent : false , image : image )
return Section ( headerDescription : header , items : [ item ])
}
2023-10-27 12:09:29 -07:00
static var customAuthDomainSection : Section {
let image = UIImage ( named : "firebaseIcon" )
let header = "Custom Auth Domain"
let item = Item ( title : customAuthDomain . name , hasNestedContent : false , image : image )
return Section ( headerDescription : header , items : [ item ])
}
2023-08-07 11:55:59 -07:00
static var sections : [ Section ] {
2023-10-27 12:09:29 -07:00
[ settingsSection , providerSection , emailPasswordSection , otherSection , recaptchaSection ,
customAuthDomainSection ]
2023-08-07 11:55:59 -07:00
}
static var authLinkSections : [ Section ] {
2023-08-24 15:42:51 -07:00
let allItems = AuthMenu . sections . flatMap { $0 . items }
2023-08-07 11:55:59 -07:00
let header = "Manage linking between providers"
let footer =
"Select an unchecked row to link the currently signed in user to that auth provider. To unlink the user from a linked provider, select its corresponding row marked with a checkmark."
return [ Section ( headerDescription : header , footerDescription : footer , items : allItems )]
}
2023-08-24 15:42:51 -07:00
var sections : [ Section ] { AuthMenu . sections }
2023-08-07 11:55:59 -07:00
}