SSH key not working with meteor-up and Digital Ocean - digital-ocean

I'm using meteor-up and Digital Ocean. If I use the username and password for authentication it works fine. However when I try to use my SSH keys it gives an error, mup setup returns All configured authentication methods failed
Here is my mup.js file (I've changed my IP, password and username for security):
module.exports = {
servers: {
one: {
// TODO: set host address, username, and authentication method
host: '139.49.141.100',
username: 'root',
pem: '/Users/MYUSERNAME/.ssh/id_rsa',
// pem: '~/.ssh/id_rsa',
// password: 'MY-PASSWORD',
// or neither for authenticate from ssh-agent
},
},
app: {
// TODO: change app name and path
name: 'nomad',
path: '../',
servers: {
one: {},
},
buildOptions: {
serverOnly: true,
},
env: {
// TODO: Change to your app's url
// If you are using ssl, it needs to start with https://
ROOT_URL: 'http://139.49.141.100',
MONGO_URL: 'mongodb://localhost/meteor',
},
// ssl: { // (optional)
// // Enables let's encrypt (optional)
// autogenerate: {
// email: 'email.address#domain.com',
// // comma separated list of domains
// domains: 'website.com,www.website.com'
// }
// },
docker: {
// change to 'abernix/meteord:base' if your app is using Meteor 1.4 - 1.5
image: 'abernix/meteord:node-8.4.0-base',
},
// Show progress bar while uploading bundle to server
// You might need to disable it on CI servers
enableUploadProgressBar: true,
},
mongo: {
version: '3.4.1',
servers: {
one: {},
},
},
};
I've added the public part of my SSH key at https://cloud.digitalocean.com/settings/security
I've also tried generating a new SSH key but I get the same result.
In my terminal if I go to /Users/MYUSERNAME/.ssh/ or ~/.ssh/ I can see that id_rsa, id_rsa.pub, id_rsa_2 and id_rsa_2.pub are all there.

Adding an SSH key to your account isn't enough, you also need to add it to the bucket.
I followed the instructions here:
https://www.digitalocean.com/community/questions/add-ssh-key-after-creating-a-droplet
Running this command from my local machine moved over the keys:
cat ~/.ssh/id_rsa.pub | ssh root#your.ip.address "cat >> ~/.ssh/authorized_keys"
Thanks Oliver for figuring this out (see the comment under my original question)

Related

Error: Amplify has not been configured correctly - VueJS/NuxtJs - Reconfigure Amplify

I'm trying to setup SignInWithApple on my webpage. Currently there is the basic auth and the google auth. Because of some required fields in my current user pool which not work together with apple, I created a second user pool. Now I am trying to make both of them work by switching the configuration.
manual config (not using the cli for the aws-exports)
export default () => {
return {
default: {
region: process.env.AWS_COGNITO_REGION,
userPoolId: process.env.AWS_COGNITO_USER_POOL_ID_DEFAULT,
userPoolWebClientId: process.env.AWS_COGNITO_APP_CLIENT_ID_DEFAULT,
mandatorySignIn: false,
oauth: {
domain: process.env.AWS_COGNITO_DOMAIN_DEFAULT,
scope: [
'profile',
'phone',
'openid',
'email',
'aws.cognito.signin.user.admin'
],
redirectSignIn: process.env.AWS_COGNITO_REDIRECT_SIGN_IN,
redirectSignOut: process.env.AWS_COGNITO_REDIRECT_SIGN_OUT,
responseType: 'code'
}
},
SignInWithApple: {
region: process.env.AWS_COGNITO_REGION,
userPoolId: process.env.AWS_COGNITO_USER_POOL_ID_APPLE,
userPoolWebClientId: process.env.AWS_COGNITO_APP_CLIENT_ID_APPLE,
mandatorySignIn: false,
oauth: {
domain: process.env.AWS_COGNITO_DOMAIN_APPLE,
scope: ['openid'],
redirectSignIn: process.env.AWS_COGNITO_REDIRECT_SIGN_IN,
redirectSignOut: process.env.AWS_COGNITO_REDIRECT_SIGN_OUT,
responseType: 'code'
}
}
}
}
And then I have a vue component with a Google and Apple login button, triggering the same function but passing either "Google" or "SignInWithApple".
import Amplify, { Auth } from 'aws-amplify'
import amplifyResources from '#/plugins/amplifyResources'
export default {
data() {
return {
bucket: null
}
},
methods: {
federatedAuth(provider) {
if ('SignInWithApple' === provider)
this.bucket = amplifyResources().SignInWithApple
if ('Google' === provider)
this.bucket = amplifyResources().default
Amplify.configure(this.bucket) **RECONFIGURE OF AMPLIFY CONFIG **
Auth.federatedSignIn({ provider })
}
}
}
And I am getting the following error:
34:03.80 AuthError -
Error: Amplify has not been configured correctly.
The configuration object is missing required auth properties.
So the funny thing is, if I init the "default" or "apple" config as a plugin, which I link and load in my nuxt.config.js file, the authentication works. The users are getting registered and logged in. With google on the default user pool auth or with apple at the new user pool. Both work then.
But I am trying to switch the userpool in some component directly, based on the auth method the user is choosing. There I am "reconfiguring" the amplify config with Amplify.configure(this.bucket). From that point I am getting the error message from above. But the config is indeed switching. Otherwise I wouldn't get redirected to apple on the apple button or to google on the google button. Both have completely different configs. So I know the "reconfiguration" is happening. I also know that in general I have the right properties in the default & apple config, since the login for both is working, if I set the config as a plugin in the nuxt.config.js file.

Contract has not been deployed to detected network (network/artifact mismatch)

I'm having some issues determining and connecting with the right MetaMask network.
In Ganache, my RPC server is 127.0.0.1.7545 and the network id is 5777. However, when I try to create a custom RPC in MetaMask with this info, I get the following error:
The endpoint returned a different chain ID: 1337
This is my truffle-config.js:
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*" // Match any network id
},
develop: {
port: 8545
}
}
};
I'm hoping this would match any network id as I've specified, but the console shows the following error:
Contract has not been deployed to a detected network (network/artifact mismatch)
I've already tried truffle migrate --reset, without success. I've also tried creating an explicit network for testrpc in truffle-config.js - that didn't work either.
Any help would be much appreciated!
You are seeing that error because your contract is deployed to Ganache but you are connected to a different network.
The code that you are writing to load the contract should be inside try/catch block.
inside loading contract logic:
export const loadContract = async (name, provider) => {
// Load the contract
// set the provider
let deployedContract = null;
try {
// Get the contract
deployedContract = await _contract.deployed();
} catch {
console.error("You are connected to the wrong network");
}
return deployedContract;
};
In the component that you are using loadContract, call it inside useEffect.
useEffect(() => {
// Detect Provider
if (provider) {
// contract should be loaded when provider exists
const contract = await loadContract("ContractName", provider);
rLoaded: true,
// Add More logic
} else {
console.error("Please, install Metamask.");
}
};
}, []);
Now you need to make sure if you are not connected to Ganache, disable the button, so your app won't crash. for this create a state variable
// You probably already have logic to get account and contract
const canConnectToContract = account && contract;
now write a proper ui:
{!canConnectToContract && (
<h2>Connect to Ganache</h2>
)}
<button
disabled={!canConnectToContract}
>
Donate 1 Ethreum
</button>

