CognitoClientException{statusCode: null, code: NetworkError, name: null, message: Failed host lookup: 'cognito-idp.us-east-1.amazonaws.com'} - flutter

Im using flutter with the Amazo Cognito Identiy Dart Plugin
I am new to AWS and followed the sample code provided on the plugin's github page to create a new user but I keep getting the following error message:
CognitoClientException{statusCode: null, code: NetworkError, name: null, message: Failed host lookup: 'cognito-idp.us-east-1.amazonaws.com'}
I have read through a good chunck of the complete sample app and can't seem to find what I am overlooking. I thought that maybe I needed to include the android permission for internet (although the documentation didn't mention it); however I still got the same error code.
Below is the code for the method to sign up a new user. The variables cognitoUserPoolId and cognitoClientId are from a secret.dart file, and reference my user pool. The user pool allows users to sign up with a name, email address, and password. Besides that it uses the default settings.
final userPool = new CognitoUserPool(cognitoUserPoolId, cognitoClientId);
signUpUser(String name, String email, String password) async {
final userAttributes = [
new AttributeArg(name: 'name', value: name),
];
var data;
try {
print('attempting to sign user up');
data = await userPool.signUp(email, password, userAttributes: userAttributes);
} catch (e) {
print(e);
}
}
Edit: turns out what I was reading was the source code of the plugin, and not the example app. According to the example it seems that the uses-internet permission is actually required. Unfortunately as I stated earlier adding it did not fix the problem.

Update: I have found the solution. It turns out the emulator I was runnning was having issues connecting to the network. Stack Overflow question detailing how to fix that issue
I simply used a physical device and all seems to be working great!

Related

"Invalid API Key provided" using the stripe extension in firebase cloud functions

having a problem that when I try to run my cloud function where my secret key is being perceived as invalid. I am 99.99% sure that it is the same as is in the Stripe dashboard and have copied and pasted 100 times so I think it is something else.
{success: false, error: Invalid API Key provided: sk_test_**********************************************************************************************************************************************************************************************************}
If anyone could help that would be fantastic.
Can you double check if there's any extra empty space characters being added to the API key that you specified in the cloud function? Or if you are reading the API key from a config file, try hardcode it directly to the code and see if it solves the problem.
Initial thoughts...
Ensure you have setup a restricted key with the specified security.
Could this be an issue with the secret manager, invalidating your key here and reconfiguring https://console.cloud.google.com/security/secret-manager?referrer=search&project={your-project-id} may fix the issue.
If you install a new instance, do you still have the same issue?
If you can run locally, does the key work ok in small nodejs project for example, depending on which extension you are using:
import Stripe from 'stripe';
// invoices extension: apiVersion: '2020-03-02',
// payments extension: apiVersion = '2020-08-27';
const stripe = new Stripe('sk_test_...', {
apiVersion: '2022-11-15',
});
const createCustomer = async () => {
const params: Stripe.CustomerCreateParams = {
description: 'test customer',
};
const customer: Stripe.Customer = await stripe.customers.create(params);
console.log(customer.id);
};
createCustomer();

How to get the coordinates from the address using google map

I'm trying to get the coordinates from the address which user input,using flutter_google_places but here is gives me error
{candidates: [], error_message: You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account, status: REQUEST_DENIED}
here is my code
static Future<String> getPlaceId(String input) async {
final String url =
"https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=$input&inputtype=textquery&key$googleApiKey";
var response = await http.get(Uri.parse(url));
Map<String, dynamic> json = jsonDecode(response.body);
print(json);
var placeId = json['candidates'][0]['place_id'] as String;
return placeId;
}
i added the key too, but it gives me this error, please help how to do this or this is there any other to get the coordinates from user input address.
There are a few steps you have to make sure you complete. First, make sure your API key is not restricted for your device. You can either set the key to restrict none or just add your authentic key to the API key. And get the access.
Also basic stuff. Make sure all the needed SDK's are activated for your project. And It would be better if you can provide some more data. That would be kinda helpful. Also don't forget to add your api key to the xml file inside your android project. if you're doing it for android.
(BTW the issue is with your credentials. First solve that. Then you can find the way to get the coordinates. It's pretty easy. You're already there.)

How to solve the {code: UNAUTHENTICATED, details: null, message: UNAUTHENTICATED}) error using Google Cloud Functions?

