I am trying to update login data from a firebase user using the Node admin sdk. My code looks like this:
var uid = req.body.uid
var objectUpdate = { "displayName": "David Coelho"};
admin.auth().updateUser(uid, objectUpdate)
.then (function (userRecord) {
//var id = userRecord.uid;
//usersRef.child(id).set(userDatabase (req, res))
res.status(200).json({ "return": "Success update user"})
})
.catch(function (error) {
res.status(500).json({ "return": error})
});
But I can not update the user. Firebase sends me the following error message:
"Code": "auth / internal-error",
"Message": "An internal error has occurred."
Can someone help me?
Related
I want to give write notification within an API request. I am able to write the notification, after that I am getting message saying "Notification" but, it's not showing in application
router.post('/api/v1/getAssetDetails', async(req, res)=>{ try { emitter.emit("saveNotification", "GENERAL", { "name": "Harshad", "description": "munna", "status": "Hello", "ephemeralTeamId": 1 }); let responseObject = setResponse(true, "Notification Sent Successfully", res.statusCode); res.status(200).send(responseObject); } catch (e) { console.log(e); res.status(500).send(setResponse(false, "Internal Server Error", res.statusCode)); } })
{ "status": true, "message": "Notification Sent Successfully", "code": 200, "data": null }
Getting in the local hit, but not in the application.
I am trying to make a monthly billing plan using node JS with stripe.
I get this error:
error when charged { Error: No such plan:
Here is my code:
const keyPublishable = "pk_test_DbEg2qVxduEZaIOl03AJAKX800fGtReb3c";
const keySecret = "XXX";
app.post("/charge", async (req, res) => {
try {
var customer = await stripe.customers.create({
email: req.body.stripeEmail,
source: req.body.stripeToken
})
await stripe.subscriptions.create({ // no point in awaiting here
plan: 'prod_EjuGPEbcrhczeA',
customer: customer.id
})
res.render("charge.pug")
In the logs of stripe I get :
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such plan: prod_EjuGPEbcrhczeA",
"param": "plan",
"type": "invalid_request_error"
}
}
I do not know what I am doing wrong.
Thank you
I suppose the id you are using is wrong. It's product id not plan id. What you need is to create a plan using the API: https://stripe.com/docs/api/plans/create.
Then use id of newly created plan to create subscription.
I've created a Azure Web App Bot and added a OAuth Connection Setting which takes the user to Salesforce. Everything works well, I'm able to authenticate the user through my bot and also, I can get the access token from Salesforce.
Problem
Can someone help me to get the user information from Salesforce? Because, I am able to get the access token alone and not sure, how to get the user id from Salesforce.
I've written the below code,
var salesforce = {};
salesforce.signin = (connector, session, callback) => {
builder.OAuthCard.create(connector,
session,
connectionName,
"Sign in to your Salesforce account",
"Sign in",
(createSignInErr, createSignInRes) => {
if (createSignInErr) {
callback({
status: 'failure',
data: createSignInErr.message
});
return;
}
callback({
status: 'success',
data: createSignInRes
});
});
};
salesforce.getUserToken = (connector, session, callback) => {
connector.getUserToken(session.message.address,
connectionName,
undefined,
(userTokenErr, userTokenResponse) => {
if (userTokenErr) {
callback({
status: 'failure',
data: userTokenErr.message
});
return;
}
callback({
status: 'success',
data: userTokenResponse
});
});
};
salesforce.accessToken = (connector, session, callback) => {
salesforce.getUserToken(connector, session, (userTokenResponse) => {
if (userTokenResponse.status == 'failure') {
// If the user token is failed, then trigger the sign in card to the user.
salesforce.signin(connector, session, (signinResponse) => {
// If the sign in is failed, then let the user know about it.
if (signinResponse.status == 'failure') {
session.send('Something went wrong, ', signinResponse.message);
return;
}
// If the sign in is success then get the user token and send it to the user.
salesforce.getUserToken(connector, session, (newUserTokenResponse) => {
if (newUserTokenResponse.status == 'failure') {
session.send('Something went wrong, ', newUserTokenResponse.message);
return;
}
callback(newUserTokenResponse);
return;
});
});
}
callback(userTokenResponse);
});
};
I can get the userTokenResponse here. But I need Salesforce user id so that I can start interacting with Salesforce behalf of the user.
If you have only OAuth access token you may query details about the user by invoking http GET against:
https://login.salesforce.com/services/oauth2/userinfo for PROD or
https://test.salesforce.com/services/oauth2/userinfo for sandbox
Add only Authorization: Bearer Y0UR0AUTHTOKEN to the header of the http GET request.
Based on my recent test the result returned from the server looks like:
{
"sub": "https://test.salesforce.com/id/[organizationid]/[userId]",
"user_id": "000",
"organization_id": "000",
"preferred_username": "me#mycompany.com",
"nickname": "myNick",
"name": "name lastname",
"urls": {
...
},
"active": true,
"user_type": "STANDARD",
...
}
You don't need a userId to get the user information where an accessToken is enough. I've installed jsforce and used the below code to get the identity information.
Solved by doing,
const jsforce = require('jsforce');
var connection = new jsforce.Connection({
instanceUrl: instanceUrl,
sessionId: accessToken
});
connection.identity((error, response) => {
if(error) {
callback({
status: 'failure',
message: error.message
});
return;
}
callback({
staus: 'success',
data: response
});
});
Im in the process of learning to use AWS Cognito. I have set up a userpool and a identity pool.
Code (simplified):
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: (result) => {
let cognitoGetUser = userPool.getCurrentUser();
if (cognitoGetUser != null) {
cognitoGetUser.getSession((err, result) => {
if (result) {
console.log ("Authenticated to Cognito User and Identity Pools!");
let token = result.getIdToken().getJwtToken();
let cognitoParams = {
IdentityPoolId: this.identityPool,
Logins: {}
};
cognitoParams.Logins["cognito-idp.eu-west-1.amazonaws.com/"+this.poolData.UserPoolId] = token;
AWS.config.credentials = new AWS.CognitoIdentityCredentials(cognitoParams);
AWS.config.getCredentials(() => {
console.log(AWS.config.credentials.accessKeyId)
console.log(AWS.config.credentials.secretAccessKey)
console.log(AWS.config.credentials.sessionToken)
}
}
}
}
},
onFailure: function(err) {
console.log('error');
console.log(err)
}
}
}
Most of the code works as expected: The authenticateUser fires the onSuccess and I can see a jwt token ect
Problem: I cant get the AWS.config.getCredentials to work. It executed without any errors, but accessKeyId, secretAccessKey and SessionToken are all undefined.
Any suggestions to what I'm doing wrong?
I cant get the AWS.config.getCredentials to work. It executed without any errors but,
This may be a mistaken assumption. Your abbreviated code is missing a couple of closing parentheses, but ran fine for me without any meaningful adjustments.
When calling getCredentials, any errors are "silently" reported through an error object. I would think you'd see a 400 response somewhere (network tab or console or both), but getCredentials() doesn't really report errors in a visible fashion by itself.
To see what is going wrong, you should add a parameter to the callback you pass to getCredentials():
AWS.config.getCredentials((err) => {
if (err) {
console.log(err);
} else {
console.log(AWS.config.credentials.accessKeyId)
console.log(AWS.config.credentials.secretAccessKey)
console.log(AWS.config.credentials.sessionToken)
}
});
For reference, one commonly encountered error object looks like this. Note that the useful message is found in originalError.message:
{
"message": "Could not load credentials from CognitoIdentityCredentials",
"code": "CredentialsError",
"time": "2018-06-03T15:19:02.078Z",
"requestId": "71b03b4a-6741-11e8-98af-b70a114474f8",
"statusCode": 400,
"retryable": false,
"retryDelay": 94.28032122526344,
"originalError": {
"message": "Invalid login token. Issuer doesn't match providerName",
"code": "NotAuthorizedException",
"time": "2018-06-03T15:19:02.078Z",
"requestId": "71b03b4a-6741-11e8-98af-b70a114474f8",
"statusCode": 400,
"retryable": false,
"retryDelay": 94.28032122526344
}
}
The corresponding 400 in the Network tab contains this response:
{"__type":"NotAuthorizedException","message":"Invalid login token. Issuer doesn't match providerName"}
I am having a node application and I need a few informations about a shopping cart from a magento customer. So I wrote myself a little test script to test the results of the soap api (I am using magento to help me communication with the soap interface).
var MagentoAPI = require('magento');
var magento = new MagentoAPI({
host: '192.168.73.45',
port: 80,
path: '/magento/api/xmlrpc/',
login: 'dev',
pass: '123456'
});
magento.login(function(err, sessId) {
if (err) {
console.log(err);
return;
}
magento.checkoutCart.info({ quoteId: 696 }, magentoCallback);
});
function magentoCallback(err,response) {
if (err) {
return console.log(err);
}
console.log("Result: ");
console.log(response)
}
This script works fine. If I use some old quote ids (which are in the database from the sample data) I get a good result, but if I use an shopping cart from an user I created, then I get the following error:
{
"original": {
"message": "Unknown XML-RPC tag 'BR'",
"name": "Error"
},
"name": "Magento Error",
"message": "An error occurred while calling cart.info"
}