Microsoft通过Firebase登录

时间:2019-11-14 19:40:30

标签: swift firebase firebase-authentication

我对应用程序开发非常陌生,请原谅我。我研究时间太长,似乎无法理解如何使用Firebase为Microsoft登录编写我的登录按钮。到目前为止,这是我的代码:

import UIKit
import FirebaseAuth

class LoginViewController: UIViewController {

    var ref : DatabaseAuth!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

    }


    @IBAction func logIntapped(_ sender: Any) {

        let provider = OAuthProvider(providerID: "microsoft.com")
        provider.getCredentialWith(nil) { (credential, error) in
            if error != nil {
                // Handle error.
                print("Failed to retreive credential.")
                return
            }
            if credential != nil {
                Auth.auth().signIn(with:completion:)(<#AuthCredential#>) { authResult, error in
                    if error != nil {
                        // Handle error.
                    }
                }
            } else {
                print("Credential is nil.")
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您需要将从Microsoft获得的凭据传递给对Firebase身份验证的调用。像这样:

Auth.auth().signIn(with: credential) { authResult, error in
  ...

另请参阅handling the sign-in flow with the Firebase SDK上的Firebase文档。