DocumentDB web API access with R - r

I have the following issue when trying to connect to the documentDB web API with R and PostMan.
In the DocumentDB documentation the way to ask something to the web API is to compose an Authorization header with base64 hash.
In R I'm trying to compute the signature and test the header directly with postman.
But I get every time a http 401.
Here is my R code:
toHash <- enc2utf8("get\ncolls\ndbs/toto/colls/testtoto\nsun, 08 may 2016 06:43:05 gmt\n\n")
hash <- hmac(key, toHash, "sha256")
base64(hash)
the "key" is the primary key got from the portal.
And then, following the Azure documentation, my header is:
type=master&ver=1.0&sig=< thebase64(hash) >
I'm pasting that into PostMan with the headers x-ms-version, date and x-ms-date.
But it'is not working..
I'm stuck now, does anyone have an idea? Am I using a wrong R function? A wrong key, is there a way to get more information about the mismatch?
The web api response is :
{
"code": "Unauthorized",
"message": "The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get\ncolls\ndbs/toto/colls/testtoto\nsun, 08 may 2016 06:43:05 gmt\n\n'\r\nActivityId: fadbfc0b-e298-418a-b56c-8114699fff91"
}

I found what was wrong by myself.
The token given in the Azure portal is base64 encoded. So It is mandatory to decode it:
RCurl::base64Decode(key, mode="raw")
in order to use it with the digest::hmac function. It is also mandatory to specify raw = TRUE within this hmac function.

Related

How to call Neo4j database api in R Studio

Please I created a Neo4j database instance, and I am trying to call it in R Studio, using the neo4r and neo4jshell packages. After running the api call, I still get a 404even though I correctly specified the url, username, and password. Please find my code below:
library(neo4r)
library(neo4jshell)
myTwitter <- neo4j_api$new(
url = "http://54.152.83.7:7474",
user = "neo4j",
password = "mypassword"
)
myTwitter$ping()
When I run the last line of code, I get the 404 instead of 200, which obviously means my api call was not successful. Please I would appreciate your helpful suggestions. Thank you
HTTP endpoints were changed since version 4 of Neo4J
Neo4j v3 had endpoint http://localhost:7474/db/data
Neo4j v4 uses http://localhost:7474/db/{databaseName}/tx instead of it.
Seems like Neo4j library for R needs to be updated...
I'm not familiar with R but you could try to use available HTTP client for R that supports Basic authentication to send POST requests to Neo4J API with JSON payload. I also see you use http schema which means your credentials will be sent as plain text through the network, which is not good.
Payload for such requests should be in form of:
{
"statements": [
{
"statement": "MATCH(n) RETURN n"
}
]
}
(adjust Cypher query to your needs)
Response will be JSON object with data section containing actual results.

'Request had insufficient authentication scopes' from Google Translate API in R

I am currently working on analyzing twitter data , however when I attempt to translate twitter text data through the translate() package leveraging the use of Google API in R I get this error.
t <- gl_translate(my_data$text, source="ar", target="en", )
2020-07-19 11:25:30 -- Translating text: 69597 characters -
ℹ
2020-07-19 11:25:32 > Request Status Code: 400
2020-07-19 11:25:32 -- API returned: Request payload size exceeds the limit: 204800 bytes.
2020-07-19 11:25:32 -- Attempting to split into several API calls
2020-07-19 11:25:32 -- Translating text: 98 characters -
Auto-refreshing stale OAuth token.
ℹ 2020-07-19 11:25:33 > Request Status Code: 403
Error: API returned: Request had insufficient authentication scopes.
why does it produce this error?
this is my code:
gar_auth(email="**#**.com")
set.key('****')
t <- gl_translate(my_data$text, source="ar", target="en", )
View(t)
If you use googleLanguageR package (it is not clear from the question itself), it seems like an authentication issue.
You'll probably need to authenticate with:
library(googleLanguageR)
gl_auth("translate_api_key.json")
To get the JSON authentication file, see Google Cloud Translation - Creating service accounts and keys.
For details on authenticating the googleLanguageR package in R, see Language tools for R via Google Machine Learning APIs - Authentication.
Note that Google API has some pricing for this.
If you want to use a Google Translate API key rather than JSON file, there are:
translate package, where you store you API key in getOption("google.key") variable, or you pass a key argument with you API key, and
github/sumtxt/datatools package with gl_translate() function, where you can provide the API key in the key argument as well,
but note that you have to generate you API key in Google Cloud Console as well (not to be confused with a password of your Google account).

Can I use my test environment merchant ID and keys to test a flex microform post?

