Failed to authenticate credentials using Mongolite R - r

I use R and trying to use the very recent "Mongolite". However I cannot connect to MongoDB server.
The manual clearly states the following:
mongo(collection = "test", db = "test", url = "mongodb://localhost")
This is what I have tried without success, where I have a log token and the port of course.
mongodb://heroku:TOKEN#lennon.mongohq.com:PORT
and keep getting the following error:
Error in mongo_collection_new(url, db, collection) :
Failed to authenticate credentials.

It is tried and true that mongolite (v0.7 as of today) supports authenticated connection to a remote 3.2.x MongoDB (as opposed to localhost).
The example below jeroenooms provides himself worked:
library(mongolite)
mongo(collection = "mtcars", url = "mongodb://readwrite:test#ds043942.mongolab.com:43942/jeroen_test")
To explain:
mtcars is the name of the MongoDB "collection" (or "table" if you insist). It could be a name that does not exist yet.
readwrite is the user name of your mongodb
test is the password of the user "readwrite"
ds043942.mongolab.com is the remote host, which could be replaced by ip address, i.e. 23.20.234.21
43942 is the port number. By default in MongoDB, it is 27017
jeroen_test is the name of the database instance in use, which has to exist already
Running the commands above in R will print:
Mongo Message: SCRAM: authenticating "readwrite" (step 1)
Mongo Message: SCRAM: authenticating "readwrite" (step 2)
Mongo Message: SCRAM: authenticating "readwrite" (step 3)
Mongo Message: SCRAM: "readwrite" authenticated
...
I tried to replace it with my own remote host info. It didn't work in the beginning, which turned to be the user role issue rather than mongolite issue. After ensuring a user with correct readWrite roles, I connected to my remote 3.2.x MongoDB via mongolite package.
The following 2 sources were of great help to me in setting up users in MongoDB:
enable-authentication
Manage User and Roles

If you look into the source code of jeroenooms/mongolite you can see that it doesn't support authentication yet:
https://github.com/jeroenooms/mongolite/blob/master/R/mongo.R
mongo_collection_new <- function(uri = "mongodb://localhost", db = "test", collection = "test"){
stopifnot(is.character(uri))
stopifnot(is.character(db))
stopifnot(is.character(collection))
.Call(R_mongo_collection_new, uri, db, collection)
}

just change the order :
mongo( url = "mongodb://localhost",db = "test",collection = "test")

I found that the following command allowed me to connect to mongodb using mongolite and the legacy SCRAM-SHA-1 authentication mode.
library(mongolite)
mongoUrl <- "mongodb://a_username:a_password#localhost:27017/admin" #<-admin here is the mongodb database that stores the authentication info
# specify your collection
colname <- "a_collection"
# specify your database
dbname <- "a_database"
# create connection (con)
con <- mongo(collection = colname, url = mongoUrl, db=dbname)
# count how many records (fyi this is just a test)
con$count('{}')

Related

Error in Oauth2.0 authentication in R using HTTR (failed to connect: connection refused)

I am trying to create a simple app (in R) using GroupMe's API, which utilizes OAuth2.0. The documentation can be found here. However, I'm getting stuck on the first step of authentication/token generation for a user. See below for my code and the response I get:
access_key = ****
client_id = ****
gendpoint <- oauth_endpoint(
authorize = glue("https://oauth.groupme.com/oauth/login_dialog?client_id={client_id}"),
access = glue("http://localhost:1410/?access_token={access_key}")
)
gapp <- oauth_app(
"pingme",
key = client_id,
secret = access_key
)
t <- oauth2.0_token(
endpoint = gendpoint,
app = gapp
)
The above code is sufficient to bring in the login page, which presumably allows me to enter my credentials to obtain a token. However, when I enter my credentials, I get the following error message in R:
Authentication complete.
Error in curl::curl_fetch_memory(url, handle = handle) :
Failed to connect to localhost port 1410: Connection refused
So it looks like my authentication/login credentials worked, but somewhere an error prevented me from actually generating the token.
Could someone help me with this? This is my first time using the OAuth2.0 framework so I'm very confused. Thanks in advance!

R JDBC snowflake connection using ssh key auth