No current user for authenticated user in Amplify

I am using react-native and the out of the box aws-amplify-react-native to sigin, signup users. Users are able to authenticate successfully but getting the following error in the signin form "no current user"
I pumped up the log level to debug in the application. I can see the user successfully authenticate and I get back the JWT token but I see the following in the logs:
[DEBUG] 22:47.149 AuthClass - Failed to get user from user pool
[ERROR] 22:47.154 AuthClass - Failed to get the signed in user No current user
[DEBUG] 22:47.161 AuthPiece - No current user
Below is a snippet of my code:
import { ConfirmSignIn, ConfirmSignUp, ForgotPassword, RequireNewPassword, SignIn, SignUp, VerifyContact, withAuthenticator } from 'aws-amplify-react-native';
const RootStack = createStackNavigator(
{
Login: LoginScreen,
Main: MainScreen,
Customer: CustomerScreen,
Reports: ReportsScreen,
Signup: SignupScreen
},
{
initialRouteName: 'Main',
}
);
const AppContainer = createAppContainer(RootStack);
export class App extends React.Component {
render() {
return (
<AppContainer />
);
}
}
export default withAuthenticator(App);
When I run my app. I see the default Sign In form for Amplify, I use it to enter username and password and then click on "SIGN IN" button which does successfully authenticate but I get the "No current user error" as shown above.
I had the similar problem. I removed the cookie storage block from the configure method and it worked.
Are you using the cookieStore? If true, do you use the secure flag? If so, change its value to false in the development environment.
The error is literally saying No current user - you need to sign in using the supported identity provider.
My solution to that:
import { Amplify } from "#aws-amplify/core";
import { Auth } from "#aws-amplify/auth";
import { CookieStorage } from 'amazon-cognito-identity-js';
import amplifyConfig from "../lib/Amplify";
Amplify.configure(amplifyConfig);
const cookieStorage = new CookieStorage(amplifyConfig.Auth.cookieStorage);
// cookie that is set before Cognito redirect to prevent infinite loop if authorization fails due to other reason than "No current user"
const redirectedFromAuthorize = cookieStorage.getItem("redirected-from-authorize");
...
Auth.currentAuthenticatedUser()
.then(user => {
setUser(user); // your custom function to do something with user attributes
// authorization was successfull, we can remove the redirect cookie
cookieStorage.removeItem("redirected-from-authorize");
})
.catch(err => {
console.error(err);
// if the cookie is set, it means the authorization failed again and you should not redirect back to Cognito
if (!redirectedFromAuthorize) {
// set redirect cookie, so that we know next time the error is reocurring
cookieStorage.setItem("redirected-from-authorize", 'true');
// redirect to Cognito hosted UI
return Auth.federatedSignIn();
}
});
I had this issue and I was able to sort it out by making the password of the user permanent with the command:
aws cognito-idp admin-set-user-password --user-pool-id us-east-1_XXX --username XXXXX --password XXXX --permanent
resolved
Togle "secure" to true in config:
Auth: {
region: "us-west-2",
userPoolId: "us-west-2_xxxxx",
userPoolWebClientId: "xxxxxx",
cookieStorage: {
domain: "localhost",
path: "/",
expires: 5,
secure: true, // <------------------------ true
},

How Do I Enable HTTPS on my AWS Elastic Beanstalk Environment for Parse Server Example?

I am trying to enable SSL/TLS on my Parse Server on AWS so that i can receive Webhooks from Stripe.
I created a self signed certificate on my using openssl, but when i tried to send a web hook with stripe i received the following error.
Invalid TLS
My Parse server index.js is
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
// push: pushConfig,
// filesAdapter: filesAdapter,
push:{
ios:{
pfx:'xxxxxxxxxxxxxxxxxx', // P12 file only
bundleId: 'xxxxxxxxxxxxxxxx', // change to match bundleId
production: false // dev certificate
}
},
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
var app = express();
// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!');
});
// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
});
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
ParseServer.createLiveQueryServer(httpServer);
How can I enable the https?
You need to get certificate from a trusted source . Otherwise even browsers will flag it as untrusted. Also while setting up https server you need to include this line of code :
https.createServer({
key: fs.readFileSync('Your-private-key.pem'),
cert: fs.readFileSync('your-crt-file.crt')
}, app).listen(3001,function(){
console.log('https server started on port 3001');
});
Also if you want to enforce https i would suggest you to look into express-sslify

Set cookie for domain instead of subDomain using NodeJS and ExpressJS

I have been using expressjs and mongostore for session management. Following is the code to configure store in expressjs,
app.configure(function(){
app.use(express.session({
secret: conf.secret,
maxAge: new Date(Date.now() + 3600000),
cookie: { path: '/' },
store: new MongoStore(conf.db)
}));
});
I had mentioned the cookie path in the above code. But it sets the cookie in sub.domain.com instead of .domain.com. How do i achieve this?
configure it like this:
app.use(express.session({
secret: conf.secret,
cookie: { domain:'.yourdomain.com'},
store: new MongoStore(conf.sessiondb)
}));
Try to use the following link to configure.
res.cookie('name', 'tobi', { domain: '.example.com', path: '/admin', secure: true });
Link : http://expressjs.com/api.html#res.cookie
This won't work, it throws error.
Error: Most middleware (like session) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
app.use(express.session({
secret: conf.secret,
cookie: { domain:'.yourdomain.com'},
store: new MongoStore(conf.sessiondb)
}));
I have a reference link, from where you can take help to set domain in cookie
https://flaviocopes.com/express-cookies/