IBM IAM API KEY AUTHENTICATION ERROR - api

I am executing the code below.. I have supplied the correct API but keep getting an authentication error (provided below)
Here's the code snippet
// Example 1: sets up service wrapper, sends initial message, and
// receives response.
const AssistantV2 = require('ibm-watson/assistant/v2');
// Set up Assistant service wrapper.
const service = new AssistantV2({
iam_apikey: 'xxx', // replace with API key
version: '2019-02-28',
});
const assistantId = 'xxx'; // replace with assistant ID
let sessionId;
Here's the error message
C:\Users\User\Desktop\Insurancebot\test>node sample.js
{ Unauthorized: Access is denied due to invalid credentials.
at RequestWrapper.formatError (C:\Users\User\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:219:21)
at C:\Users\User\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:207:29
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'Unauthorized',
code: 401,
message: 'Access is denied due to invalid credentials.',
body: '{"code":401,"error":"Unauthorized"}',
headers:
{ 'x-backside-transport': 'FAIL FAIL',
'content-type': 'application/json',
'x-dp-transit-id': 'gateway02-3627341245',
'x-global-transaction-id': 'ffea405d5d0083b9d834d5bd',
'strict-transport-security': 'max-age=31536000;',
'x-dp-watson-tran-id': 'gateway02-3627341245',
'content-length': '37',
'x-edgeconnect-midmile-rtt': '110',
'x-edgeconnect-origin-mex-latency': '132',
date: 'Wed, 12 Jun 2019 04:46:49 GMT',
connection: 'close' } }

Outside of the wrong IAM key, the most common cause is the wrong service endpoint being used.
It defaults to US, so if you have set up your assistant in U.K. for example, you would set: url: ‘https://gateway-lon.watsonplatform.net/assistant/api’
The full list is here:
https://cloud.ibm.com/apidocs/assistant#service-endpoint

Related

VISA api: Fail to post requests with this error, "Expected input credential was not present"

