Communication between a Mac app & local website/server - objective-c

I want to control a mac app via a local website. I think the best way is to create a webserver with my mac app and then to send (primarily) integer values from the website and vice versa.
I found already CocoaHTTPServer, but I'm not sure how to do it.
For start with I want to have a slider on the website, that updates a slider in my mac application (and vice versa)

You will initiate on a separate thread or operation the web server and always wait for incoming requests. Whenever you receive a request you will handle it accordingly.
Also, if you are using this: https://github.com/robbiehanson/CocoaHTTPServer/
then there are a few examples that show how to do it. Copy the code from there to begin with the web server handling requests. After that, think through what you want to send and what you want to do. Build a form or something for the web site and submit a request to the web server.

CocoaHTTPServer will let you embed the web server into your application, which is a fine solution for what you're trying to accomplish.
Some thoughts on how to engineer it:
You'll need to subclass HTTPConnection.
Model your solution on the PostHTTPServer example.
You could get the data you want to send into the URL. Something like POST http://localhost:12345/updateSlider/123. (You probably don't need an actual POST, but no reason it wouldn't work. Technically a PUT would be more correct.)
Start by handling that part – where the browser sends a value to your application. To generate POST/PUT requests for testing purposes, use curl, or else build a static page and open it in your browser.
When you get that working, then worry about presenting a web page to the user.

Related

Authentication with Vue/Electron Application

I'm building an application with Vue and Electron, and I'm wondering what the best approach is for authenticating users.
I'm using JSStore as a wrapper for IndexedDB as my database. I'm familiar with using bcryptjs as a means for authenticating users when I create Node backend and have traditional /login or /signup routes.
But this is where I'm starting to get confused. Do I need to set up a Node server to start up when my application starts up? Because given that I'm using IndexedDB, I don't know that it makes sense to have a process of Sign Up --> Request to Node Server --> Send data back to browser
Would I be better served using a different type of database? Could I do something such as adding bcryptjs to the Vue prototype, so that's it's accessible where I need it to work with JS Store? Are there security concerns that I should be aware of with an approach like that?
At this point I'm stuck, and have more questions than answers. I've done some looking around for articles, and I find a lot of content about setting up authentication with Vue, but not within the context of an Electron application. I'm not sure how that variable changes things.
Any advice or direction would be greatly appreciated.
JsStore is client side technology, which means if you are setting up authentication in client side, it will be available only to that device.
Let's understand it more by use case -
Say your application named My Awesome app has authenticaion implemented. User register it and then they are able to use it after registration. They are logging out and signing in again with registration data and everything is working normal.
Here is what wrong with this approach -
User buys another pc and installed application My Awesome app, he tries to login but unable to login because registration data does not exist on their new PC.
Due to some issue, user hard disk crashed & he installed new hard disk. Same thing as above he is not able to log in.
So it is recommended to implement the signin on some server & keep data there.

Google OAuth: custom scheme for desktop app

I'm trying to authenticate a desktop application with OAuth. I already asked a question, but I deleted it as I discovered that the method was obsolete (integrated web view).
The idea is to open the browser and then have the page call back my application with a custom:// URI scheme.
Of course it doesn't work, Google asks that the scheme contains a dot (like com.org.myapp), but the native app can only have a fmp:// uri scheme, which I can't change.
The documentation doesn't mention anything, and I can't create a local temporary server.
1- Can I use the fmp:// scheme as a callback in any way?
2- If not, is it possible to redirect the call to another centralised web server? Everything I try generates a 400 error on the google page, saying "redirect_uri_mismatch" or similar stuff.
As stated in the comments above, the only solution is to create an intermediate web server that serves a page which then opens the URL. OR creates a record in the database with the authentication code.

IBM Worklight 6.0 - URL shortening

I have build a simple web app using Worklight.
My apps Preview URL is :
//local.loc:9080/Mobile/apps/services/preview/MobileAPP/common/0/default/MobileAPP.html
Shortend URL (with bit.ly credentials) is: http://bit.ly/153qbvr
Here the domain is completely different (bit.ly).
But actually I am looking for URL like : http://local.loc:9080/Mobile/MobileAPP.html.
Are there any ways to get a URL for public access like:
//:/application-name/launch_App_.html
if not, let me know ways to reduce the URL - if any.
The first URL you've mentioned is internal. It is meant for preview (development time mostly). Why would you be interested in shortening it? What is the value of doing so for you?
Also note that the shortened URL provided by bit.ly when using this service via Worklight - IS NOT the same URL as the first one (preview), it is meant for the Mobile Web environment, meaning for users who use their mobile browser app to access your app.
In short (no pun intended...), no, there is no way to do what you are asking for via Worklight - you cannot tweak the URL.
Let me re-iterate, the preview URL (the one mentioned in your question and that you want to shorten) is for the administrator or developer. It is NOT MEANT TO BE PUBLICALLY USED in any capacity, shape, form.
If you want to provide a web-public link to your app, add the Desktop Browser environment to your application. This environment is meant to access the app from a regular Desktop (PC/Mac) browser app. Note that even in this case, you cannot shorten the URL via a tweak in Worklight.
What you can do, is install some custom shortening service of your own in your company's servers and create your own custom URL that will look the way you want it to.

Stripe and titanium mobile

How can I intergrate the stripe api for payment processing to allow people to pay for services through my titanium mobile app. Stripe.com
I am using this code to start:
https://github.com/abh/node-stripe/blob/master/lib/main.js
How can I make sure the information is encrypted.
First you need to make sure what you are selling is physically tenable, assuming it is (and your not selling any form of digital content, or functionality within the app) then the easiest way to use stripe from within Titanium would be to just wrap it in a web view (you could implement it in native code but this could get tiresome).
Assuming you have this example in a file called index.html in your resources directory.
var webView = Ti.UI.createWebView({
url : 'index.html
});
win.add(webView);
Note that you will need to let your server support https requests for actual encryption to happen, you shouldn't be encrypting yourself (in code).
Once this is done, all the work now happens on your server to process payments using Stripes libraries like in this example in the documentation.
Really this is a server job, all your doing is sending the server the information to process, not a lot going on with Titanium here except as a gateway.

To build an App for an Internet site without its API and Schema

I was asked to build a control-system for a Ebay-like Finnish auction-site huuto.net.
The system would reopen closed auctions by a specific rules. It would be completely external from the main site, running at an external website.
The site is however unwilling to release its API and Schema. I know no way to build such a system without knowing its API.
How do you build an internet site without its API and Schema?
You could try some form of automatic browsing: mechanize
Edit:
Examples here.
I think you're asking about building a site that interacts with another site without using a well-defined API. Is that right?
You can interact with an external site without using an official API - in order to do so, you need to imitate a normal site visitor and send your requests to the site frontend (in much the same way as a web crawler does). Tools like hpricot, mechanize and curl can help you parse the content of pages and send requests, but in doing so your system may be quite brittle. Any change to the target site might mean you have to rewrite portions of your system.
It might be possible to get the data you need by screen scraping the site. You could perform the operations you want to do by POSTing data into their forms or using a WebClient type API to make your program act like a web browser but that's likely to be an extremely brittle solution.
Honestly though, without an API, there really is no good solution.
you either need access to the database or an API, otherwise no point in even trying.