有使用auth0进行身份验证的解决方案吗?

时间:2019-10-30 12:27:47

标签: ios auth0 swift4.2 auth0-lock

我正在swift 4.2

工作

该代码以前可以工作,但是我不知道现在如何工作。 所以我的authentification部分带有auth0

我有两个问题:

1-我既无法使用gmail也无法登录或注册Facebook,这很奇怪,因为一周前它可以正常工作,并且向我显示了此错误。

==============

  

失败,错误无法验证

==============

2-当我使用邮件和密码登录时,它将无法登录,并显示此错误

==============

  

callGetGeneric响应:{“代码”:“ invalid_token”,“消息”:“无效   签名”}
{
code =“ invalid_token”;
message =“无效   签名”;
}

==============

我正在使用以下代码:

 fileprivate func presentLockLogin() {
  Lock.classic().withOptions {
 $0.closable = true
 $0.allow = [.Login, .ResetPassword]
 }.onAuth { credentials in

    guard let accessToken = credentials.accessToken else { return }
      Auth0
        .authentication()
        .userInfo(token: accessToken)
        .start { result in
        switch result {
        case .success(let profile):
         NSLog("%@", profile.description)


        // Save token and user profile
        UserAuth.currentIdToken = credentials.idToken
        UserAuth.currentRefreshToken = credentials.refreshToken
        UserAuth.currentAccessToken = credentials.accessToken

        // Save the attribute that we want
        var tempProfile:Dictionary = [String:String]()
        tempProfile["name"] = profile.name
        tempProfile["nickname"] = profile.nickname
        tempProfile["pictureURL"] = profile.pictureURL.absoluteString

        UserAuth.currentUserProfile = tempProfile

        // Get current account from token
        self.getCurrentAccount() {
          result in
          switch result {
             case .success(let currentAccount):
                // Dismiss the Lock controller
                 //controller?.dismiss(animated: true, completion: {
                  // Instead present home
                    Server.getUsersForCurrentAccount { result in
                    switch result {
                        case .success(let jsonArray):
                         let allUsersForAccount = jsonArray.flatMap { User(dictionary: $0) }
                         // Get the main user (if there are several, get the first main user)
                          if let mainUser = (allUsersForAccount.filter { $0.main == true }).first {
                          // Save the currentUser
                           User.currentUser = mainUser

                                                        Server.getUserMustValidateTaC(forUserId: mainUser.id, completion: { (result) in
        switch result {
         case .success(let jsonArray):
           let jsonDictionnary = jsonArray[0]
           if let mustValidateTaC = jsonDictionnary["mustValidate"] as? Bool
             {
               if (mustValidateTaC)
              {
                if let verion = jsonDictionnary["version"] as? Int,
                 let release = jsonDictionnary["release"] as? Int,
                  let htmlTaC = jsonDictionnary["fileContentsHtml"] as? String
                     {
                       self.versionTaC = verion
                       self.releaseTaC = release
                       self.htmlTextTaC = htmlTaC
                                                                            self.performSegue(withIdentifier: "SegueLoginToTerms", sender: nil);
                        }
                       }
                      else
                       {
                // Present rootViewController
   let rootVC = UIStoryboard.mainStoryboard().instantiateViewControllerWithClass(CustomSideMenuController.self)
    self.present(rootVC, animated: true, completion: nil)
                       }
               }
              case .failure(let error):
             self.displayAlert(title: "Couldn't find Terms and Conditions!", message: "\(error)", actionHandler: { alertAction in
              // Back to login screen
                  let launcherVC = UIStoryboard.loginStoryboard().instantiateViewControllerWithClass(LauncherViewController.self)
                                                                    self.navigationController?.present(launcherVC, animated: true, completion: nil)
                       })

                   }
              })

                } else {
                  print("No main user found")
                  // Present the userInfo view controller
                       //let rootVC =         


    UIStoryboard.loginStoryboard().instantiateViewControllerWithClass(AccountInfoViewController.self)
                      //self.present(rootVC, animated: true, completion: nil)

 let accountInfoNavController = UIStoryboard.loginStoryboard().instantiateViewControllerWithClass(AccountInfoNavigationController.self)
         if let accountInfoVC = accountInfoNavController.contentViewController as? AccountInfoViewController {
          accountInfoVC.account = currentAccount
                      }
                                                    self.present(accountInfoNavController, animated: true, completion: nil)
         }

     case .failure(let serverError):
       print("Users: Server error: \(serverError)")
         }
    }
    //})




 case .failure(_):
 // Message KO
 //controller?.dismiss(animated: true, completion: {
self.displayAlert(title: NSLocalizedString("creation_error_title", comment: "Error"),
message: NSLocalizedString("creation_error_msg", comment: "Something went wrong"))
           //})
         //}
     break;
   }
  }



 case .failure(let error):
      print("Failed with error", error)
         break;
       }
  }

 }.onSignUp { email, attributes in
   print("New user with email \(email)!")
        }.onError { error in
             print("Failed with error", error)
         }.present(from: self)
  }

  fileprivate func presentLockSignup() {
  Lock.classic().withOptions {
                $0.closable = true
                $0.allow = [.Signup]
                }.onAuth { credentials in


                    guard let accessToken = credentials.accessToken else { return }
                    Auth0
                        .authentication()
                        .userInfo(token: accessToken)
                        .start { result in
                            switch result {
                            case .success(let profile):
                                NSLog("%@", profile.description)

                                /*guard let token = accessToken,
                                 let profile = profile
                                 else {
                                 return // it's a sign up
                                 }*/

                                // Save token and user profile
                                UserAuth.currentIdToken = credentials.idToken
                                UserAuth.currentRefreshToken = credentials.refreshToken
                                UserAuth.currentAccessToken = credentials.accessToken

                                // Save the attribute that we want
                                var tempProfile:Dictionary = [String:String]()
                                tempProfile["name"] = profile.name
                                tempProfile["nickname"] = profile.nickname
                                tempProfile["pictureURL"] = profile.pictureURL.absoluteString

                                UserAuth.currentUserProfile = tempProfile

                                // Get current account from token
                                self.getCurrentAccount() {
                                    result in
                                    switch result {
                                    case .success(let currentAccount):
                                        // Dismiss the Lock controller
                                        //controller?.dismiss(animated: true, completion: {

                                            // Present the account info
                                            let accountInfoNavController = UIStoryboard.loginStoryboard().instantiateViewControllerWithClass(AccountInfoNavigationController.self)
                                            if let accountInfoVC = accountInfoNavController.contentViewController as? AccountInfoViewController {
                                                accountInfoVC.account = currentAccount
                                            }
                                            self.present(accountInfoNavController, animated: true, completion: nil)
                                        //})


                                    case .failure(_):
                                        // Message KO
                                        //controller?.dismiss(animated: true, completion: {
                                            self.displayAlert(title: NSLocalizedString("creation_error_title", comment: "Error"),
                                                              message: NSLocalizedString("creation_error_msg", comment: "Something went wrong"))
                                        //})
                                    }
                                }

                            case .failure(let error):
                                print("Failed with error", error)
                                break;
                            }
                    }

                }.onSignUp { email, attributes in
                    print("New user with email \(email)!")
                }.onError { error in
                    print("Failed with error", error)
                }.present(from: self)
        }


        enum GetAccountResult {
            case success(Account)
            case failure(Error)
        }

        fileprivate func getCurrentAccount(_ completion: @escaping (GetAccountResult)-> Void) {
            // Get current account from token
            Server.getCurrentAccount { result in
                switch result {
                case .success(let jsonArray):
                    if let jsonDict = jsonArray.first,
                        let currentAccount = Account(dictionary: jsonDict) {

                        completion(.success(currentAccount))
                    }

                case .failure(let serverError):
                    print("Current account: Server error: \(serverError)")
                    completion(.failure(serverError as Error))
                }
            }

        }

0 个答案:

没有答案