Skip to content

Commit

Permalink
style and spm fix
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 committed Sep 30, 2023
1 parent 36be5cc commit 8e65fe8
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 179 deletions.
26 changes: 13 additions & 13 deletions FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ import Foundation
}

public required init?(coder: NSCoder) {
guard let uid = coder.decodeObject(of: [NSString.self], forKey: kUIDCodingKey) as? String else {
guard let uid = coder.decodeObject(of: [NSString.self], forKey: kUIDCodingKey) as? String
else {
return nil
}
self.uid = uid
self.factorID = coder.decodeObject(of: [NSString.self],
forKey: kFactorIDCodingKey) as? String
factorID = coder.decodeObject(of: [NSString.self],
forKey: kFactorIDCodingKey) as? String
displayName = coder.decodeObject(
of: [NSString.self],
forKey: kDisplayNameCodingKey
Expand All @@ -76,16 +77,15 @@ import Foundation
}
}

extension MultiFactorInfo : NSSecureCoding {
private static var secureCodingWorkaround = true
public class var supportsSecureCoding: Bool { return secureCodingWorkaround }
extension MultiFactorInfo: NSSecureCoding {
private static var secureCodingWorkaround = true
public class var supportsSecureCoding: Bool { return secureCodingWorkaround }


public func encode(with coder: NSCoder) {
coder.encode(uid, forKey: kUIDCodingKey)
coder.encode(displayName, forKey: kDisplayNameCodingKey)
coder.encode(enrollmentDate, forKey: kEnrollmentDateCodingKey)
coder.encode(factorID, forKey: kFactorIDCodingKey)
public func encode(with coder: NSCoder) {
coder.encode(uid, forKey: kUIDCodingKey)
coder.encode(displayName, forKey: kDisplayNameCodingKey)
coder.encode(enrollmentDate, forKey: kEnrollmentDateCodingKey)
coder.encode(factorID, forKey: kFactorIDCodingKey)
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@ import Foundation

#if os(iOS)

enum SecretOrID {
case secret(TOTPSecret)
case enrollmentID(String)
}
enum SecretOrID {
case secret(TOTPSecret)
case enrollmentID(String)
}

/** @class FIRTOTPMultiFactorAssertion
@brief The subclass of base class MultiFactorAssertion, used to assert ownership of a TOTP
(Time-based One Time Password) second factor.
This class is available on iOS only.
*/
@objc(FIRTOTPMultiFactorAssertion) public class TOTPMultiFactorAssertion: MultiFactorAssertion {

let oneTimePassword: String
let secretOrID: SecretOrID
@objc(FIRTOTPMultiFactorAssertion) public class TOTPMultiFactorAssertion: MultiFactorAssertion {
let oneTimePassword: String
let secretOrID: SecretOrID

init(secretOrID: SecretOrID, oneTimePassword: String) {
self.oneTimePassword = oneTimePassword
self.secretOrID = secretOrID
super.init(factorID: PhoneMultiFactorInfo.TOTPMultiFactorID)
init(secretOrID: SecretOrID, oneTimePassword: String) {
self.oneTimePassword = oneTimePassword
self.secretOrID = secretOrID
super.init(factorID: PhoneMultiFactorInfo.TOTPMultiFactorID)
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,69 @@ import Foundation

#if os(iOS)

/**
@class FIRTOTPMultiFactorGenerator
@brief The data structure used to help initialize an assertion for a second factor entity to the
Firebase Auth/CICP server. Depending on the type of second factor, this will help generate
the assertion.
This class is available on iOS only.
*/
@objc(FIRTOTPMultiFactorGenerator) public class TOTPMultiFactorGenerator: NSObject {

/**
@fn generateSecretWithMultiFactorSession
@brief Creates a TOTP secret as part of enrolling a TOTP second factor. Used for generating a
QR code URL or inputting into a TOTP app. This method uses the auth instance corresponding to the
user in the multiFactorSession.
@param session The multiFactorSession instance.
@param completion Completion block
@class FIRTOTPMultiFactorGenerator
@brief The data structure used to help initialize an assertion for a second factor entity to the
Firebase Auth/CICP server. Depending on the type of second factor, this will help generate
the assertion.
This class is available on iOS only.
*/
@objc public func generateSecretWithMultiFactorSession(session: MultiFactorSession,
completion:((TOTPSecret?, Error?) -> Void )) {
// Saturday TODO

}
@objc(FIRTOTPMultiFactorGenerator) public class TOTPMultiFactorGenerator: NSObject {
/**
@fn generateSecretWithMultiFactorSession
@brief Creates a TOTP secret as part of enrolling a TOTP second factor. Used for generating a
QR code URL or inputting into a TOTP app. This method uses the auth instance corresponding to the
user in the multiFactorSession.
@param session The multiFactorSession instance.
@param completion Completion block
*/
@objc public func generateSecretWithMultiFactorSession(session: MultiFactorSession,
completion: (TOTPSecret?, Error?)
-> Void) {
// Saturday TODO
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
public func generateSecretWithMultiFactorSession(session: MultiFactorSession) async throws
-> TOTPSecret {
return try await withCheckedThrowingContinuation { continuation in
self.generateSecretWithMultiFactorSession(session: session) { secret, error in
if let secret {
continuation.resume(returning: secret)
} else {
continuation.resume(throwing: error!)
}
}
}
}
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
public func generateSecretWithMultiFactorSession(session: MultiFactorSession) async throws
-> TOTPSecret {
return try await withCheckedThrowingContinuation { continuation in
self.generateSecretWithMultiFactorSession(session: session) { secret, error in
if let secret {
continuation.resume(returning: secret)
} else {
continuation.resume(throwing: error!)
}
}
}
}

/**
@fn assertionForEnrollmentWithSecret:
@brief Initializes the MFA assertion to confirm ownership of the TOTP second factor. This assertion
is used to complete enrollment of TOTP as a second factor.
@param secret The TOTP secret.
@param oneTimePassword one time password string.
*/
@objc(assertionForEnrollmentWithSecret:oneTimePassword:)
public func assertionForEnrollment(secret: TOTPSecret, oneTimePassword: String) -> TOTPMultiFactorAssertion {
return TOTPMultiFactorAssertion(secretOrID: SecretOrID.secret(secret),
oneTimePassword: oneTimePassword)
}
/**
@fn assertionForEnrollmentWithSecret:
@brief Initializes the MFA assertion to confirm ownership of the TOTP second factor. This assertion
is used to complete enrollment of TOTP as a second factor.
@param secret The TOTP secret.
@param oneTimePassword one time password string.
*/
@objc(assertionForEnrollmentWithSecret:oneTimePassword:)
public func assertionForEnrollment(secret: TOTPSecret,
oneTimePassword: String) -> TOTPMultiFactorAssertion {
return TOTPMultiFactorAssertion(secretOrID: SecretOrID.secret(secret),
oneTimePassword: oneTimePassword)
}

/**
@fn assertionForSignInWithenrollmentID:
@brief Initializes the MFA assertion to confirm ownership of the TOTP second factor. This
assertion is used to complete signIn with TOTP as a second factor.
@param enrollmentID The ID that identifies the enrolled TOTP second factor.
@param oneTimePassword one time password string.
*/
@objc(assertionForSignInWithEnrollmentID:oneTimePassword:)
public func assertionForSignIn(enrollmentID: String, oneTimePassword: String) -> TOTPMultiFactorAssertion {
return TOTPMultiFactorAssertion(secretOrID: SecretOrID.enrollmentID(enrollmentID),
oneTimePassword: oneTimePassword)
/**
@fn assertionForSignInWithenrollmentID:
@brief Initializes the MFA assertion to confirm ownership of the TOTP second factor. This
assertion is used to complete signIn with TOTP as a second factor.
@param enrollmentID The ID that identifies the enrolled TOTP second factor.
@param oneTimePassword one time password string.
*/
@objc(assertionForSignInWithEnrollmentID:oneTimePassword:)
public func assertionForSignIn(enrollmentID: String,
oneTimePassword: String) -> TOTPMultiFactorAssertion {
return TOTPMultiFactorAssertion(secretOrID: SecretOrID.enrollmentID(enrollmentID),
oneTimePassword: oneTimePassword)
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ import Foundation

#if os(iOS)

/**
@class FIRTotpMultiFactorInfo
@brief Extends the MultiFactorInfo class for time based one-time password second factors.
The identifier of this second factor is "totp".
This class is available on iOS only.
*/
class TOTPMultiFactorInfo: MultiFactorInfo {

/**
@brief This is the totp info for the second factor.
*/
let totpInfo: NSObject?
@class FIRTotpMultiFactorInfo
@brief Extends the MultiFactorInfo class for time based one-time password second factors.
The identifier of this second factor is "totp".
This class is available on iOS only.
*/
class TOTPMultiFactorInfo: MultiFactorInfo {
/**
@brief This is the totp info for the second factor.
*/
let totpInfo: NSObject?

/**
@fn initWithProto:
@brief Initilize the FIRAuthProtoMFAEnrollment instance with proto.
@param proto FIRAuthProtoMFAEnrollment proto object.
*/
init(proto: AuthProtoMFAEnrollment) {
self.totpInfo = proto.totpInfo
super.init(proto: proto, factorID: PhoneMultiFactorInfo.TOTPMultiFactorID)
}

public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
/**
@fn initWithProto:
@brief Initilize the FIRAuthProtoMFAEnrollment instance with proto.
@param proto FIRAuthProtoMFAEnrollment proto object.
*/
init(proto: AuthProtoMFAEnrollment) {
totpInfo = proto.totpInfo
super.init(proto: proto, factorID: PhoneMultiFactorInfo.TOTPMultiFactorID)
}

@available(*, unavailable)
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
}

#endif
Loading

0 comments on commit 8e65fe8

Please sign in to comment.