I have a Rstudio setup with no browser and only terminal access to internet.
Having issues following the guides for snowflake connections with Rstudio and dplyr library using ssh keys for auth, can confirm access to the tenant via browser outside of terminal. I also tried the jdbcDriver jar directly and connection to no avail.
Any pointers would be helpful
Examples below, tried with and without region
install.packages(c("rJava"))
install.packages(c("RJDBC", "DBI", "dplyr"))
install.packages("devtools")
devtools::install_github("snowflakedb/dplyr-snowflakedb")
library(RJDBC)
library(dplyr)
library(dplyr.snowflakedb)
options(dplyr.jdbc.classpath = "/opt/snowflake-jdbc-3.9.2.jar")
snowflake_con <- src_snowflakedb(user = "myusername#domain.comm", password = "mypassword", private_key_file = "/home/ssh-keys/rsa_key.p8", private_key_file_pwd="myfilepassword", host = "myhost.eastus2.snowflakecomputing.com", opts = list(warehouse = "WAREHSE", db = "DB", schema = "CB", authenticator="externalbrowser"))
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:snowflake://<account><.region_id>.snowflakecomputing.com", "<username>","<password>")
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:myhost.eastus2.snowflakecomputing.com", private_key_file = "/home/ssh-keys/rsa_key.p8", private_key_file_pwd="myfilepassword")
tried following snowflakes guide here but this just uses username and password which requires the auth verified.
https://community.snowflake.com/s/article/connecting-r-to-snowflake-using-the-jdbc-driver-mac-os-x
https://snowflakecommunity.force.com/s/article/How-TO
You will either need a user configured with password authentication or Key Pair Authentication. SSO authentication will not work for you in the absence of a browser. After creating the keys, you will need to assign the key to the Snowflake user. Finally, here is how to configure JDBC configuration to use key pair authentication

How Do I Connect to a Neo4J AuraDB Instance from R Studio

I created a Neo4j AuraDB database where I have dumped the movie recommendation dataset. I am able to start and connect to the instance in the cloud. However, when I try to connect to the instance via its API in R Studio, using the neo4r package and the following code
movieDB <- neo4j_api$new(
url = curl("neo4j+s://0cc45a14.production-orch-0054.neo4j.io:7687"),
user = "neo4j",
password = "password"
)
movieDB$ping()
I get the error message in my console Error: Could not resolve host: 7. Also, when I try to start a graph with the following code
graph <- startGraph(
url = curl("neo4j+s://0cc45a14.production-orch-0054.neo4j.io:7687"),
user = "neo4j",
password = "password"
)
I also get the following error message in my console
Error in function (type, msg, asError = TRUE) :
Could not resolve host: 8
I do not know why the error is happening, as I have previously connected to a Neo4j sandbox instance from within R Studio without any hassle. As always, I will appreciate your helpful suggestions. Thanks!
AuraDB requires a driver which supports the Bolt protocol. I do not know of any R driver that supports the protocol at the moment, they only support HTTP (and HTTP is not available yet in AuraDB).

Authentication Error while connecting outlook from R

I m trying to connect to outlook from R
But it returns authentication error:
Error in response_error_handling(e$message[1]) :
Login denied: the server returned an authentication error
Please help
library(mRpostman)
con <- configure_imap(url="imaps://outlook.office365.com/",
username="*********#*******.com",
password=rstudioapi::askForPassword())
con$select_folder(name = "Inbox")
When it comes to Office 365, the email you see is usually an alias and not your "real" email address. For example, we use Office 365 in my company and my email is allan#company.com. However, the real address is 3254339#company.com, where 3254339 is my ID number in the company.
Please, check with your IT department/sector if this is also your case, and create ​the connection token like this
con <- configure_imap(
​url = "imaps://outlook.office365.com/",
​username = "3254339#company.com",
​password = rstudioapi::askForPassword()
)

Error when signing into R Studio on Google Cloud VM: Unable to connect to service

I want to run Rstudio on a VM through Google Cloud Platform. Everything seems to work except when I sign in to RStudio I receive an 'RStudio Initialization Error': "Unable to connect to service". My username and password are correct as if they're wrong it tells me so.
I created the instance using RStudio on my laptop. I've tried adding a rule in Google Cloud Platform to allow all access to the IP address but that did not work.
#My Code
library(googleComputeEngineR)
#Setup ------------
project <- "r-bench"
zone <- "europe-west1-b"
account_key <- "gcs-key.json"
Sys.setenv(GCE_AUTH_FILE = account_key,
GCE_DEFAULT_PROJECT_ID = project,
GCE_DEFAULT_ZONE = zone)
gce_auth()
#Set our default global project
gce_global_project(project)
gce_global_zone(zone)
default_project <- gce_get_project("r-bench")
default_project$name
#Deploy instance
vm <- gce_vm(template = "rstudio",
name = "rstudio-demo",
username = "rstudio",
password = "xxxxxxxx",
predefined_type = "n1-standard-1")
I expect to sign in and use RStudio as normal. Instead, I receive the error I mentioned previously.
If I am not mistaken using rstudio is a reserved name and as a username is not allowed.

Resources