I am currently facing the above mentioned error when using the cloud_functions dependency on my Flutter app. My function https call is as follows:
final HttpsCallable callable = CloudFunctions(region: "region name").getHttpsCallable(functionName: 'function-name')..timeout = const Duration(seconds:30);
And my function invocation within the code is as given below:
onPressed: () async {
try {
dynamic resp = await callable.call(<String, dynamic>{
'message':'hello!',
'url': urlController.text,
});
setState(() {
imgurl = resp.data['image'];
time = resp.data['timestamp'];
});
I have added the ID I am using for authentication to my function via the console IAM. Unfortunately, I still keep receiving the following error:
PlatformException(functionsError, Cloud function failed with exception., {code: UNAUTHENTICATED, details: null, message: UNAUTHENTICATED})
How can I resolve that?
Thanks for your help in advance.
If you have deployed your function in "private mode", I mean, allow only authenticated user, you have to add a valid identity_token in the header of your request.
You have an example here, mostly on end user because it's your use case. Don't use a service account key file because your flutter app is public and you will share your secret publicly.
You can also use Cloud Endpoint with Firebase authentication mode. I wrote an article for setting up an authentication with API key. Simply update the authentication mode and it will works.

Why doesn't Accounts.createUser create a user in MongoDB?

I'm using accounts-password package to manage my user accounts. I tried 2 ways to create account using Accounts.createUser() function.
1st way: Calling Accounts.createUser() from the client
register.js:
Template.register.events({
"submit form"(event){
event.preventDefault();
const email = event.target.email.value;
const password = event.target.password.value;
Accounts.createUser({
email: email,
password: password
});
}
});
2nd way: Calling Accounts.createUser() from the server method and calling that method from the client. Got the hint after going through: Meteor: Accounts.createUser() doesn't create user
register.js:
Template.register.events({
"submit form"(event){
event.preventDefault();
const email = event.target.email.value;
const password = event.target.password.value;
Meteor.call('createNewUser', email, password);
}
});
methods.js:(on server)
Meteor.methods({
'createNewUser'(email, password){
Accounts.createUser({
email: email,
password: password
});
}
});
In both the cases, no new collection is created in MongoDB. Neither is any old collection updated. My connection strings are proper. Why is this happening?
However, when I use the following on the server, a document is created:
Accounts.users = new Mongo.Collection("profiles", {
_preventAutopublish: true, _driver: dbConn
});
Meteor.users = Accounts.users;
I don't know why a new collection has to be created for this to work. Isn't accounts-password package supposed to create a collection by itself?
if you are just keen on getting a basic version up and running try adding the default {{>loginButtons}} to your html. This will also make sure the javascript is executed as it should be. Building the js manually only makes sense if you need more customizability.
Have you added the accounts-base package? Accounts.createUser comes from this package. (docs)
In the linked example you gave, the OP had set forbidClientAccountCreation: true in the Accounts.config(). That prevents the Accounts.createUser function from working on the client (which is useful in applications where users need an invitation to register). That is why the answers recommended to create the user account server side and isn't applicable to your application.
As a side note, in your second example you are passing an unencrypted password from the client to the server which is considered dangerous.
You can encrypt it before sending it to the server method like so:
const password = Accounts._hashPassword( event.target.password.value );
_driver: dbConn
That line is really concerning. Are you trying to manage your own database connection?
There's nothing wrong with the code you wrote, it's not your problem. Accounts.createUser is the correct method to call.
If you need to use a different database than the one initialized by default by running the meteor command from terminal, look at the documentation on using MONGO_URL.

passport.socketio's passport "Failed to deserialize user out of session". But passport in my main app (with the same key) deserializes just fine

passport.socketio throwing this error, while failing to authorize the user.
Error: Error: Failed to deserialize user out of session
I've narrowed the problem down to passport.socketio's /lib/index.js.
At line 59
auth.passport.deserializeUser(userKey, function(err, user) {
if (err)
return auth.fail(data, err, true, accept);
...
It throws that error. Debugger tells me the userKey is valid, and should deserialize the user. It's the same key that passport in my main app uses to deserialize the user. (it's the ID of mongoDB object). And passport in my main app has no problem deserializing the user. (details)
So don't know why this still throws the error.
The userKey passed here is the same key passport in my main app uses to deserialize.
I've gone to the extent of making the userKey global and putting it in my main code
passport.deserializeUser(global.userKey, function(err, user) {
if (err)
return auth.fail(data, err, true, accept);
console.log('ok');
Which results in infinite loop (because it's inside outer passport.deserialize) but iut prints 'ok'!, so passport from my main app can atleast deserialize just fine using the same thing that passport from index.js (passport.socketio\lib\index.js) can not! .. for some reason.
Then I've even tried passing the passport object itself from main app
io.set('authorization', require('passport.socketio').authorize({
passport: passport,
...
which actually results in no errors!! but then I don't get the socket.handshake object.
I'm out of ideas to diagnose this any further and would really appreciate any help whatsoever.
What could be causing passport.socketio's passport to not "deserialize user out of session"?
Deleted npm_modules, re-wrote the packages.json with "every_package":"latest", and so basically re-installed every package's latest version. That fixed it.
One problem could be that you have configured your 'passport' instance in the main app to use a specific 'deserializeUser' implementation. look for all the places where your passport has been intiallized in the main app. (If its a framework like mean.io, you will find it in config/passport.js).
Make sure the same initiallization is done to the passport instance in the socket app. Pass it to passportsocketio as such:
passportSocketIo.authorize({
passport: passport,
cookieParser: express.cookieParser,
key: 'connect.sid'
...
});