Serverless Phone Verification with Twilio Verify and Twilio Functions error - javascript

I am trying to implement a project in Vuejs with this https://www.twilio.com/code-exchange/one-time-passcode-verification-otp. I deployed my functions through this.
I have a custom vuejs app that I’m using this in a form with.
Here is my front end function
verifyNumber() {
var auMobilePrefix = “+61”;
var m = this;
m.mobileNumber = ‘’;
m.mobileNumber = auMobilePrefix.concat(this.finalModel.mobile);
// console.log(m.mobileNumber);
const code = this.vcode;
const data = new URLSearchParams();
data.append(“to”, m.mobileNumber);
data.append(“verification_code”, code);
fetch(“https://verify-xxxx-xxxxx.twil.io/check-verify”, {
method: ‘POST’,
body: data
})
.then(response => response.json())
.then(json => {
if (json.success) {
console.log(json.message);
} else {
console.log(json.message);
}
})
.catch(err => {
console.log(err);
});
}
After I validate the code. I get the following error in console:
Verify-xxxx-xxxxx.twil.io/check-verify:1 Failed to load resource: the server responded with a status of 404 ()
MultiStepVerification.vue?280d:214 The requested resource /Services/VAxxxxxxx/VerificationCheck was not found
How do I resolve this issue?
Update
https://www.twilio.com/docs/verify/api/verification-check
This is actually the intended behaviour.
Twilio deletes the verification SID once it’s:
expired
approved
when the max attempts to check a code have been reached
Under the verification service logs I noticed that the Status for my tests were Approved.

Can you check the Twilio Helper Library version, to make sure it is current?
twilio-node changelog
You can manually add a Twilio helper library version to your Twilio Function NPM Dependencies to override the older version used by default, which is currently 3.29.2.
Displays Node Version and Twilio Helper Library Version

Related

request method showing 403 error in node js

