I just finished up movie my app over to Parse Server. I've got everything working except for my Twitter Login and Signup. When I login or signup, I get an Internal Server Error message printed to my console. I am using the latest Parse SDK. Here is my login code (my signup code is similar, it just gets other data from the Twitter API and stores it to my database):
PFTwitterUtils.logInWithBlock {
(user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
spinningActivity.hideAnimated(true)
PFUser.currentUser()?.deleteInBackground()
self.displayNoticeWithTwoActions("Account Not Found", message: "This Twitter account is not in our system. You have to sign up first.", firstButtonTitle: "Sign Up", closeButtonTitle: "Ok", segue: "dontHaveAccountSegue")
} else if error != nil {
spinningActivity.hideAnimated(true)
self.displayError("Error", message: error!.localizedDescription)
} else {
spinningActivity.hideAnimated(true)
self.performSegueWithIdentifier("successfulLoginSegue", sender: self)
}
} else {
spinningActivity.hideAnimated(true)
self.displayError("Error", message: "Unless you tapped on 'Cancel' or 'Done', something went wrong. Please try again.")
}
}
The only thing I could find online is that it could be a problem on Twitter's end...I made sure my consumer key and secret were right in my AppDelegate. Any ideas?
To your index.js file that is your config file for Parse Server, you'll need to add this:
var api = new ParseServer ({
databaseURI: xxxxxxx,
cloud: xxxxxx,
appID: xxxxxx,
//more keys
//add oauth keys
oauth: {
facebook: {
appIds: xxxxxxxxxxxxx
},
twitter: {
appIds: xxxxxxxxxxxxx
}
}
})
Related
I incorporated Firebase's email verification for my iOS mobile app and am trying to resolve the following issues:
The length of the redirect url appears extremely long. It looks like it repeats itself.
https://app.page.link?link=https://app.firebaseapp.com//auth/action?apiKey%3XXX%26mode%3DverifyEmail%26oobCode%3XXX%26continueUrl%3Dhttps://www.app.com/?verifyemail%253Demail#gmail.com%26lang%3Den&ibi=com.app.app&ifl=https://app.firebaseapp.com//auth/action?apiKey%3XXX%26mode%3DverifyEmail%26oobCode%3XXX%26continueUrl%3Dhttps://www.app.com/?verifyemail%253Demail#gmail.com%26lang%3Den
When I set handleCodeInApp equal to true, and am redirected back to the app when I click on the redirect url, the user's email is not verified. Whereas when I set it to false and go through Firebase's provided web widget, it does get verified. Wasn't able to find documentation that outlined handling the former in swift...
Any thoughts are appreciated.
func sendActivationEmail(_ user: User) {
let actionCodeSettings = ActionCodeSettings.init()
let redirectUrl = String(format: "https://www.app.com/?verifyemail=%#", user.email!)
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.url = URL(string: redirectUrl)
actionCodeSettings.setIOSBundleID("com.app.app")
Auth.auth().currentUser?.sendEmailVerification(with: actionCodeSettings) { error in
guard error == nil else {
AlertController.showAlert(self, title: "Send Error", message: error!.localizedDescription)
return
}
}
}
Make sure you're verifying the oobCode that is part of the callback URL.
Auth.auth().applyActionCode(oobCode!, completion: { (err) in
if err == nil {
// reload the current user
}
})
Once you have done that, try reloading the the user's profile from the server after verifying the email.
Auth.auth().currentUser?.reload(completion: {
(error) in
if(Auth.auth().currentUser?.isEmailVerified)! {
print("email verified")
} else {
print("email NOT verified")
}
})
I'm trying to make User Authentication but I got the error:
Credential used before its being initialized
My code below:
if error._code == 17014 {
// required recent authentication
let credential: AuthCredential
user.reauthenticateAndRetrieveData(with: credential, completion: nil)
}
}else {
self.ShowAlert(title: "succeed", message: "mail Updated")
}
})
}
}))
You need to initialize the credential. If this is an email/password user, you should ask the user to provide the password. If this is an OAuth user, get a new OAuth credential. You would then initialize the Firebase AuthCredential with those and reauthenticate.
I am trying to develop a very simple chat application using quickblox and swift.
Knowing that there are few tutorials online that try to explain the process, I started with creating a user in the application dashboard and getting its credentials to initiate the connection. (I am certain that the user credential are correct and the dashboard is correctly set as I have followed this tutorial)
Here is the Application view controller:
import UIKit
import Quickblox
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let user = QBUUser()
user.id = 29777469
user.password = "tahrisqalli"
QBChat.instance().connect(with: user) { (error) in
if error != nil {
print("error: \(error)")
}
else {
print("login to chat succeeded")
}
}
}
}
and following is the error I get telling me that I did not connect successfully.
2017-07-11 11:33:50.837 QuickbloxTutorial[1045:24701] [ChatService] Connecting to Chat, host: chat.quickblox.com, user JID: 29777469-0#chat.quickblox.com/DCB0A1F4-3A56-49AD-9639-8C2A6BBE7B08
2017-07-11 11:33:52.042 QuickbloxTutorial[1045:24711] [ChatService] Stream isSecure: YES
2017-07-11 11:33:52.658 QuickbloxTutorial[1045:24722] [ChatService] Stream did connect, supportsStartTLS: YES
2017-07-11 11:33:52.824 QuickbloxTutorial[1045:24722] [ChatService] Did not authenticate, error: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
error: Optional(Error Domain=com.quickblox.chat Code=401 "<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>" UserInfo={NSLocalizedDescription=<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>})
2017-07-11 11:33:52.842 QuickbloxTutorial[1045:24722] [ChatService] Did disconnect
First of all, you have to log in with a user.
After this, You can connect with chat and it is best for you to use ServicesManager class that manage session automatically.
let loginUser = QBUUser()
loginUser.id = 29777469
loginUser.password = "tahrisqalli"
ServicesManager.instance().authService.logInWithUser(loginUser, completion: { (response, qbUser) in
if qbUser != nil {
ServicesManager.instance().chatService.connectWithCompletionBlock { (error) in
if error != nil {
print("user not connected error: ",error?.description)
} else {
//user connect successfully
}
}
print(qbUser)
} else {
print(response.error?.description)
}
})
I am writing app with Swift 3 on iOS 10. sharedInstance() method throws errors to console when user deny permissions to account from systems or account is not configured (e.g. "Unable to authenticate using the system account"). Errors are shows on console before enter to closure. I wont shows this errors to users in app e.g. on alert. This is my code:
Twitter.sharedInstance().logIn { (session, error) in
if error != nil {
// print(error?.localizedDescription ?? " ")
return
})
I get this error:
2016-11-29 14:49:09.023 CarReview[1254:31719] [TwitterKit] did encounter error with message "Unable to authenticate using the system account.": Error Domain=TWTRLogInErrorDomain Code=2 "User allowed permission to system accounts but there were none set up." UserInfo={NSLocalizedDescription=User allowed permission to system accounts but there were none set up.}
2016-11-29 14:49:09.024 CarReview[1254:31719] [TwitterKit] No matching scheme found.
2016-11-29 14:49:09.292 CarReview[1254:31719] [TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash>
" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash>
}
I want show users this: "Unable to authenticate using the system account. User allowed permission to system accounts but there were none set up."
I am facing the same issue as in the question.
I have just set the callBack Url into the Twitter App and resolved the issues.
Go to https://apps.twitter.com/app -> Settings -> Callback URL and Update Settings to save.
I'm not sure I understand what you want to do but you probably want to print the result on the main thread:
Twitter.sharedInstance().logIn{(session, error) in
DispatchQueue.main.async{
if error != nil {
print("Failed to login with Twitter / error:", error!.localizedDescription)
}else{
print("succeeded")
}
}
}
OK, I use this code to notify user about some error:
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {
if ACAccountStore().accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter).accessGranted {
Twitter.sharedInstance().logIn{
(session, error) in
if error != nil {
self.showAlert(title: "Twitter - Error", message: (error?.localizedDescription)!)
return
}
guard let token = session?.authToken else { return }
guard let secret = session?.authTokenSecret else { return }
let credential = FIRTwitterAuthProvider.credential(withToken: token, secret: secret)
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if error != nil {
self.showAlert(title: "Firebase (Twitter)", message: (error?.localizedDescription)!)
return
}
self.showAlert(title: "Firebase (Twitter)", message: "Logged to Firebase via Twitter.")
})
}
} else {
showAlert(title: "Twitter - Error", message: "Give access to the system Twitter account.")
}
} else {
showAlert(title: "Twitter - Error", message: "No system accounts set up.")
}
But it isn't what I want:/
You need to use withMethods and specify using the systemAccounts, not webBased or all to use the iOS Twitter settings. The following code is in Swift 3:
twitSharedInstance.logIn(withMethods: .systemAccounts) { (session :TWTRSession?, error :Error?) in
if (error != nil) {
if (session != nil) {
//We have logged into Twitter.
}
}
}
I'm trying to unlink email/password authentication from a user in Swift on iOS. I've read the documentation and managed to link and unlink Facebook authentication without a problem. However, after linking email/password credentials successfully, the providerData object is nil. The providerID is "Firebase" but when I pass that to the unlink code the following error is thrown:
Error Domain=FIRAuthErrorDomain Code=17016 "User was not linked to an account with the given provider." UserInfo={NSLocalizedDescription=User was not linked to an account with the given provider., error_name=ERROR_NO_SUCH_PROVIDER}
The unlink code I'm using is:
let providerId = (FIRAuth.auth()?.currentUser?.providerID)!
print("Trying to unlink:",providerId) // providerId = "Firebase"
FIRAuth.auth()?.currentUser?.unlinkFromProvider(providerId) { user, error in
if let error = error {
print("Unlink error:", error)
} else {
// Provider unlinked from account successfully
print("Unlinked...user.uid:", user!.uid, "Anonymous?:", user!.anonymous)
}
}
Reading the docs and having got it working for Facebook, I expected the providerData array to be populated with something after email authentication. So is my linking code wrong (it doesn't throw an error and appears to work fine)?
My linking code:
let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: password)
FIRAuth.auth()?.currentUser!.linkWithCredential(credential) { (user, error) in
if user != nil && error == nil {
// Success
self.success?(user: user!)
dispatch_async(dispatch_get_main_queue(), {
self.dismissViewControllerAnimated(true, completion: nil)
if type == "new" {
print("New user logged in...")
}
if type == "existing" {
print("Existing user logged in...")
}
})
} else {
print("Login error:",error)
self.showOKAlertWithTitle("Login Error", message: error!.localizedDescription)
}
}
Any pointers of how I can modify my approach would be great.
To get the profile information retrieved from the sign-in providers linked to a user, use the providerData property.
if let user = FIRAuth.auth()?.currentUser {
for profile in user.providerData {
// Id of the provider (ex: facebook.com)
let providerID = profile.providerID
}
} else {
// No user is signed in.
}
Calling FIRAuth.auth()?.currentUser?.providerID will result to "firebase".