Есть ли решение для аутентификации с помощью auth0? - PullRequest
0 голосов
/ 30 октября 2019

Я работаю в swift 4.2

Код работал раньше, но я не знаю, как теперь он не будет работать. Итак, у меня есть эта authentification часть с auth0

У меня есть две проблемы:

1- Я не могу войти или зарегистрироваться через Facebook, ни через gmail, это странно, потому что неделю назадэто сработало, и это показывает мне эту ошибку.

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

Сбой с ошибкой canNotAuthenticate

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

2- Когда я захожу с почтой и паролем, он не будет входить в систему и покажет мне эту ошибку

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

callGetGeneric ответ: {"code": "invalid_token", "message": "неверная подпись"}{code = "invalid_token";сообщение = "неверная подпись";}

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

Я использую этот код:

 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))
                }
            }

        }
...