IBM MFP8 - Unresponsive host error when adapter is called - ibm-mobilefirst

I am getting below error when I try to obtain access token from the server using this code.
WLAuthorizationManager.obtainAccessToken()
.then(
function (accessToken) {
console.log("accessToken ", accessToken);
},
function (error) {
console.log("error ", error);
});
ERROR
See the screenshot here
{
"responseHeaders":{},
"status":200,
"responseText":"undefined",
"errorCode":"UNRESPONSIVE_HOST",
"errorMsg":"unresponsive host"
}
Usually when I get the access token, soft update is received but now soft update is not received because of this error.
Can anyone help?

There can be 2 scenarios here.
MFP version of client and server is mismatched. Validated the version number of MFP and try again.
Application version number is not defined in MFP Console. So you can check the version number on MFP console.
let me know if that didn't work.

your response status is 200. it means everything is fine. check if you don't have the required data in DB/Server what you are looking for.

Related

How to handle 401 errors in#microsoft/signalr JavaScript client

We are using the #microsoft/signalr JavaScript client in our Vue frontend to establish a websocket connection with our backend (.net core). Also, we use a Bearer token for authentication.
This is the connection builder in the frontend:
this.connection = new HubConnectionBuilder()
.withUrl('/chat', { accessTokenFactory: () => IdService.getToken() })
.configureLogging(LogLevel.Information)
.withAutomaticReconnect()
.build()
Then I start the connection in this code:
HubService.connection.start().then(() => {
console.log('Connection started')
}).catch(err => {
console.error(err)
})
My problem is, when the Bearer token expires in the backend, on a reconnect I get a 401 error in the frontend, which is correct and I want to respond correctly to this error. I can catch the error in the catch block of the start function but I don't know how to handle the error, because I can't read a status code from the request like in a normal HTTP request. Its just a error message from the signalr client. Of course I could search in the string for '401' but that seems wrong.
Error: Failed to start the connection: Error: Failed to complete negotiation with the server: Error: Unauthorized: Status code '401'
I would like to know where in my code and how to properly handle this type of error and other errors to. Any help or ideas are appreciated.
The correct way to to this is your IdService.getToken() get you a refreshed token when it is almost expires because it's said in the Microsoft documentation that this function is called every time that there is an communication from client to hub.
The access token function you provide is called before every HTTP request made by SignalR. If you need to renew the token in order to keep the connection active (because it may expire during the connection), do so from within this function and return the updated token.
There are many examples for the token providers to refresh the token when it is near expiration.
But if that fix/implementation is out of your reach/control, the only thing you can do is catch the exception and just initialize again the connection. Something like this:
Catch the exception;
Emit an event with 401 unauthorized exception.
Catch the event and just call the method that initializes your connection.
But this is a workaround to the original problem, that is the proper token refresh function.

Cross-Origin Request Blocked error in HTTPS request

I have a standard HTTPS Axios request from my Frontend (which is based on Vue), to the our company's API which is on another server(server use SSL sertificate).
testApi() {
axios.get('https://rng-hub2.staging.rng:8001/rng/3/')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
},
Which cause an error like this:
In Firefox:
In Chrome the error looks like this:
As I was thinking, in browsed developing tools under tab of Netwerk -> Response, I should also see an error, which is true for Chrome, but eventyally is not true for Firefox.
So Chrome shows me:
But in the Firefox I receive my data in exactly right format:
Have any idea how I can retrieve this data correctly and assign it to the response variable in .then section?
About Cross-Origin Request Blocked error: API's server administrator told me, that he have added my IP to the CORS "trusted list". However I'm not sure, because according to this post: https://jonhilton.net/cross-origin-request-blocked/
in my Response Header I should receive an additional header with my local IP like:
Access-Control-Allow-Origin: http://192.168.32.44
But I'm not.
This proxy staff also didn't work:
How to deal with CORS error on Vue CLI 3?
Please give me hint what am I doing wrong
Found the solution. The problem was deeper then I thought. So short answer is: If you are working in local network, with different API servers, they might be certified with inner corporate CA (Certificate authority) to be able to communicate via HTTPS protocol. So what you need is, to ask from your server administrator to give you private_key with which you gonna sign all the request to a specific API. In guzzle its looks like this:
new GuzzleClient(['verify' => '/path/to/self-signed/cert.pem']);

MobileFirst Obtain Access token and Login give no response after setting WL.App.setServerURL

