Building Server-client application with CakePHP and Android - php

I'm currently building an application on Android that allows user to register a location-based service. I'm pretty new in both server-side programming and Android. Therefore I need some suggestions to point me to the right direction.
Concretely, my Android application will allow users to register, login, and update their profile and settings on the server side, and I'm using Apache as my server.
My idea now is using CakePHP on the server-side, and use JSON/XML format to communicate with the Android App via HTTP POST and response. I don't want to rebuild everything like authentication from scratch, however I can't find any CakePHP plugin that work for me. I've tried CakeDC and Authake. CakeDC seems incompatible with current CakePHP version. For Authake, I've followed the steps on the Authake Tutorial, however, the register and login page do not work. (I can't use admin to login as well.)
Summary
1. Is this server-client architecture feasible?
2. Can anyone point me to an CakePHP authentication/registration plugin which is compatible with current CakePHP?

Seems feasible to me. Though you might have to build a REST or
similar interface if you are letting users log in remotely through
the web interface.
I used the User Management plugin for my auth-based CakePHP programs and really like it.

Related

Configure a completely separated front and back end web app with Laravel and VueJS

I'm planning on creating a multi-page web app using Laravel as a back-end REST API and a Vue.js front-end to consume this API.
To be clear up front, I'm not interested in code snippets of exactly how to set this up, unless some will help visualize the architecture.
What I would like to know is how this 'Split-Stack' can be deployed in a completely separated manner. I.E. neither stack shares a codebase, and are stored in completely independent repositories.
I'm not very familiar with JavaScript frameworks beyond jQuery, so I think my lack of understanding lies mainly in the Vue.js department. Some questions which stand out in particular are:
Can a Vue.js application be hosted by a web server to serve static HTML files, if so, which one is compatible?
Can both the front and back end services run on the same server, on different ports for example, and what would be any best practices for this?
And how is login authentication affected by running a web app in this way, and should I be looking into creating some kind of OAuth authentication between the front and back ends?
After reading many blog posts, it is obvious that this architecture is possible, but I'm struggling to find details on how exactly this is configured to be completely separate.
The tools and technologies don't necessarily matter here, but any specifics for Vue.js and Laravel are appreciated.
I have a VueJS Front-End set up with an ExpressJS Back-End, which is very similar to what you are talking about. And yes, it is entirely possible. So let's take a look at each of your questions individually.
Can a Vue.js application be hosted by a web server to serve static HTML files, if so, which one is compatible?
Yes, when you run VueJS, you can either build it as a static application or serve it as a NodeJS Application.
See the Deployment section of the Vue CLI 3 documentation here. It explains how the /dist directory is used to serve the VueJS Application in the manner you are intending to.
Can both the front and back end services run on the same server, on different ports for example, and what would be any best practices for this?
I recently posted an example of how to host both your Front-End and API on the same server here. (Includes Coding Examples and Explanation). This answer references ExpressJS as the API, but the principles are the same. Really, just have your Front-End listening on port 80 and have your API operating on a different, unused port (ie: 8081).
And how is login authentication affected by running a web app in this way, and should I be looking into creating some kind of OAuth authentication between the front and back ends?
I handle all authentication on the back end. Basically, in the Vue Router, you can set a secure parameter. Then declare a router.beforeEach((to,from,next) => {}); call towards the end. This call should then check to see if the user has a valid login token and redirect them to the applications login page after setting a cookie with the URL the user was asked to login from so that they can be sent back to it after logging in.
In our case, we have the user redirected to the VueJS Route /saml/login. The /saml/login component. This component makes a call to the API and returns the address the user should be redirected to to login. In our case, it is the API (which is running on the same server, but a different port [see answer above]), www.example.com:8081/api/v1/saml_login. This then works with the IDP and receives the token and user data. This is also where you would perform you ACS functions (provisioning the user, updating the login time or user data, etc.) After receiving the token, it is placed into a cookie or other placeholder so that it can be used to validate against the token stored in the Database when the user was validated initially. (It is a best practice to set expiration's on your tokens). The user is then redirected to the url stored in the cookie that lets us know where they were asked to sign in from so they can view their content without having to look for it again. (Happy to share code on this if you want)
I think using Firebase or Auth0 Authentication is one of the best ways to do this. Firebase or Auth0 will take care of all the authentication for you and allow your backend to verify the authenticity of your front end. So that makes it much easer to separate the two.
There is an admin SDK for connecting Laravel to Firebase and there are templates and existing authentication SDK's for Vue. There are a few articles which sort of describe it but I haven't seen anything that pieces it all together yet. I was able to figure it out from 2 or 3 different articles and it ended up being easier than I thought it would be.

iOS app tweaked for server connection

I'm currently developing an iOS app and have reached the point where I need to implement a server back-end in order to support the core functionality.The app is built in a way to store certain questions locally (Within the app) and pose the questions to the app user. I need to tweak it such that it retrieves the question from a remote server. Furthermore, the question will reside in a specific folder within the remote DB. So the app will have to fetch the questions from the appropriate folder based on user login.
I have zero server experience and am need of some advise as to where I should begin with this. I would like to know if there is a template spec for this kind of task. With a template spec, I can hire a programmer and talk intelligently. Please help!
Here is a number of solutions:
1) You can use other services that provide backend functionality with REST API (as #Niklas Hein mentioned), it calls BAAS - backend as a service, such as Parse (but Parse is closing his service in one year), BaasBox, etc.
2) You can use CloudKit. This is service created by Apple, where you can store app data in the cloud, with authorization, requests, admin panel, etc.
3) Create you own back end. Here is a large number of languages and web frameworks, so php is not the only one solution. Ruby on Rails, Python Django, NodeJS, and many others on your choice.
There are plenty of BAAS (Backend as a service) provider, like Parse or Firebase. You might want to have a look into them. (Although Parse is going to shut down.)
Another simple way is to look into PHP Laravel.
Laravel is a great Framework which makes it really easy to set up a backend.
Have a look at Laracast

