Files
firebase-ios-sdk/FirebaseAuth/Sources/Swift/AuthProvider/GitHubAuthProvider.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

60 lines
1.8 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 GitHub Sign In credentials.
*/
@objc(FIRGitHubAuthProvider) open class GitHubAuthProvider: NSObject {
@objc public static let id = "github.com"
/**
@brief Creates an `AuthCredential` for a GitHub sign in.
@param token The GitHub OAuth access token.
@return An AuthCredential containing the GitHub credentials.
*/
@objc public class func credential(withToken token: String) -> AuthCredential {
return GitHubAuthCredential(withToken: token)
}
}
@objc(FIRGitHubAuthCredential) private class GitHubAuthCredential: AuthCredential, NSSecureCoding {
private let token: String
init(withToken token: String) {
self.token = token
super.init(provider: GitHubAuthProvider.id)
}
@objc override func prepare(_ request: VerifyAssertionRequest) {
request.providerAccessToken = token
}
static var supportsSecureCoding = true
func encode(with coder: NSCoder) {
coder.encode(token)
}
required init?(coder: NSCoder) {
guard let token = coder.decodeObject(forKey: "token") as? String else {
return nil
}
self.token = token
super.init(provider: GitHubAuthProvider.id)
}
}