I'm getting started understanding what's required for Cybersource's Flex Microform integration. But to start with, I'm hoping to be able to see a valid response using my merchant ID, shared secret key and the general key that comes with generating the secret on the cybersource api reference page: https://developer.cybersource.com/api-reference-assets/index.html#flex-microform_key-generation_generate-key
This is using the HTTP Signature method and ChasePaymentech (default) processor.
If I use the default settings they supply and choose to do a test POST to here https://apitest.cybersource.com/flex/v1/keys?format=JWT&
The JSON response is good with no complaints of authentication.
If I try to do the same POST with my test environment merchant ID and keys I generated in my merchant environment here: https://ubctest.cybersource.com/ebc2/app/PaymentConfiguration/KeyManagement the POST response will return a 401 with this JSON:
{
"response": {
"rmsg": "Authentication Failed"
}}
Is this developer.cybersource.com site a valid place to perform this kind of test? Are there any other steps I need to do in the merchant account to have this Authenticate?
I'm just getting started on figuring out the CyberSource Flex Micro Form code out myself and it's pretty straight forward from what I can see. If you don't have the proper SDK already pulled in, you can fetch it from https://github.com/CyberSource
I had to use Composer to fetch all the dependencies but once I did, I was able to load up the microform checkout page in my browser window successfully. Make sure you edit the ExternalConfiguration file with your credentials that you setup in CyberSource.
The apiKeyId value is the value you can find in your CyberSource account under Key Management. This is the value with the dashes in it.
The secretKey value is the value you should have downloaded from CyberSource that is your public key. This is the value without the dashes and probably has a few slashes / in it.
That's all I had to do in my setup to get the first successful authentication / token on my end.

Shopee Open Platform API always response "Invalid token"

I'm sorry in advance if something bring you here and I talk about a platform that's not really well-known over the world despite featuring a well-known person dancing in their commercial.
It's Shopee Open Platform API I talk about. I was trying to follow very properly their instruction here.
https://open.shopee.com/documents?module=63&type=2&id=51
But stuck instantly at step 5 : Shop Authorization. First, I've been given a test partner id, a test key, and I need to set manually the test redirect URL. I have to generate authorization token from all given information. Firstly I need to create a token base string by concatenating the test key with URI component encoded string of the URL. It turns into something like this.
9b754aca01a5d719cb70c5778294dae6ff90fcc68c82908ee480a36ff901d181https%3A%2F%2Fwww.unwelldocumented.com
To generate the authorization token, it says I need to do hexencode(sha256(token_base_string)). It returned a very long integer.
32373935663639356636346266303137613465396239383361373334646133656530313333393762636138396364663037366566313366313436316534303761
So I just assumed everything is fine and that is the authorization token. But when I send this...
https://partner.uat.shopeemobile.com/api/v1/shop/auth_partner?id=(test_partner_id)&token=(authorization_token)&redirect=(test_redirect_URL)
... suddenly I get this
{
"error": "error_auth",
"msg": "Invalid token",
"request_id": "30a4b6b0074541bdd88260a33f155ca6"
}
In order to solve this, you have to understand that SHA256 is an Encryption hash function. Please research more on SHA256 on your specific language.
For this very specific case, your SHA256 token should be as below.
Before SHA256:
9b754aca01a5d719cb70c5778294dae6ff90fcc68c82908ee480a36ff901d181https%3A%2F%2Fwww.unwelldocumented.com
After SHA256:
2795f695f64bf017a4e9b983a734da3ee013397bca89cdf076ef13f1461e407a
The rest of your steps seems correct.

How can export list of Cloud Messaging topics using Postman (or any client)?

I want to get a list of all Cloud Messaging topics that have been created by my app. Documentation shows that I need to fire a GET request to the https://iid.googleapis.com/iid/info/IID_TOKEN endpoint with an Authorization header containing my API key. For example:
https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=true
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
Steps:
Get IID_TOKEN by printing FIRInstanceID.instanceID().token() in my
iOS app. This returns a 152 character long string.
Get Authorization key from API_KEY in GoogleService-Info.plist. This is a 39 character long string.
Fire GET request using Postman Chrome Extension
Result:
I get MissingAuthorization. Either I am providing the wrong IID_TOKEN, API_KEY (unlikely), or setting authorization header incorrectly in Postman.
What am I doing wrong?
You can get the server key directly from Firebase -> Project settings -> Cloud Messagings:
After that, you can create a request using Postman in this way:
Or you can use Authorizations OAuth 2.0 in this way:

Resources