OtherAuthMethods.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. var navigationTitle: String { "Sign in using \(rawValue)" }
  22. var textFieldPlaceholder: String {
  23. switch self {
  24. case .Passwordless:
  25. return "Enter Authentication Email"
  26. case .PhoneNumber:
  27. return "Enter Phone Number"
  28. case .Custom:
  29. return "Enter Custom Auth Token"
  30. }
  31. }
  32. var textFieldIcon: String {
  33. switch self {
  34. case .Passwordless:
  35. return "envelope.circle"
  36. case .PhoneNumber:
  37. return "phone.circle"
  38. case .Custom:
  39. return "lock.shield"
  40. }
  41. }
  42. var textFieldInputText: String? {
  43. switch self {
  44. case .PhoneNumber:
  45. return "Example input for +1 (123)456-7890 would be 11234567890"
  46. default:
  47. return nil
  48. }
  49. }
  50. var buttonTitle: String {
  51. switch self {
  52. case .Passwordless:
  53. return "Send Sign In Link"
  54. case .PhoneNumber:
  55. return "Send Verification Code"
  56. case .Custom:
  57. return "Login"
  58. }
  59. }
  60. var infoText: String {
  61. switch self {
  62. case .Passwordless:
  63. return passwordlessInfoText
  64. case .PhoneNumber:
  65. return phoneNumberInfoText
  66. case .Custom:
  67. return customAuthInfoText
  68. }
  69. }
  70. private var passwordlessInfoText: String {
  71. """
  72. Authenticate users with only their email, \
  73. no password required! This login flow signs in \
  74. users by emailing them a verification link. \
  75. Opening the link sends users back to the app, \
  76. completing the verification step and signing them in. \
  77. \n
  78. To demo, enter an email for the link to be sent to. \
  79. Without dismissing the current view, switch \
  80. to a mail app and open the link that was emailed to you. \
  81. This should return you to this app, completing the sign in process!
  82. """
  83. }
  84. private var phoneNumberInfoText: String {
  85. """
  86. Firebase can authenticate a user by sending an SMS message \
  87. to the user's phone, prompting them to sign in using a one-time code. \
  88. It is recommended to alert users that standard rates apply to this message. \
  89. Silent APNs notifications are used to verify \
  90. the request is coming from a user's device. If APNs notifications \
  91. are not configured, a reCAPTCHA verification flow will be presented. \
  92. \n
  93. To demo, enter a phone number and wait a few seconds for Firebase \
  94. to present the designated login flow.
  95. """
  96. }
  97. private var customAuthInfoText: String {
  98. """
  99. Create a custom authentication \
  100. system by configuring an authentication \
  101. server to produce custom signed \
  102. tokens when a user successfully signs in. \
  103. These tokens can then be used to \
  104. authenticate with Firebase. \
  105. \n
  106. To demo this login flow, generate a \
  107. custom signed token and paste it in \
  108. the textfield to begin. Visit the docs \
  109. for more info.
  110. """
  111. }
  112. }