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)
master
The starting point of this workshop.completed
The 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 type
toConfidential
. - Set
Authorization grant type
toResource owner password-based
. - Set
Name
toGeoNode Mobile
. - Copy the auto generated
Client id
andClient secret
into a side note, both will be used later. - Hit
Save
to 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
authenticationClientId
to theClient id
value from step1
. -
Set the
authenticationClientSecret
to theClient secret
value 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
Authentication
works, open the filesrc/context/Authentication/AuthenticationContextProvider.tsx
and check theloginHandler
method. -
To Enable Authorization on requests such as the
Get Layers
request. Open the filesrc/pages/Home/Home.tsx
and 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
12
again in theLayers
page to show theauthorized
layers only. Open the filesrc/pages/Layers/Layers.tsx
and 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
Maps
andDocuments
pages 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
api
directory. - From the Postman app, test
Login
andLogout
requests to seeAuthentication
, then test theGet Layers
request to see theAuthorization
concept.
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