Firebase customtoken incorrect - ios

Building and ios chat application. Started testing generated a token but when it is passed as customtoken ios throwing error.
FIRAuth.auth()?.signIn(withCustomToken: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyeHAiOjE0ODM4NzEyOTAsInYiOjAsImQiOnsidWlkIjoiNTg0MTVhM2ZkOTA1MGVjZjAzOGI0NWU3In0sImlhdCI6MTQ4MTI3OTI5MH0.QIxFmbap_cDsUB5L_OxE29haev7cSe29lHZtmVTnJ3c") { (user, error) in
if let error = error {
print(error.localizedDescription)
return
}
self.signedIn(user!)
}
The custom token format is incorrect. Please check the documentation.
where as when i test the same token online its working fine.
http://jsfiddle.net/firebase/XDXu5/
Any help will be very helpfull.

Related

Error on refreshing auth token in Firebase iOS

I'm trying to refresh my auth token in Firebase using swift as follows
let currentUser = Auth.auth().currentUser
currentUser?.getIDTokenForcingRefresh(true) { idToken, error in
if error != nil {
return;
}
self.userDataManager.fetchUser()
}
It's hitting the error return statement with,
message = "Requests to this API securetoken.googleapis.com method google.identity.securetoken.v1.SecureToken.GrantToken are blocked.";
status = "PERMISSION_DENIED";
I search around the docs, But couldn't find a proper solution for this. Please help with this.
I had the same error but with the Web APIs. Solved it by
Going to https://console.developers.google.com/apis/credentials,
Clicking on the API key
Enabling the "Token Service API", along with "Identity Toolkit API"

Swift Gmail API: Try to send message gives error -1001

I'm trying to send a gmail message in Swift using the GoogleAPIClientForREST and GTMOAuth2 libraries but I'm getting the aforementioned error.
Here's my code:
let message = GTLRGmail_Message()
message.raw = "test"
let query = GTLRGmailQuery_UsersMessagesSend.query(withObject: message, userId: "example#gmail.com", uploadParameters: nil)
let gmailService = GTLRGmailService()
let auth = GTMOAuth2Authentication()
auth.clientID = gmailClientID
gmailService.authorizer = auth
gmailService.executeQuery(query) { ticket, object, error in
print(ticket)
print(object)
print(error)
}
and here's the error:
Optional(Error Domain=com.google.GTMOAuth2 Code=-1001 "(null)" UserInfo={request=<NSMutableURLRequest: 0x600000016ed0> { URL: https://www.googleapis.com/gmail/v1/users/example%40gmail.com/messages/send?prettyPrint=false }})
Notes:
I used "example#gmail.com" for sake of asking the question, I'm using a real email in my app.
I followed all the basic steps in Google's tutorial
Make sure that you've integrated GTMOAuth2 properly into your app by following this tutorial. Be sure to register the Platform as Other and NOT iOS otherwise you'll get "invalid_client" error when authenticating.
You may also check the given solution on this thread.

Google Places Api Error in Swift 3

Google Places Api
I am implementing google place api in my project. I have implemented everything but google Api returns the following error:
Current Place error: The operation couldn’t be completed. An internal
error occurred in the Places API library. If you believe this error
represents a bug, please file a report using the instructions on our
community and support page
(https://developers.google.com/places/support).
It was working earlier but suddenly it stops. I found nothing in any other answer that could be helpful for me.
This my code to call the Api:
GMSPlacesClient().currentPlace(callback: {
(placeLikelihoods, error) -> Void in
guard error == nil else {
print("Current Place error: \(error!.localizedDescription)")
return
}
})
Any Help would be appreciated!!
Make sure that you have given place_id instead of id.
This solved my issue
According to the GMSPlacesClient reference (https://developers.google.com/places/ios-api/reference/interface_g_m_s_places_client) you should be accessing the shared instance of the client, so in Swift 3 your code above should be
GMSPlacesClient.shared().currentPlace(callback: {
(placeLikelihoods, error) -> Void in
guard error == nil else {
print("Current Place error: \(error!.localizedDescription)")
return
}
})

Linking oAuth Providers in Firebase iOS

I'm new to Firebase and iOS and I was wondering if someone knew how to link multiple oAuth Providers. I followed the Firebase docs and tried to implement this function:
func firebaseSignInWithLink(credential: FIRAuthCredential) {
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if error != nil {
debugPrint("APP: there has been an error signing into firebase, perhaps another account with same email")
debugPrint("APP: \(error)")
// if existing email, try linking
FIRAuth.auth()?.currentUser?.link(with: credential, completion: { (user, error) in
if error != nil {
debugPrint("APP: there has been an error signing into firebase")
debugPrint("APP: \(error)")
}
else {
debugPrint("APP: successfully signed into firebase")
}
})
}
else {
debugPrint("APP: successfully signed into firebase")
}
})
}
The FIRAuth.auth()?.currentUser?.link function never gets called despite the above debugPrint("APP: \(error)") being called. Because this doesn't work, I keep getting the error below:
Optional(Error Domain=FIRAuthErrorDomain Code=17007 \"The email address is already in use by another account.\" UserInfo={NSLocalizedDescription=The email address is already in use by another account., error_name=ERROR_EMAIL_ALREADY_IN_USE, FIRAuthErrorUserInfoEmailKey=example#gmail.com})"
Any help would be greatly appreciated! Thank you :D
I believe you are confused by the instructions. On firebase documentation it reads
To link auth provider credentials to an existing user account:
Sign in the user using any authentication provider or method.
Complete the sign-in flow for the new authentication provider up to, but not including, calling one of the FIRAuth.signInWith methods. For example, get the user's Google ID token, Facebook access token, or email and password.
Get a FIRAuthCredential for the new authentication provider
So you should not call the method FIRAuth.signInWith. I should also point out that you want to create a link to an existing account, so you should have signed in first and then you can link it. This is why you should have a currentUser.
It occurred because of unchecking "Multiple accounts per email address setting firebase setting" from firebase console.

Error adding Firebase users Swift

By following the information on this link, I am currently working on trying to create a user using Firebase, as shown in the code below. However, it appears no user is created when the app is run. Any input is greatly appreciated. The Firebase URL was taken from my test database.
let ref = Firebase(url: "https://test-96df2.firebaseio.com")
ref.createUser("bobtony#example.com", password: "correcthorsebatterystaple",
withValueCompletionBlock: { error, result in
if error != nil {
// There was an error creating the account
print("error creating account")
} else {
let uid = result["uid"] as? String
print("Successfully created user account with uid: \(uid)")
}
})
Edit:
The propagated error is:
Error Code: AUTHENTICATION_DISABLED) Projects created at
console.firebase.google.com must use the new Firebase Authentication
SDKs available from firebase.google.com/docs/auth/
However, as shown below, the email/password authentication is enabled in the Firebase console.
You have already authorized the email registration as I can see in your screenshot. So the problem doesnt realies on AUTHENTICATION_DISABLED.
From your error message and the snippet code I can see that you have created a new project but you are trying to use the legacy firebase SDK and so you will have compatibility issues. Also, you are looking into the old firebase documentation.
First of all you will need to make sure you have configured your project as documented in new firebase start guide.
After, you can take a look at the documentation for creating a new user with the new sdk. You can find the 3.x create user call bellow.
FIRAuth.auth()?.createUserWithEmail(email, password: password) { (user, error) in
// ...
}

Resources