How to pass authentication credientials to php application from a WPF app

I have WPF app and Web browser control in it. I am opening a web page which is a php application.
I need to pass my machine credential's to the php application.
The Web browser control opens a [http://app/login.php]. The user has logged onto the machine with his domain credential's. The PHP website uses windows authentication..
Both the WPF application and php site are internal application(i.e. same domain)
You have a CakePHP application and a login.php? Then there is something seriously wrong with it.
You need to get your current logged in users identity and pass that on to the php application.
See Using windows authentication with php?
If you're using CakePHP 2.0 you might find an LDAP adapter for the AuthComponent. I guess you can use google to find more, I don't know if this one here is any good or not http://www.analogrithems.com/rant/2012/01/03/cakephp-2-0-ldapauth/
My answer covers the CakePHP part
Best practice would be to communicate using REST, between your wpf and cakephp. CakePHP provides a very easy way to connect your actions via REST. You will have to connect your authentication method using the REST.
Cake's documentation has a nice section on REST from CakePHP.

Moodle Integration with a PHP project of mine

I've been developing a project using php that my students use to take quizes (that moodle can't do itself) Now I would like to integrate moodle and my project such that my project authenticates against moodle users and reports grades into a courses gradebook. I've so far been authenticating using direct database reading but I'm very hesitant to do writes to the moodle database. I'm also aware of LTI; I am open to using it but the human readable documentation and any samples are impossible to find. If you could provide me a sample or documentation thats less theory and more applicable for LTI it would be greatly appreciated.
Thanks in advance.
To do this you need to use the Web Services API. You need to setup a web service first, see Using web services. The entire API documentation is available on your Moodle site via Administration > Plugins > Web services > API Documentation.
You need to use moodle's External Tool, which is created precisely for this kind of uses. External tool uses LTI in the background to send user, course, role etc information to an external application and the external application can even send back scores to moodle if configured as a quiz.
Check out : https://docs.moodle.org/23/en/External_tool
You will also have to make your quiz taking app, an LTI provider.
This open source package is out of the box package to create LTI provider in ruby - https://github.com/instructure/ims-lti
There are similar tools in other languages too, but this one is the most polished one.

Accessing Wordpress remotely

I was in the process of developing an app in Titanium Mobile. (It's a great way to develop apps btw if you're a web dev).
This app communicates and gets data from a Wordpress server.
(In case you're not familiar with Titanium Mobile, I request you to keep reading the question. Knowledge of that platform is not necessarily important in this case. Thanks)
After a lot of research I finalized on the Wordpress JSON API as a method of communication between the app and the server.
I've got it all up and running successfully and it's great. So far so good.
Now the problem is that my app requirements exceed the functionality provided by the JSON API.
For example, I would like a user to "log in" and maintain a session while using the app. He should be able to edit his Wordpress profile info, etc.
I just want to have an idea how I would be able to best implement this.
One way could be to have a php script running on the server which handles each and every function. Another could be to manually edit the JSON API to add more functionality to it. But that'll take time and I haven't developed a Wordpress plugin before.
Can anyone suggest me a better or easier way of doing the above? I hope I've described what I'm looking for. Apologies if it's too long. I wanted to best explain it.
Thanks for the help in advance!
Wordpress has a XML-RPC interface already, no need to re-invent the wheel.
Wordpress XML-RPC SupportCodex
Wordpress XML-RPC APICodex

Categories