As per my requirement, I am using WL.APP.setServerURL before every login request WLAuthorizationManager.loginof mobilefirst.
When I do first an valid/Invalid login attempt it works fine. As on next attempt I do WL.App.setServerURL, and then WLAuthorizationManager.login (login request) OR WLAuthorizationManager.obtainAccessToken (obtain access token request) don't respond anything. No success and no fail. Although non-secure adapter method works fine.
If I do WL.APP.setServerURL only once on application startup, everything works fine but in between call cause application failure.
let url = ... //fetcht url from adapter call
WL.App.setServerUrl(url, function (sucess) {
WLAuthorizationManager.login(securityCheckName, loginParam).then((data) => {
.... //After login code
}, (response) => {
//Login fail code
});
}, function (error) {
});
Flow :-
I call above code on click of login button.I call a method to get server url from adapter first then I set that url as server url.
When I do an invalid attempt of login it works find for first time, and on next call MFP login, it doesn't respond. Not success nor fail in application.
I am getting error in native logs android.
Android Error logs :-
E/SecurityCheckChallengeHandler(30199): SecurityCheckChallengeHandler.submitChallengeAnswer in SecurityCheckChallengeHandler.java:51 :: submitAnswer has been called for unknown request
.
MobileFirst server version :- 8.0.0.00-20170911-123510
MobileFirst Cordova(plugin) version :- 8.0.2017102403
The WL.App.setServerUrl API is meant to be used sparingly whenever the app needs to connect to a server other than the one defined in mfpclient.properties. If you want to keep the server URL constant, you should just put it up in the mfpclient.properties.
Having said that, the behaviour you mention is not expected - can you update your question with a code snippet of your app performing login & setServerUrl

React-native android , REST api post error getting "access denied"

Developing sample application, when i was call the post method
service in componentDidMount() getting error response access
denied. Only android it's having this issue. But I got this
response IOS Devices .
I researched this case Most of the this issue get an based up on
NetWork same wife connection like emulator and my System this is
fine.
when i was check on AndroidManifest.xml file also getting
Internet Permissions also Accessed.But Still getting this Error in
Android. Please Solve this ,
Only getting in Android Device and emulator having this issue
other Platform device like IOS working fine.
Thanks in Advance.
If the REST server is on localhost in Android you'll have to use your IP instead of http://localhost.
If the rest server is not on localhost you might have to adjust the body and the headers. So instead of string body use a json object etc.
Your code:
fetch('site:ab4aca652284d7dc87ca1f347f2ac432#ori-eu-west-1.s‌​‌​earchly.co…
',{ method:'POST', headers:{ 'Accept':'application/json',
'Content-Type':'application/json' }, body:JSON.stringify(string)
}).then((response)=>response.json()).then((responseData)=>{
}).catch((err)=>{ console.error(err) })
rowDatanewOrders:{"status":"error","message":"access denied"}
make sure you have a valid json in body if you have the header 'Content-Type':'application/json', not a string as you have now!
more details about possible adjustments of the body and headers here:
https://github.com/facebook/react-native/issues/5222

cPanel, Laravel TokenMismatchException with Cookies not being set

I recently moved my laravel application to a production server rather than just developing locally. However since doing so I have been unable to login to the site as I keep running into Illuminate \ Session \ TokenMismatchException.
I never had the issue on the local server, just when I ported it over the production server.
I have looked into the tokens and they never match at all. My code is as follows:
Route::filter('csrf', function()
{
// Check ajax requests for token validity via the header.
// app.js has the code to grab form tokens and put it in
// a header, well validate it here if its a post AJAX
if (Request::ajax() && Request::getMethod() == 'POST')
{
if (Session::getToken() != Request::header('X-CSRF-Token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
} else {
if (Request::getMethod() == 'POST' && Session::token() != Input::get('_token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
}
});
The error occurs when I am trying to compare Session::token() to Input::get('_token)
So my question is, is there something blatantly obvious that I am missing in regards to the difference between tokens on a local server to that of a production server?
Any help on this would be greatly appreciated!
~Additional Information~
From the other sources I've found there are similar issues where the session isn't persisting. I'm already on Laravel 4.1 so the lifetime and expire_on_close are already set to the default of 120 and false. I have also tried changing the session driver to file/database/cookie all with the same outcome.
~Another Update~
Ok, somewhere a bit closer, looking into browser resources, on my local server a cookie is set laravel_session, however on my web server this is not appearing at all. So think this is related it.
I couldn't solve this. In the end though I found that is was related to the use of cPanel, as soon as I used another hosting provider without cPanel the issue has never occured.