Files
firebase-ios-sdk/FirebaseAuth/Sources/Swift/AuthProvider/FacebookAuthProvider.swift
T
Morten Bek Ditlevsen 78b3357fe9 [WIP] Attempt at merging own ported swift code to official repo (#10696)
* Attempt at merging own ported swift code to official repo

* Fix: networkError was accidentally marked as internal.

* Added Copyright notices

* Moved base64 encoding extension. Reformatted a few todos

* Converted a bit of MultiFactor

* Added VerifyPhoneNumberRequest/Response and AuthOperationType
2023-07-11 16:07:41 -07:00

61 lines
1.9 KiB
Swift

// Copyright 2023 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 Foundation
/**
@brief Utility class for constructing Facebook Sign In credentials.
*/
@objc(FIRFacebookAuthProvider) open class FacebookAuthProvider: NSObject {
@objc public static let id = "facebook.com"
/**
@brief Creates an `AuthCredential` for a Facebook sign in.
@param accessToken The Access Token from Facebook.
@return An AuthCredential containing the Facebook credentials.
*/
@objc public class func credential(withAccessToken accessToken: String) -> AuthCredential {
return FacebookAuthCredential(withAccessToken: accessToken)
}
}
@objc(FIRFacebookAuthCredential) private class FacebookAuthCredential: AuthCredential,
NSSecureCoding {
private let accessToken: String
init(withAccessToken accessToken: String) {
self.accessToken = accessToken
super.init(provider: FacebookAuthProvider.id)
}
@objc override func prepare(_ request: VerifyAssertionRequest) {
request.providerAccessToken = accessToken
}
static var supportsSecureCoding = true
func encode(with coder: NSCoder) {
coder.encode(accessToken)
}
required init?(coder: NSCoder) {
guard let accessToken = coder.decodeObject(forKey: "accessToken") as? String else {
return nil
}
self.accessToken = accessToken
super.init(provider: FacebookAuthProvider.id)
}
}