I'm new to VISA developer and trying to send requests to https://sandbox.api.visa.com/cofds-web/v1/datainfo to check whether the credit card is valid or not in Python.
Python code:
cert = 'C:\\Users\\user\\visa_cert\\cert.pem'
ca_cert = 'C:\\Users\\user\\visa_cert\\ca_cert.cer'
key = 'C:\\Users\\user\\visa_cert\\my_key.pem'
user_id = 'your user id of your project'
password = 'your password of your project'
timeout = 10
cred_info = 'credit_info.json'
payload = json.loads('''{
"requestHeader": {
"requestMessageId": "6da6b8b024532a2e0eacb1af58581",
"messageDateTime": "2019-02-35 05:25:12.327"
},
"requestData": {
"pANs": [
4072208010000000
],
"group": "STANDARD"
}
}
''')
try:
response = requests.post(url,
verify = (ca_cert),
cert=(cert, key),
# headers = headers,
auth=(user_id, password),
json = payload,
timeout=timeout
)
except Exception as e:
print(e)
Execution itself succeeded, but the response says the "Ecpectd input credential was not present"
Response header and contetns are as below.
# response header:
{'Server': 'nginx', 'Date': 'Fri, 03 Jun 2022 13:52:17 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '130', 'Connection': 'keep-alive', 'X-SERVED-BY': 'c6795c5t4', 'X-CORRELATION-ID': '1654264337_872_241384137_c6795c5t4_VDP_WS', 'X-ERROR-ORIGIN': '9200', 'X-APP-STATUS': '400', 'X-Frame-Options':
'SAMEORIGIN', 'X-XSS-Protection': '0', 'X-Content-Type-Options': 'nosniff', 'Strict-Transport-Security': 'max-age=31536000;includeSubdomains', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '-1'}
# response content:
b'{"responseStatus":{"status":400,"code":"9125","severity":"ERROR","message":"Expected input credential was not present","info":""}}'
I followed the instruction here(https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl#configuring_a_twoway_ssl_keystor...) to generate the CA certificate, double-checked my user_id and password are correct and two-way SSL certificate is active.
I googled this error, but I'm still not sure how to fix this problem.
Thank you.
passiveradio
So this API requires Message Level Encryption so I have been struggling to figure out how to implement the MLE with the API, if you try to use the Visa Developer Center with MLE enabled you will get the error you're getting but if you run it with MLE enabled it works.
So if you figure out how to implement MLE in the code I would be grateful because the documentation is very vague.
https://developer.visa.com/pages/encryption_guide

Unable to generate OAuth 2.0 Access Token from Office365 via JavaScript

I'm trying to pull an access token from Office365's /token identity platform endpoint via OAuth 2.0 client credentials grant flow. I have my app registered, the client ID & secret, etc...
I can make the POST request in Postman and receive the access token without issue:
However, when I try the POST request via JavaScript (by way of Google Apps Script), I receive an error message: AADSTS900144: The request body must contain the following parameter: 'grant_type'
I've already Google'd this error and found a bunch of different solutions, and have tried implementing them to no avail. I imagine this has to do with the URL encoding, but cannot figure it out.
Code:
function getO365() {
// POST Request (To get Access Token)
var tenantID = 'longstringhere'
var appID = 'longstringhere'
var appSecret = 'longstringhere'
var graphScore = 'https://graph.microsoft.com/.default'
var url = 'https://login.microsoftonline.com/' + tenantID + '/oauth2/v2.0/token'
var data = {
'client_id': appID,
'scope': graphScore,
'client_secret': appSecret,
'grant_type': 'client_credentials'
};
var postOptions = {
'method': 'POST',
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
'body': data,
'redirect': 'follow'
};
var authToken = UrlFetchApp.fetch(url, postOptions);
}
The only real difference between my code and the JavaScript Fetch code I pulled off of Postman is:
var urlencoded = new URLSearchParams();
urlencoded.append("client_id", "longstringhere");
urlencoded.append("scope", "https://graph.microsoft.com/.default");
urlencoded.append("client_secret", "longstringhere");
urlencoded.append("grant_type", "client_credentials");
When I try to use URLSearchParams in Google Apps Script, I keep getting this error: ReferenceError: URLSearchParams is not defined
Any ideas? Thanks in advance!
This was resolved by changing 'body' to 'payload' for UrlFetchApp per the documentation. Edited code to reflect the change. Credit to #TheMaster for pointing out my mistake.
'payload': data,//from 'body': data,

unable to encrypt message in matrix-js-sdk

I'm used 'olm' version '3.1.4' and 'matrix-js-sdk' version '2.4.6'
Trying use end to end encryption supported in matrix using olm
I'm using the following code snipping:
const cryptoStore = new sdk.MemoryCryptoStore(window.localStorage);
const webStorageSessionStore = new sdk.WebStorageSessionStore(window.localStorage);
var matrixStore = new sdk.MatrixInMemoryStore();
matrixClient = sdk.createClient({
baseUrl: 'SERVER_HOME',
accessToken: token,
userId: 'USER_ID',
store: matrixStore,
sessionStore: webStorageSessionStore,
cryptoStore: cryptoStore,
deviceId: 'DEVICE_ID'});
matrixClient.initCrypto()
.then(() => {
matrixClient.startClient({ initialSyncLimit: 10 });
})
1- I have error with post key/upload API bad request
REQUEST: POST Request URL: https://SERVER_HOME/_matrix/client/r0/keys/upload/DEVICE_ID?access_token=XXXX
RESPONSE: 400 Bad Request {"errcode":"M_UNKNOWN","error":"One time key signed_curve25519:XXXX already exists. Old key: {\"key\":\"64zJVMH61Toei8Kaz2SRXEZ4VyNBjjG2vfaGjSXXXX\",\"signatures\":{\"#USER_ID\":{\"ed25519:869254020336060\":\"HBnlhazYGY+IrvImq5d4OcIYsXeo094St2p/SMYWobMfteML1gH1jMSUmAh9o7EYIXQMnshiPSh6FSdL4XXXXw\"}}}; new key: {'key': 'VSfPQ7NFzdPl0owA1pVK8CqTzLCyF6NQCuS8aTIIYmc', 'signatures': {'#USER_ID': {'ed25519:869254020336060': 'rIQHea/3kh5w8PaC91H83zsTKQDevbkPpnJ5Dpj7YHv3o4Jzq1O3AmgMzfhFzhlXBwn1N6gRPfC+jNMCIPXXXX'}}}"}
2- When I test it with encryption Roit room and try to send message from sdk to Roit find this is error get this error
Error sending event UnknownDeviceError: This room contains unknown devices which have not been verified. We strongly recommend you verify them before continuing.
3- When I test it with encryption Roit room and send message from Roit to sdk I get this error
Error decrypting event (id=xxxx): DecryptionError[msg: The sender's device has not sent us the keys for this message., session: FoIZTb4W906iFiQofhzgyZlkjeR9XazjN9vfIC9uzFQ|nCwWvT+VU/FVz7uNLojW51+PtkrXj++eMC1d/Xxxxxxx]

oAuth returning 400 bad request

I am making a request to my auth server using the example from cypress documentation below.
https://github.com/cypress-io/cypress-example-recipes/blob/aa434ffc29946d545daf4c94019f9692eb0db3e0/examples/logging-in__single-sign-on/cypress/integration/logging-in-single-sign-on-spec.js#L47
Following is my configuration but I am getting a 400 bad request. The url should take me to the login form and authorise the user and then redirect to call back page to get the token.
Am i missing something?
const options = {
method: 'POST',
url: 'https://fakeauthserver.net/Account/Login',
qs: {
redirect_uri: 'http://localhost:9000/login/callback',
client_id: 'webapp',
response_type: 'code',
scope: 'full-access'
},
form: true,
body: {
Username: 'fakeusername#grr.la',
Password: '123456',
button: 'login'
}
};
_.extend(config);
cy.request(config)
Usually, the 400 Bad Request error occurs when you have made an error in the parameters sent in the request. Check whether you have sent all the parameters and whether they are the same as the ones registered in your identity provider.
Also, it might be due to POST request you have made here. According to the OAuth specification, authorization request should be a GET request.

Getting a 422 Authorization error with Uber API

I am testing my app for the first time, just trying to get basic info via the API but am getting an error: 422 Unprocessable Entity, "validation_failed".
What am I missing here? I have tried it with both sandbox-api.uber.com and with api.uber.com.
getting back:
code: "validation_failed" fields: {start_longitude:Required,
start_latitude:Required} start_latitude: "Required" start_longitude:
"Required" message: "Invalid request"
var uberServerToken = "XXXXXXXXcEE0cHbwhKiF_sl_ZUYvEHHO_f6U6dr" ;
$http({
url: "https://api.uber.com/v1/estimates/time" ,
headers: {
Authorization: "Token " + uberServerToken
},
data: {
start_latitude: setLat,
start_longitude: setLon
},
success: function(result) {
console.log(result);
}
});
You need to provide an access token for the request. Grab the access code from the user, exchange that for an access_token, and provide the access_token with each request to Uber's API.
Link: https://developer.uber.com/v1/auth/