How to find callback function name from hcaptcha? - web-scraping

I'm trying to bypass hcaptcha without submit button.
So I need to know the callback name function but I can't find it in the source code of the page.
Any idea how to submit my request after received my token thx to a captcha resolver ?
Looks like it's possible for recaptcha : https://gist.github.com/2captcha/2ee70fa1130e756e1693a5d4be4d8c70
But can't find the same solution for hcaptcha.
Thx for the help.

This looks pretty straightforward actually:
$('form').submit()

It's what I did to validate the hcaptcha. But unfortunatly the captcha ask me again to fill it even if I send him a validate token
await page.$eval('textarea', (e, token) => {
e.value = token
}, token)
await page.waitForTimeout(1000 + randomTime()*3)
await page.evaluate(() => document.querySelector('form').submit())

Related

How to know if form is submitted without errors in puppeteer

I am trying to submit a form and I am testing for cases where the form won't submit due to invalid input. If the zip code I enter is valid, then this line of code will return null because there was no error message.
await self.page.waitForFunction(
'document.querySelector("#adr-zip-error")'
);
However I have to hard code a delay before this or set some kind of timeout to catch this error message.
I tried also checking if the form itself is null in the same way but again, it only works if I check after some amount of time as it takes time for the form to submit.
Is there a way to tell if a form is submitted successfully without using a hard coded delay?
This is not a general solution and is tailored to this problem. You could use waitForResponse
const response = await page.waitForResponse(response => response.url().startsWith("https://app.shipt.com/api/v1/customer_addresses"));
if (response.ok())
//success
or, you could just check input validity:
const invalid = await page.evaluate(() => document.querySelector('#adr-zip').getAttribute('aria-invalid') === "true");
After the submit you could do something like:
await Promise.race([
page.waitFor('#adr-zip-error'),
page.waitForNavigation()
])
and then
let error = await page.$('#adr-zip-error')
will let you know if the error happened first

How to determine whether it's a SignUp or SignIn in Passwordless Auth from Firebase? [duplicate]

