Login Error in Firebase for Nativescript - firebase

Hi i try to instance my password login in nativescript but send me this error:
JS: error con login por email Logging in the user failed. com.google.firebase.FirebaseException: An internal error has occurred. [ {
JS: "error":{
JS: "code": 400,
JS: "message": "USER_NOT_FOUND",
JS: "errors": [
JS: {
JS: "message": "USER_NOT_FOUND",
JS: "domain": "global",
JS: "reason": "invalid"
JS: }
JS: ]
JS: }
JS: } ]
here is my code:
constructor() {
firebase.login({
type: firebase.LoginType.PASSWORD,
passwordOptions: {
email: 'test#test.com',
password: 'test#test.com'
}
}).then((user)=>{
console.dir(user);
}, (error)=>{
console.log("error con login por email "+ error);
}
)
}
can you help me to find why gives me that error?
when I login anonymous doesn't have errors

check if you don't forget to enable email-password login in your firebase instance.
https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/AUTHENTICATION.md#email-password-login

Related

The forbidden error occurs, when I try to link an account to another user with an email

I have a user's refresh token with these scopes:
'https://www.googleapis.com/auth/analytics https://www.googleapis.com/auth/analytics.edit https://www.googleapis.com/auth/analytics.readonly https://www.googleapis.com/auth/analytics.manage.users’’
The user has a few accounts and a forbidden error occurs for XXXX2 account when I try to give access to an account to another user(you can see at the below code and account list json). I checked this account's effective permission field, I see that it is an empty array as you can see below as well.
In my opinion, this error reason is that this user does not have ‘manage_users’ permissions for this account(XXXX2), so this is an expected error, isn't it?
PS: I can link XXXX1 properly with the below code.
My code :
linkAccount = self.service.management().accountUserLinks().insert(
accountId=accountId,
body={
'permissions': {
'local': [
'EDIT',
'MANAGE_USERS'
]
},
'userRef': {
'email': email}}).execute()
User Account list :
{
"id": "XXXX1",
"kind": "analytics#account",
"selfLink": "https://www.googleapis.com/analytics/v3/management/accounts/XXXX1”,
"name": "XXXX1",
"permissions": {
"effective": [
"COLLABORATE",
"EDIT",
"MANAGE_USERS",
"READ_AND_ANALYZE"
]
},
"created": "2014-02-17T17:52:10.911Z",
"updated": "2019-06-04T16:06:12.717Z",
"childLink": {
"type": "analytics#webproperties",
"href": "https://www.googleapis.com/analytics/v3/management/accounts/XXXX1/webproperties"
}
},
{
"id": "XXXX2”,
"kind": "analytics#account",
"selfLink": "https://www.googleapis.com/analytics/v3/management/accounts/XXXX2”,
"name": "XXXX2",
"permissions": {
"effective": []
},
"created": "2015-07-02T19:11:16.307Z",
"updated": "2019-03-05T21:16:19.552Z",
"childLink": {
"type": "analytics#webproperties",
"href": "https://www.googleapis.com/analytics/v3/management/accounts/XXXX2/webproperties"
}
}
Error Code :
<HttpError 403 when requesting https://analytics.googleapis.com/analytics/v3/management/accounts/XXXXX/entityUserLinks?alt=json returned "User does not have permission to perform this operation.". Details: "User does not have permission to perform this operation."
I would check what access the currently authenticated user has to the account in question.
If the user you are authenticated with only has read access. To the Analytica account there not going to be able to give your application the ability to add another user.

Can't delete account from Firebase

