We use windows authentication in our application and it is working fine on our test server. When we publish it onto Production environment (Google compute engine), every first ajax request (per URL) on iPhone/iPad (not matter chrome or safari) after user logon will fail(can not connect to the server). When we perform exactly same action again, it will success. Here is one of our ajax request:
$.ajax({
url: '#Url.Action("GridData")',
type: 'post',
data: {
JobName: $("#JobName").val(),
JobNumber: $("#JobNumber").val(),
},
success: function (data) {
...
},
error: function (xhr, textStatus, errorThrown) {
// first attempt in iPad/iPhone(no matter safari or chrome) will go to here
alert('#Params.AjaxErrorMsg');
},
complete: function() {
...
}
});
After debugging with mac, I found the first ajax call missing the content of Authorization but I have no idea why (this is working fine in any browser with computer version.) Also, I am not sending cross domain request. If I tried to manually put valid data of Authorization for the first ajax call, it will success. Any direction or suggestion will be appreciated. Thanks!
Related
I have successfully added my callback url in my webhooks setup. At that time, the callback url was called successfully with proper logs and everything in the server. But when I click on the TEST button for the respective name (leadgen in this case), nothing AT ALL is being received by the server when in fact it should at least log the very first line. Note that I am using post and get.
Additional note: for NetSuite experienced developers, I am using a suitelet as the callback url for the webhook.
Thanks.
Suitelets that are available externally without login will only work if the User-Agent header in the request mimics a browser. See for example SuiteAnswers # 38695.
I ran into a similar issue, and the workaround was to proxy the request using a Google Cloud Function that simply rewrote the User Agent:
const request = require('request');
exports.webhook = (req, res) => {
request.post(
{
url: process.env.NETSUITE_SUITELET_URL,
body: req.body,
json: true,
headers: {
'User-Agent': 'Mozilla/5',
Authorization: req.headers['authorization'],
},
},
function(error, response, body) {
res.send(body);
}
);
};
I'm trying to integrate a very small custom web application with NetSuite. I want a custom record to be created in NetSuite whenever a user clicks a button in my web application.
I have written a RESTlet that works with the REST API Testing chrome extension. I have successfully created records through that chrome extension.
However, when I try to POST from my web application, I get this error:
"Response to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access. The response
had HTTP status code 401."
How can I POST to NetSuite with a RESTlet from an external site? Should I even be using a RESTlet or is there a better way?
RESTlets are meant more as a system to system technology. They require authentication and if you are doing that from a public app your credentials will be compromised.
Netsuite doesn't allow you to set a CORS header so your cross domain integration needs to be via a publicly available suitelet and JSONP.
Since JSONP makes use of get requests you need to make sure your url params end up less than about 2k characters. That's not a standard limit so ymmv
patterns I often use:
Client code:
var url = "public suitelet url from deployment screen";
var params = {
mode: 'neworder',
//simple name/value data
};
$.ajax({
url: url+"&"+ $.param(params) +"&jsoncallback=?",
cache:false,
dataType:'json',
success: function(jResp){
if(!jResp.success){
if(jResp.message) alert(jResp.message);
return;
}
// act on the results
}
});
A library function in the suitelet source file.
function _sendJSResponse(request, response, respObject){
response.setContentType('JAVASCRIPT');
//response.setHeader('Access-Control-Allow-Origin', '*');
var callbackFcn = request.getParameter("jsoncallback") || request.getParameter('callback');
if(callbackFcn){
response.writeLine( callbackFcn + "(" + JSON.stringify(respObject) + ");");
}else response.writeLine( JSON.stringify(respObject) );
}
and then a Suitelet function
function service(request, response){
... do some work and generate a response
var returnObj = {
success:true,
message: '',
result:result
};
_sendJSResponse(request, response, returnObj);
}
That's your browser and its CORS setting
If using chrome ( you should be ;) ) on Windows, create a chrome shortcut with the following flags
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir
Then, kill/restart ALL INSTANCES of chrome in the Task Manager and try your requests again
Otherwise google "disable CORS on MY_BROWSER"
I am using Jasper 6.1 and configured my server to allow token based authentication. It works fine when i use token to login from browser. With the valid token, I am able to get into the system without entering username and password.
Now, I am integrating it with visualize.js in order to show reports on our application's web page. Below is request call :-
var authToken = encodeURIComponent("u=jsmith|r=admin|exp=20150831172506-0800|t=ABC");
visualize.config({
server: "http://localhost:8080/jasperserver-pro",
scripts: "optimized-scripts",
logEnabled: true,
logLevel: "error",
auth: {
token: authToken,
preAuth: true,
tokenName: "pp"
}}, function (v) {
$scope.v = v;
$scope.reportingInitialized = true;
$scope.$digest();
}, function (err) {
alert("Auth error! Server said: " + err.message);
});
However, on successful authentication it is not redirecting to success url but returning the below html with HTTP code 200. Due to which the Authentication is failing with the error message as "Unexpected token <".
Appreciate any help on this.
<head>
<title></title>
<meta http-equiv="refresh" content="0;url=home.html">
<script language="javascript" type="text/javascript">
window.location="home.html";
</script>
</head>
<body>
If your browser doesn't automatically go there,
you may want to go to the destination
manually.
</body>
</html>
Here is the resolution for this issue for other's benefit:
The jsonRedirectUrl was missing in the applicationContext-externalAuth-preAuth.xml
<property name="jsonRedirectUrl" ref="authSuccessJsonRedirectUrl"/>
Also following lines need to be removed from this file to have the report show up without any error:
<!-- marker disabling JIAuthenticationSynchronizer: pre-5.1 external auth config-->
<alias name="${bean.authenticationProcessingFilter}" alias="proxyAuthenticationProcessingFilter"/>
Above solution is tested and working on Jasper Server 6.1
I have installed JRS 6.1 and :
The
was already in the applicationContext-externalAuth-preAuth.xml
And I have commented the "alias..." line
But still, when I do refresh my report page, the report is not displayed. I have to delete my cookies so that the report appears.
Did it really work for you ?
We found that the problem was that the first request establishes a session. If you send a new token with the second request while the first session is still active then the request fails. You need to modify your application to either continue to use the same token for the browser session or you could logout the user before sending the second request.
This is the expected behavior with visualize.js authentication so here are 2 options which I have through of using in my application
Approach 1
Reuse authentication call as per visualize.js documentation
use visualize.configure
visualize.config({
auth: {
token: "token",
organization: "organization_1"
}
});
then use visualize function to serve report 1 and report 2
// report 1
visualize(function(v) {
v("#container1").report({
resource: "/public/Samples/Reports/06g.ProfitDetailReport",
error: function(err) {
alert(err.message);
}
});
});
// report 2
visualize(function(v) {
v("#container2").report({
resource: "/public/Samples/Reports/State_Performance",
error: function(err) {
alert(err.message);
}
});
});
Approach 2
This approach which is not desirable. every time you want to show a report do following
send login call
serve the report
send a logout call
I am using Worklight 6.0 and in this case testing with iOS7.
I'm trying to setup saml 2.0 SSO with Worklight and I seem to have succeeded, but I don't know how it works... At first, I have my app attempt to access my url like this:
WLJQ.ajax({
url: 'url.com',
type: 'GET',
xhrFields: {
withCredentials: true
},
success: function(data, status, xhr) {
console.log(data);
},
error: function(result) {
console.log("error");
console.log(result);
}
});
The request goes to success and returns me the url of the login page, which is correct because I haven't authenticated yet, but it does not display the login (as I intended).
Next I click a button to display a Native page (iOS) which is a UIWebView of url.com. This displays the login page via:
WL.NativePage.show('LoginController', backFromNativeLoginPage, params);
I log in successfully and see the contents of url.com that I expect. Then I return back to the non-native app via:
[NativePage showWebView:0];
Now that I'm back in the non-native code, I sent the same request above and I expect for it not to return the contents of url.com, but rather the login page because I have no headers attached to my request and I think the non-native code shouldn't have any knowledge of the cookies I may have made in the UIWebView.
My question is how does this work? Does my non-native part of worklight have knowledge of all the cookies that were created in the native code's UIWebView?
Let me start by saying my answer is partly based on speculation, but I think this is whats happening:
Since your Native page is using the a WebView and Cordova is also using the WebView, any headers and cookies that your Native page is using will be visible when you return from native since cookies are shared across differet UIWebViews.
If your native page was using the native URL request methods or some third party / open source mechanism for connecting to your backend server, then I would think that your non-native page would not be able to see the headers and cookies.
$.ajax({
url: loginPath,
password: Password,
username: Username,
type: "GET",
error: function(xhr,textStatus,thrownError)
{
alert(textStatus+" "+thrownError);
},
success: function(data)
{
alert(data);
}
});
I am developing an application in Phonegap for iphone & android, my application needs to call web services at a point, now when i call the web service as above, the alert(textStatus+" "+thrownError); show only "error" the thrownError parameter is blank, all this happens when i run the application on the device/simulator, if i run my code on safari it works just fine without any error, but on the device it somehow screws up. Can some1 tell me what i'm doing wrong? or is there any problem with the web services.
P.S: when i say device i mean iPhone 3GS, as of now i am testing it on this device.
Try alert(xhr.statusText); in the error function.