FacebookAuthProvider.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2023 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. import Foundation
  15. /// Utility class for constructing Facebook Sign In credentials.
  16. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  17. @objc(FIRFacebookAuthProvider) open class FacebookAuthProvider: NSObject {
  18. /// A string constant identifying the Facebook identity provider.
  19. @objc public static let id = "facebook.com"
  20. /// Creates an `AuthCredential` for a Facebook sign in.
  21. /// - Parameter accessToken: The Access Token from Facebook.
  22. /// - Returns: An `AuthCredential` containing the Facebook credentials.
  23. @objc open class func credential(withAccessToken accessToken: String) -> AuthCredential {
  24. return FacebookAuthCredential(withAccessToken: accessToken)
  25. }
  26. @available(*, unavailable)
  27. @objc override public init() {
  28. fatalError("This class is not meant to be initialized.")
  29. }
  30. }
  31. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  32. @objc(FIRFacebookAuthCredential) class FacebookAuthCredential: AuthCredential, NSSecureCoding,
  33. @unchecked Sendable {
  34. let accessToken: String?
  35. init(withAccessToken accessToken: String) {
  36. self.accessToken = accessToken
  37. super.init(provider: FacebookAuthProvider.id)
  38. }
  39. override func prepare(_ request: VerifyAssertionRequest) {
  40. request.providerAccessToken = accessToken
  41. }
  42. // MARK: Secure Coding
  43. static let supportsSecureCoding = true
  44. func encode(with coder: NSCoder) {
  45. coder.encode(accessToken, forKey: "accessToken")
  46. }
  47. required init?(coder: NSCoder) {
  48. accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as String?
  49. super.init(provider: FacebookAuthProvider.id)
  50. }
  51. }