I am creating a simple app using NativeScript where administrators can add and delete users from a a Firebase database. I am being able to add the users easily, but I can't seem to figure out how to delete them. I am following the instructions found in the documentation: https://firebase.google.com/docs/reference/rest/auth#section-delete-account
but when I submit the post request like this:
.post(https://identitytoolkit.googleapis.com/v1/accounts:delete?key=${FIREBASE_API_KEY},{ "idToken": userId }) .... (the rest of the code)
I get the following error:
This is the error I am getting:
JS: ERROR {
JS: "headers": {
JS: "normalizedNames": {},
JS: "lazyUpdate": null
JS: },
JS: "status": 400,
JS: "statusText": "Bad Request",
JS: "url": "https://identitytoolkit.googleapis.com/v1/accounts:delete?key=[MY_API]",
JS: "ok": false,
JS: "name": "HttpErrorResponse",
JS: "message": "Http failure response for https://identitytoolkit.googleapis.com/v1/accounts:delete?key=[MY_API]: 400 Bad Request",
JS: "error": {
JS: "error": {
JS: "code": 400,
JS: "message": "INVALID_ID_TOKEN",
JS: "errors": [
JS: {
JS: "message": "INVALID_ID_TOKEN",
JS: "domain": "global",
JS: "reason": "invalid"
JS: }
JS: ]
JS: }
JS: }
JS: }
I have tried all sorts of things, I have checked questions here, and nothing. Another user mentioned that the user I am trying to delete needs to have signed in before I delete it, but that did not work either. If any of you has any ideas on how to proceed I would appreciate it!
idToken is not the same as the userId, so the first thing you need to do is "log in" (use the SDK) as the user to retrieve his token and then use that token to delete the account.
I was able to do this using the methods described in this doc.

How to make meteor work with google apis?

please help me to make google apis and meteor work. So I set up accounts-ui accounts-password accounts-google. I took the needed scopes with my accounts-config.js
import { Accounts } from 'meteor/accounts-base'
Accounts.ui.config({requestPermissions: {
google: [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.compose',
'https://www.googleapis.com/auth/gmail.insert',
'https://www.googleapis.com/auth/gmail.labels',
'https://www.googleapis.com/auth/gmail.metadata',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/gmail.send',
'https://www.googleapis.com/auth/gmail.settings.basic',
'https://www.googleapis.com/auth/gmail.settings.sharing'
]
},
requestOfflineToken: {
google: true
}
})
On my server I have a method like this
import { Meteor } from 'meteor/meteor'
import { HTTP } from 'meteor/http'
Meteor.startup(() => {
// Meteor.call('createDraft')
Meteor.methods({
'createDraft': function () {
console.log(this.userId)
const user = Meteor.users.findOne(this.userId)
const email = user.services.google.email
console.log(email)
const dataObject = {
'message': {
'raw': CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse('Hello, World!'))
}
}
HTTP.post('https://www.googleapis.com/upload/gmail/v1/users/' + encodeURIComponent(email) + '/drafts', dataObject, (error, result) => {
if (error) {
console.log('err', error)
}
if (result) {
console.log('res', result)
}
})
}
})
})
On the client I have a component like this
import React, { Component } from 'react'
class Test extends Component {
createDraftClick () {
Meteor.call('createDraft', () => console.log('called createDraft'))
}
render () {
return (
<div className="btn btn-primary" onClick={this.createDraftClick.bind(this)}>Create Draft</div>
)
}
}
export default Test
When I click on it and my method is called I get the following response
err { [Error: failed [401] { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Login Required" } } ]
I20161219-17:02:07.904(4)? response:
I20161219-17:02:07.904(4)? { statusCode: 401,
I20161219-17:02:07.905(4)? content: '{\n "error": {\n "errors": [\n {\n "domain": "global",\n "reason": "required",\n "message": "Login Required",\n "locationType": "header",\n "location": "Authorization"\n }\n ],\n "code": 401,\n "message": "Login Required"\n }\n}\n',
I20161219-17:02:07.907(4)? headers:
I20161219-17:02:07.908(4)? { 'x-guploader-uploadid': 'AEnB2UrTNWqenpV_aT_KKab8HA71eHYdc3t8pjIzo6e_JyW4OWz3fIopa6hVpCmDK5nTM0VE8z3UOam8bSNKQNatKjLHHN_zNPFLQl_9eet8VNXO-3yNBYU',
I20161219-17:02:07.908(4)? vary: 'Origin, X-Origin',
I20161219-17:02:07.913(4)? 'www-authenticate': 'Bearer realm="https://accounts.google.com/"',
I20161219-17:02:07.914(4)? 'content-type': 'application/json; charset=UTF-8',
I20161219-17:02:07.914(4)? 'content-length': '238',
I20161219-17:02:07.916(4)? date: 'Mon, 19 Dec 2016 13:02:07 GMT',
I20161219-17:02:07.917(4)? server: 'UploadServer',
I20161219-17:02:07.917(4)? 'alt-svc': 'quic=":443"; ma=2592000; v="35,34"',
I20161219-17:02:07.917(4)? connection: 'close' },
I20161219-17:02:07.919(4)? data: { error: [Object] } } }
I20161219-17:02:07.926(4)? res { statusCode: 401,
I20161219-17:02:07.926(4)? content: '{\n "error": {\n "errors": [\n {\n "domain": "global",\n "reason": "required",\n "message": "Login Required",\n "locationType": "header",\n "location": "Authorization"\n }\n ],\n "code": 401,\n "message": "Login Required"\n }\n}\n',
I20161219-17:02:07.926(4)? headers:
I20161219-17:02:07.928(4)? { 'x-guploader-uploadid': 'AEnB2UrTNWqenpV_aT_KKab8HA71eHYdc3t8pjIzo6e_JyW4OWz3fIopa6hVpCmDK5nTM0VE8z3UOam8bSNKQNatKjLHHN_zNPFLQl_9eet8VNXO-3yNBYU',
I20161219-17:02:07.928(4)? vary: 'Origin, X-Origin',
I20161219-17:02:07.929(4)? 'www-authenticate': 'Bearer realm="https://accounts.google.com/"',
I20161219-17:02:07.930(4)? 'content-type': 'application/json; charset=UTF-8',
I20161219-17:02:07.931(4)? 'content-length': '238',
I20161219-17:02:07.931(4)? date: 'Mon, 19 Dec 2016 13:02:07 GMT',
I20161219-17:02:07.932(4)? server: 'UploadServer',
I20161219-17:02:07.933(4)? 'alt-svc': 'quic=":443"; ma=2592000; v="35,34"',
I20161219-17:02:07.933(4)? connection: 'close' },
I20161219-17:02:07.933(4)? data: { error: { errors: [Object], code: 401, message: 'Login Required' } } }
But I am signed in with my google account. Why am I getting this error?
I also tried to use atmosphere package GoogleApi but I get the same error. Please help dear sirs. Thank you in advance.

share on linkedin returns "Can not parse JSON share document"

I am trying to share a post on linkedin.
I managed to log in and get returned an id and an accessToken but when I follow the REST APIs way of sharing an update I keep getting:
Error: failed [400] {
"errorCode": 0,
"message": "Can not parse JSON share document.\nRequest body:\n\nError:\nnull",
"requestId": "NWGE7D4LSW",
"status": 400,
"timestamp": 1451699447711
}
My http POST looks like this:
HTTP.post('https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token=' + accessToken, {
'headers': {
'Content-Type': "application/json",
'x-li-format': "json"
},
'comment': "test!",
'visibility': {
'code': "anyone"
}
});
this worked:
HTTP.post('https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token=' + Meteor.user().services.linkedin.accessToken, {
headers: {
"Content-Type": "application/json",
"x-li-format": "json"
},
data: {
comment: "testing",
visibility: {
code: "anyone"
}
}
});

Login for DDP API in Chimp tests (Meteor)

I'm using Chimp to test my DDP API. As such, using the server object. What's a good way to do login?
Spying the DDP messages teaches me login looks like this:
{
"msg": "method",
"method": "login",
"params": [{
"user": {
"username": "myname"
},
"password": {
"digest": "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b",
"algorithm": "sha-256"
}
}],
"id":"1"
}
I could try to write my own logic to do this login, but I'd prefer a more elegant solution.
The following works:
function login(data) {
return Meteor.call('login', {
user: { username: data.username },
password: {
digest: Package.sha.SHA256(data.password),
algorithm: 'sha-256'
}
});
}
server.execute(login, { username: username, password: password });
To prevent disconnection problems, at the end of the test I do:
server.call('logout');

Resources