My use case is that I want to ask newly signed up users to enrich basic info like their names.
So I was hoping to do it like:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
if (some indicator tells me it is newly signed up user)
{redirect to a form to fill in more info}
} else {
// No user is signed in.
}
});
I checked the doc, and could not find anything related to this...
Thanks for the help in advance.
Since version 4.6.0: https://firebase.google.com/support/release-notes/js#4.6.0
You can get if a user is new or existing in 2 ways:
If you are getting back a UserCredential result, check result.additionalUserInfo.isNewUser
Check firebase.auth().currentUser.metadata.creationTime === firebase.auth().currentUser.metadata.lastSignInTime
Previously you had to do that on your own and keep track of the user using Firebase Realtime Database. When a user signs in, you check if a user with the specified uid exists in the database or not. If the user was not found, it is a new user, you can then add the user to the database. If the user is already in the database then this is a returning existing user. Here is an example in iOS.
Handing Firebase + Facebook login process
Example for using result.additionalUserInfo.isNewUser:
firebase.auth().signInWithPopup(provider).then((result) => {
console.log(result.additionalUserInfo.isNewUser);
});
One thing you can do is do things in the callback function of the signup function, the signup function do return a promise. You can do something like this:
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function(user) {
//I believe the user variable here is the same as firebase.auth().currentUser
//take the user to some form you want them to fill
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
However, I don't really recommend doing it this way because the client side code can be unreliable. Think about what if a user suddenly disconnect before they can fill the form. Their data will be incomplete in your database. So if you do it this way, do set a flag in your user's profile when they submit the form so that you know who filled detailed information and who didn't.
Another better way to do this is using firebase cloud functions. You can have code like this in your cloud functions. Cloud functions are written in node.js so you don't need to spend time on another language.
exports.someoneSignedUp = functions.auth.user().onCreate(event => {
// you can send them a cloud function to lead them to the detail information form
//or you can send them an welcome email which will also lead them to where you want them to fill detailed information
});
This way is much better because you can safely assume that your cloud functions server will never be down or compromised. For more information about cloud functions you can refer to their doc: https://firebase.google.com/docs/functions/auth-events
You can check the sign-in methods the user has (if any). If there are none, it is a new user.
// Fetch sign in methods (if any)
Auth.auth().fetchSignInMethods(forEmail: userEmail!) { [self] signInMethodsArray, error in
// Check for error and alert user accordingly
if let error = error {
// handle errors
}
// Email accepted.
// Check if new or returning user.
else {
if (signInMethodsArray == nil) {
// New User
}
else {
// Returning User
}
}
}
This is Swift (iOS) code, but the concept is the same across languages.

How to allow Flutter to get a value that it stored in a firebase server or any server?

Right now I am using an http 0.11.3+16 and I am able to add a true value to an item on the site using the following function:
if (newAcceptStatus) {
response = await http.put('https://example.com/example1/${selectedOrder.id}/example2/${_authenticatedUser.id}.json?auth=${_authenticatedUser.token}',
body: json.encode(true));
this function is only called when the admin is logged in and the admin is the only one that can change the status of the Boolean, so the value is stored under the admins id and token. so I tried the following to help show if the item was changed by the admin to the user but i keep getting that the value is null when i decode the response with the following function:
Future<Null> checkAccept() async{
http.Response response;
response = await http.get('https://example.com/example1/${selectedOrder.id}/example2/(admin id goes here).json?auth=${_authenticatedUser.token}');
accepted = json.decode(response.body);
}
not sure what i am doing wrong. any help would be appreciated!
I was calling the wrong list of items which were very similar, thus giving me an empty list

Firebase Auth, how to know new user signed up, rather than existing user sign in?

My use case is that I want to ask newly signed up users to enrich basic info like their names.
So I was hoping to do it like:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
if (some indicator tells me it is newly signed up user)
{redirect to a form to fill in more info}
} else {
// No user is signed in.
}
});
I checked the doc, and could not find anything related to this...
Thanks for the help in advance.
Since version 4.6.0: https://firebase.google.com/support/release-notes/js#4.6.0
You can get if a user is new or existing in 2 ways:
If you are getting back a UserCredential result, check result.additionalUserInfo.isNewUser
Check firebase.auth().currentUser.metadata.creationTime === firebase.auth().currentUser.metadata.lastSignInTime
Previously you had to do that on your own and keep track of the user using Firebase Realtime Database. When a user signs in, you check if a user with the specified uid exists in the database or not. If the user was not found, it is a new user, you can then add the user to the database. If the user is already in the database then this is a returning existing user. Here is an example in iOS.
Handing Firebase + Facebook login process
Example for using result.additionalUserInfo.isNewUser:
firebase.auth().signInWithPopup(provider).then((result) => {
console.log(result.additionalUserInfo.isNewUser);
});
One thing you can do is do things in the callback function of the signup function, the signup function do return a promise. You can do something like this:
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function(user) {
//I believe the user variable here is the same as firebase.auth().currentUser
//take the user to some form you want them to fill
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
However, I don't really recommend doing it this way because the client side code can be unreliable. Think about what if a user suddenly disconnect before they can fill the form. Their data will be incomplete in your database. So if you do it this way, do set a flag in your user's profile when they submit the form so that you know who filled detailed information and who didn't.
Another better way to do this is using firebase cloud functions. You can have code like this in your cloud functions. Cloud functions are written in node.js so you don't need to spend time on another language.
exports.someoneSignedUp = functions.auth.user().onCreate(event => {
// you can send them a cloud function to lead them to the detail information form
//or you can send them an welcome email which will also lead them to where you want them to fill detailed information
});
This way is much better because you can safely assume that your cloud functions server will never be down or compromised. For more information about cloud functions you can refer to their doc: https://firebase.google.com/docs/functions/auth-events
You can check the sign-in methods the user has (if any). If there are none, it is a new user.
// Fetch sign in methods (if any)
Auth.auth().fetchSignInMethods(forEmail: userEmail!) { [self] signInMethodsArray, error in
// Check for error and alert user accordingly
if let error = error {
// handle errors
}
// Email accepted.
// Check if new or returning user.
else {
if (signInMethodsArray == nil) {
// New User
}
else {
// Returning User
}
}
}
This is Swift (iOS) code, but the concept is the same across languages.

Accounts.onLogout - what user logged out?

I'm excited about the addition of the Accounts.onLogout() server side hook: http://docs.meteor.com/api/accounts-multi.html#AccountsCommon-onLogout
However I can't seem to find a way to access the user who is logging out. The PR says the onLogout hook is directly analogous to the onLogin, but I can't find the user anywhere.
Accounts.onLogout(function(user) {
console.log("onLogout:", user);
console.log(Meteor.user());
console.log(this._userId);
console.log(this.connection);
});
outputs undefined for everything.
How can I know which user is logging out?
As you already found out, there doesn't seem to be a way to directly access the logged out user from within the callback since this is undefined and no arguments are given to the callback.
To solve the issue I suggest you create a custom method that takes an argument: the user ID. You can simply call that method from the client code just before calling Meteor.logout(). Inside the method you then have access to the user ID and can lookup the user from the Database and perform whatever action you want.
Example
// On the server
Meteor.methods({
preLogoutHook: function (userId) {
check(userId, String);
// .. do stuff ..
}
});
// On the client, probably in an event handler of a logout button
Meteor.call('preLogoutHook', Meteor.userId(), (error, result) => {
if (error) console.log(error);
});
Meteor.logout();
seems like no way to do this using onLogout function as of now,
I would not recommending tracking logout in Client code - hard to maintain this code.
Have you tried this package: Event-Hooks(https://atmospherejs.com/differential/event-hooks)?
Hooks.onLoggedOut = function (userId) { ... } ( anywhere ) - Provide a callback to run when a user has logged out

Resources