Connection refused Cordova Android (localhost) - javascript

When running my App on Android, I get following Error message when trying to authenticate with the Spotify API (after redirecting back):
net::ERR_CONNECTION_REFUSED (http://localhost/index.html#access_token=...)
Logging in works, but redirecting back to my index.html form Cordova won't.
However, in the config.xml, I've set <content src="http://localhost/index.html" />, so exactly the same URL, just without the other params, and the index.html loads as expected. Even if I copy the URL I'm redirected to (where the error comes from) and paste it as the content src, there is still no error, so it's just the redirection I guess?
I also tried to set localhost to 10.0.0.2, but then I wasn't able to view the index.html

Related

Ionic/Capacitor React App API Requests returning HTML on iOS

The current behavior:
All API requests to the localhost server are returning the index.html file of the React.js app on the iOS build, but requests work fine on browser and PWA builds.
The expected behavior:
Requests return the intended data (usually JSON).
Details
Typically, API requests go to http://localhost:3000/api/[route]. In the iOS build, they are going to capacitor://localhost/api/[route]
Because the route is returning HTML and not JSON data, I am getting the following error (one of many, as each API route, has the same error) which causes a white screen:
TypeError: undefined is not a function (near '...a.map...')
I tried adding a hostname (location where the production server is hosted) to the capacitor.config.json file in my root directory, but it still fails. Dev API server is running on localhost:3000.
Tried setting the server hostname to "localhost:3000" in the config as well.
"server": {
"hostname": "localhost:3000"
},
"http" is not allowed as a iosScheme as mentioned in the docs for the capacitor config:
Can't be set to schemes that the WKWebView already handles, such as http or https](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler)
Because the site works on every other build other than this iOS build, the issue should be here...
How can I route my requests on the iOS build to direct to the correct location?
Update
If I set the server.url option in the capacitor.config.json file to https://www.website.com, I'm able to pull data from my production server, but when the authorization check returns a 401, the app seems to hang on the splash screen and the only error-like message I get in the console is that the response returned a 401 (as expected)
Device console output:
XCode console output:
The first issue was fixed by setting the server.url parameter in the capacitor.config.json file to the URL of the production server:
"server":{
"url":"https://www.website.com"
}
Second issue was making sure the splash screen hide code from #capacitor/splash-screen was actually deployed onto prod in the index.js file.
import { SplashScreen } from '#capacitor/splash-screen';
setTimeout(() => {
SplashScreen.hide();
}, 2000);
By the little information you have provided I'll try to guess what's wrong.
You are using relative urls instead of absolute urls. If you make a XHR/fetch call to /api/[route], the browser will append the scheme and host name to it and will turn it into capacitor://localhost:3000/api/[route]. That url belongs to the app, not to the web server where you API is running.
You are using localhost, localhost means "this machine", if you run the app in a browser or iOS simulator, localhost is the machine where the browser and simulator and browser are running, and the local server is also running on the same machine, so they don't have any problem accessing it. But if you run on a real device, localhost is the device, and the device doesn't have a server running. You should use the local IP (numbers) of the computer where the server is running, and the device should be connected to the same network for being able to access it.
Capacitor apps are "affected" by CORS, you need special server configurations to allow the connections https://ionicframework.com/docs/troubleshooting/cors.
Looks like you are on the point 1, once you fix it you'll hit point 2 and then probably point 3 after that.

Facebook Login using Cordova / React

I have recently implemented Facebook Login using a plugin called react-facebook-login.
It works perfectly in a browser running on localhost. However when I build to device using cordova, I get the following error:
Application Error
net::ERR_FILE_NOT_FOUND
(file://www.facebook.com/dialog/oauth?client_id=***...
I assume the issue is the file:// before the facebook url which comes from Cordova I believe.
The Component looks like this:
<FacebookLogin
appId="my-app-id"
autoLoad={false}
fields="first_name,last_name,email,picture,birthday,location{location{country, country_code, city, region}},gender"
scope="public_profile, email, user_birthday, user_location"
callback={LoginWithFacebook}
/>
Do I need to set a redirect uri? seems to be set to file:///android/.../index.html at the minute.
You'll need to modify the plugin to use https: here
window.location.href = `https://www.facebook.com/dialog/oauth${getParamsFromObject(params)}`;

Javascript file type displayed as 'html' in console

I'm checking under network tab on a site. In my local host it works correctly. But I doubt the site's hosting provider has some setting that is not fulfilled by my script file.
I get 403 - permission denied error for all my js files in this server.
Additionally when I opened the network tab, I found the following:
Domain = the sites domain
Cause = script
Type = html
The site also has other plugins where the js file's Type = js and it rendered correctly(status = 200).
I suspected the server might be using old html, so I specified type="text/javascript" for it to be recognized as js file. yet it doesn't help.
This is a joomla site and my plugin is a system plugin. Does this has anything to do with my script?
Exact error I'm getting:
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /plugins/system/conversekit/assets/js/conversekit.js
on this server.<br />
</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

Pimcore: Getting the White-Screen-of-Death after successful admin login

I've installed Pimcore on a VPS through Liquid Web. I loaded the sample data install which also uses the nightly build code. While everything installed fine, the public facing website appears fine and functions well, as does the login screen for the admin panel, once you log in, you see three black pulsing dots in the middle of a white screen, where eventually they disappear and you're simply left with a white screen.
Upon inspection of the error console, I'm seeing this error:
Failed to load resource: the server responded with a status of 404 (Not Found)
/website/var/tmp/minified_javascript_core_b18dd1d6984052da2ab5abc79f0c4a17.js?_dc=3704
Other scripts are also failing because this script isn't being loaded, so I'm fairly sure that once this script loads the others will work just fine.
When I try to directly access this JS file, I see this message:
HTTP/1.1 404 Not Found Filtered by error handler (static file exception)
I have verified that the file exists in the filesystem, so I know for sure that it's there, leading me to believe that the filesystem has that directory and/or file locked down. Permissions etc, are all set to their appropriate values.
Pimcore Version 4
It's been a few years and this project surfaced in our pipeline again. The actual cause for why this breaks was because we are also running the ModSecurity suite on our host. Accessing the interface .js file was triggering rule 2000009 where the pattern /var/tmp was being matched.
Possible solution (if you're using WHM/CPanel as we are):
Configure your /etc/apache2/conf.d/modsec2/whitelist.conf file to include the following rule (add more in the same place if needed).
<LocationMatch '/website'>
SecRuleRemoveById 2000009
</LocationMatch>
Be sure that you restart your HTTP service after making this update.
Enjoy!

Google Login For Phonegap

After the authentication page does not return the redirect url and showing 404 error. I need the run project in mobile . I am building with phonegap but mobile does not have localhost. how to define local file to redirect_uri ?
Returns This url after
http:// localhost /cevap/redirect.html?state=%7B%22client_id%22:%2275055614045-a999nkehht0jk3i46548qg32imu0toqg.apps.googleusercontent.com%22,%22network%22:%22google%22,%22display%22:%22popup%22,%22callback%22:%22_hellojs_8ws7jbej%22,%22state%22:%22%22,%22oauth_proxy%22:%22https://auth-server.herokuapp.com/proxy%22,%22scope%22:%22friends,basic%22,%22oauth%22:%7B%22version%22:2,%22auth%22:%22https://accounts.google.com/o/oauth2/auth%22,%22grant%22:%22https://accounts.google.com/o/oauth2/token%22%7D%7D&code=4/x9MedwZ8NJN6qUgq2rXAVaBtFuOk.QpP5N0crfbAbYFZr95uygvVVqe1rjwI&authuser=0&num_sessions=1&hd=veriyazilim.com.tr&session_state=f715c83530f60300552e4920948401332014eeea..224b&prompt=none
hello.init({
google : '75055614045-a999nkehht0jk3i46548qg32imu0toqg.apps.googleusercontent.com'
}, {
redirect_uri : 'http://localhost/cevap/redirect.html',
response_type:'code',
scope:'friends'
});
I created Client ID for web application in google .
This is my folder directionary :
For developing in a desktop browser:
A dev domain is required which matches the domain you defined as a callback url when registering your app - define this callback url in redirect_uri, and ensure it points a document containing ./hello.js.
in your case this file would be located at http:// localhost /cevap/redirect.html
For phonegap this isn't the case as apps are run as "file://path/to/installed/apps/myproject" or something. But phonegap apps can watch the URL of popup windows it intitiates, and thats exactly how hello.js works to extract the access_token from the popup windows querystring. in this case there is no need for the redirect_uri to be a valid path, but for a better user experience i would have it point to a web resource which can display something like a spinning wheel.
Problem does not in url.
inappbrowser doesnt load to project. I changed config.xml plugin to this and inappbrowser loaded and problem fixed.
<gap:plugin name="org.apache.cordova.inappbrowser" />

Categories