This repo is a workshop as a part of the GeoNode Summit in 2020
If you have GeoNode in your environment or considering it as a solution, then you might want to add additional functonalities to it in the future. Possible functionality would be to have a mobile client for your GeoNode backend that users can download and use directly, perhaps add data collection capabilities to that mobile client and send it to GeoNode, or even send push notifications to your users with updates. You can develop your own backend system (php - node - etc...) which consumes resources from your GeoNode directly with the discuess concept in this workshop.
- Developers
- Business Owners
A basic knowledge of the following is needed to proceed with the workshop
- Node - React
- Android Studio (to make the android app) - xCode (to make the iOS app)
masterThe starting point of this workshop.completedThe complete working project.
Please follow the below steps (on master branch to complete the workshop):
The GeoNode instance you're using must have the CORS enabled for this to work.
The GeoNode instance that will be used for the workshop has all the needed configurations.
-
Log in to the GeoNode backend and register the mobile app in Django oAuth Toolkit through GeoNode admin (replace GeoNodeHost with your actual host address) https://[GeoNodeHost]/en/admin/oauth2_provider/application/
- Create a new application.
- Set
Client typetoConfidential. - Set
Authorization grant typetoResource owner password-based. - Set
NametoGeoNode Mobile. - Copy the auto generated
Client idandClient secretinto a side note, both will be used later. - Hit
Saveto create the oAuth application.
-
Clone/Download the code from the repo https://github.com/Cartologic/geonode-mobile-sample.
git clone https://github.com/cartologic/geonode-mobile-sample.git
-
Open the code in your IDE and open the file
src/config.ts. -
Set the
authenticationClientIdto theClient idvalue from step1. -
Set the
authenticationClientSecretto theClient secretvalue from step1. -
In your terminal, install the dependencies
npm install
- Start the app
npm start
You should have the app up and running in your browser at http://localhost:300 by default.
-
Adjust the view in the browser. Open the dev tools, and choose mobile view and set it to either and Android device or iOS device.
-
Test the authentication by using the app to login to GeoNode by a user in the system. (workshop username: demo and password demo).
-
The app should login successfully and you see the profile picture of the user visible in the menu. If you click on the picture, that should take you to the profile page to see some information about the user retrieved from GeoNode.
-
To see how the
Authenticationworks, open the filesrc/context/Authentication/AuthenticationContextProvider.tsxand check theloginHandlermethod. -
To Enable Authorization on requests such as the
Get Layersrequest. Open the filesrc/pages/Home/Home.tsxand add an authorization header to the Get request at line47.
Instead of
const layersCountResponse = await axios.get("/api/layers");
Replace with
const layersCountResponse = await axios.get("/api/layers", { headers: { Authorization: `Bearer ${token}` } })
This will send the user Access Token along with the Get request and GeoNode will identify the approperiate resources to show accordingly.
- Repeat step
12again in theLayerspage to show theauthorizedlayers only. Open the filesrc/pages/Layers/Layers.tsxand add an authorization header to the Get request at line50.
Instead of
const response = await axios.get("/api/layers", {
params: {
order_by: sortLayersBy,
},
});
Replace with
const response = await axios.get("/api/layers", {
params: {
order_by: sortLayersBy,
},
headers: {
Authorization: `Bearer ${token}`,
},
});
- Try doing the same for the
MapsandDocumentspages on your own.
A postman collection is available in the repo to see the requests (login - logout - get layers) outside of the code.
- Open Postman app, and import the postman collection from the repo inside the
apidirectory. - From the Postman app, test
LoginandLogoutrequests to seeAuthentication, then test theGet Layersrequest to see theAuthorizationconcept.
username: demo
password: demo
For detailed instructions, please refer to the official documentation https://ionicframework.com/docs/developing/android
Generate code build, then create an Android project.
npm run build
ionic capacitor add android
ionic capacitor open android