app.post("/",function(req,res){
// console.log(req.body.crypto);
request("https://apiv2.bitcoinaverage.com/indices/global/ticker/all?crypto=BTC&fiat=USD,EUR",function(error,response,body){
console.error('error:', error);
console.log(response.statusCode);
});
From the documentation:
All requests to our API must be authenticated with your public key.
First register an account.
Then choose one of our plans from the plans page.
Finally get your public key from the main dashboard.
You're not passing any key in your request.
You are seeing that error with 403 (Forbidden) status code because the API you are trying to use requires an API key. You can see it in their API documentation.
What you should do is following the steps mentioned in API documentation and get a API key. Then you should to use this API key as x-ba-key header for your future requests like below:
I suggest you to use axious package to make your API calls since request module is deprecated and they will not support future issues and versions. Install axios package using npm install axios command and then import it to your application file. Then make a request to the endpoint with your API key like this:
const options = {
headers: { 'x-ba-key': 'yourAPIKey' }
};
axios.get('https://apiv2.bitcoinaverage.com/indices/global/ticker/all?crypto=BTC&fiat=USD,EUR', options)
.then((response) => {
console.log(response);
}, (error) => {
console.log(error);
});

Can I use the PaperCut (XML-RPC) API in Node.js?

I was going to use PaperCut API though as far as I can judge XML-RPC doesn't support Node.JS or I couldn't find an appropriate client for the purpose. Here's the link with PaperCut API:
https://www.papercut.com/support/resources/manuals/ng-mf/common/topics/tools-web-services.html
I was wondering who had been able to get it working in JavaScript. I'm using Node.js in QNAP (in Container Station). If it can be run in Python should I install Python container? Could I use a snippet of code in Python requesting it from Node.js?
I work for PaperCut Software
Sorry it took me so long to reply to this, but I eventually found a free afternoon to knock up some code.
var xmlrpc = require('xmlrpc')
const authToken = 'token'
const hostAddress = "172.24.96.1"
// Waits briefly to give the XML-RPC server time to start up and start
// listening
setTimeout(function () {
// Creates an XML-RPC client. Passes the host information on where to
// make the XML-RPC calls.
var client = xmlrpc.createClient({ host: hostAddress, port: 9191, path: '/rpc/api/xmlrpc'})
// Sends a method call to the PaperCut MF/NG server
client.methodCall(`api.${process.argv[2]}`, [authToken].concat(process.argv.slice(3)), function (error, value) {
// Results of the method response
if (undefined === error || null === error) {
console.log(`Method response for \'${process.argv[2]}\': ${value}`)
}
else
{
console.log(`Error response for \'${process.argv[2]}\': ${error}`)
}
})
}, 1000)
To run this from the command line try something like
node main.js getUserProperty alec balance

How to fix/find 'Bad Request' and 'Denied' authentication errors in react

I am working on a user registration page in my group project and came across a bad request error when submitting the data. I created a button to get users so I can check the authentication and it gave me a 401. "HTTP401: DENIED - The requested resource requires user authentication. (Fetch)GET - http://localhost:49967/Users" When I login, I use the admin login that's in the database and I see a token in my developers options. How do I find this error? I am new to react and programming so if you can lend some advice or docs it would be appreciated.
So to test my api endpoint, I loaded Postman and attempted to GET/POST and everything worked. I am using a react front-end, SQL sever for the database and ASP.Net Core in Visual Studios c#.
For starters here is the const I am using to access the back end
const apiHelper = {
get(url, params){
return fetch(`${baseUrl}${url}`, {
headers: this.headers
})
.then(response => response.json())
.catch(error => {
console.log(error);
return Promise.resolve();
});
}
This is the onclick action
handleGetUsers = async() => {
const response = await apiHelper.get('Users')
if(response){
console.log(response)
}
}
Lastly my URL
http://localhost:49967/

firebase googlesignin error in express js

this is the function which is called when user click a button from the html page.
this function is in auth.js which is called in server.js page
auth.js
const firebase = require("firebase");
static googleSignIn(req,res){
firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider()).
then( (result) => {
console.log(result.credential.idToken);
firebase.auth().currentUser.getIdToken(true).then( (token) => {
console.log(token);
});
}).catch((err) => {
console.log(err);
});
}
i get this error
code: 'auth/operation-not-supported-in-this-environment',
message:
'This operation is not supported in the environment this application is
running on. "location.protocol" must be http, https or chrome-extension and
web storage must be enabled
is there any way to send html request and get the token as response ,or any alternative way.please help
That error message is trying to tell you that Firebase Authentication client libraries don't work in a node.js environment. They're only supported for web browser clients.
Read more here.

How to handle backend errors from Node/Koa on frontend apollo-client

My frontend, using apollo-client, throws an exception when the backend returns an error after a request.
When the node server receives a request, I check the validity of the request's token using koa middleware. If the token is valid, the request is forwarded to the next middleware. If the token is invalid, I want to return a 401 access denied error to the client. To do this, I followed Koa's error documentation located here.
The code for the error handling middleware I wrote:
function userIdentifier() {
return async (ctx, next) => {
const token = ctx.request.headers.authorization
try {
const payload = checkToken(token)
ctx.user = {
id: payload.userId,
exp: payload.exp,
iat: payload.iat,
}
} catch (error) {
ctx.user = undefined
ctx.throw(401, "access_denied")
// throw new Error("access_denied")
}
await next()
}
}
This seemingly works on the backend, but not on the frontend. When the frontend receives this error, a JavaScript runtime error occurs. I am not sure what causes this.
Note, the unexpected "a" is the same "a" found in ctx.throw(401, "access_denied"). If it were instead ctx.throw(401, "x") the frontend shows "unexpected token x" instead.
The frontend code where the errors happens:
In an attempt to fix this, I followed Apollo's error handling documentation and used apollo-link-error.
const errorLink = onError(props => {
const { graphQLErrors, networkError } = props
console.log("ON ERROR", props)
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
)
if (networkError) console.log(`[Network error]: ${networkError}`)
})
Then I combine all links and create the Apollo client like this:
const link = ApolloLink.from([errorLink, authLink, httpLink])
export const client = new ApolloClient({
link,
cache: new InMemoryCache(),
})
The output of the debugging log in apollo-link-error is as follows:
Related Documents
Someone seems to be having an identical error, but a solution was not listed.
I found that the errors were handled correctly on the frontend when I began using this library on the backend: https://github.com/jeffijoe/koa-respond
Using just ctx.unauthenticated()
But I would still like to know more about how to return json/object-based errors with koa without a plugin helping

Categories