OtherAuthMethods.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /// Defined namespace for alternative auth methods
  15. /// Used in configuring the UI for `OtherAuthViewController` subclasses
  16. /// - Tag: OtherAuthMethods
  17. enum OtherAuthMethod: String {
  18. case Passwordless = "Email Link/Passwordless"
  19. case PhoneNumber = "Phone Auth"
  20. case Custom = "a Custom Auth System"
  21. case MfaLogin = "Multifactor Authentication"
  22. var navigationTitle: String { "Sign in using \(rawValue)" }
  23. var textFieldPlaceholder: String {
  24. switch self {
  25. case .Passwordless:
  26. return "Enter Authentication Email"
  27. case .PhoneNumber:
  28. return "Enter Phone Number"
  29. case .Custom:
  30. return "Enter Custom Auth Token"
  31. case .MfaLogin:
  32. return "Choose a Second Factor to Continue"
  33. }
  34. }
  35. var textFieldIcon: String {
  36. switch self {
  37. case .Passwordless:
  38. return "envelope.circle"
  39. case .PhoneNumber:
  40. return "phone.circle"
  41. case .Custom:
  42. return "lock.shield"
  43. case .MfaLogin:
  44. return "phone.circle"
  45. }
  46. }
  47. var textFieldInputText: String? {
  48. switch self {
  49. case .PhoneNumber:
  50. return "Example input for +1 (123)456-7890 would be 11234567890"
  51. case .MfaLogin:
  52. return "Enter the index of the selected factor to continue"
  53. default:
  54. return nil
  55. }
  56. }
  57. var buttonTitle: String {
  58. switch self {
  59. case .Passwordless:
  60. return "Send Sign In Link"
  61. case .PhoneNumber:
  62. return "Send Verification Code"
  63. case .Custom:
  64. return "Login"
  65. case .MfaLogin:
  66. return "Send Verification Code"
  67. }
  68. }
  69. var infoText: String {
  70. switch self {
  71. case .Passwordless:
  72. return passwordlessInfoText
  73. case .PhoneNumber:
  74. return phoneNumberInfoText
  75. case .Custom:
  76. return customAuthInfoText
  77. case .MfaLogin:
  78. return mfaLoginInfoText
  79. }
  80. }
  81. private var mfaLoginInfoText: String {
  82. """
  83. MFA placeholder
  84. """
  85. }
  86. private var passwordlessInfoText: String {
  87. """
  88. Authenticate users with only their email, \
  89. no password required! This login flow signs in \
  90. users by emailing them a verification link. \
  91. Opening the link sends users back to the app, \
  92. completing the verification step and signing them in. \
  93. \n
  94. To demo, enter an email for the link to be sent to. \
  95. Without dismissing the current view, switch \
  96. to a mail app and open the link that was emailed to you. \
  97. This should return you to this app, completing the sign in process!
  98. """
  99. }
  100. private var phoneNumberInfoText: String {
  101. """
  102. Firebase can authenticate a user by sending an SMS message \
  103. to the user's phone, prompting them to sign in using a one-time code. \
  104. It is recommended to alert users that standard rates apply to this message. \
  105. Silent APNs notifications are used to verify \
  106. the request is coming from a user's device. If APNs notifications \
  107. are not configured, a reCAPTCHA verification flow will be presented. \
  108. \n
  109. To demo, enter a phone number and wait a few seconds for Firebase \
  110. to present the designated login flow.
  111. """
  112. }
  113. private var customAuthInfoText: String {
  114. """
  115. Create a custom authentication \
  116. system by configuring an authentication \
  117. server to produce custom signed \
  118. tokens when a user successfully signs in. \
  119. These tokens can then be used to \
  120. authenticate with Firebase. \
  121. \n
  122. To demo this login flow, generate a \
  123. custom signed token and paste it in \
  124. the textfield to begin. Visit the docs \
  125. for more info.
  126. """
  127. }
  128. }