Project

General

Profile

API Authentification » History » Version 7

Kurt Gerber, 09 Jan 2020 21:00

1 1 Kurt Gerber
h1. API Authentification 
2
3
The following is a proposed authentication mechanism for handling mobile app requests. This is to facilitate other API endpoints allowing users to create cases, upload images and edit cases.
4
5 4 Kurt Gerber
h2. User authentification and authorisation
6 1 Kurt Gerber
7 4 Kurt Gerber
* Use the existing API Token for application authorisation
8
* Use a second token for the user authentification. This can be solved bei either one of the following options:
9
** A: Using the existing django-based session ID, same as the web gui.
10
** B:  Create a Secondary authentication table, as follows:
11
*** One to many relationship to the Registered UserID (different mobile devices should be possible)
12 5 Kurt Gerber
*** 3 fields --> 'UserID', UserToken' & 'time_stamp'  
13 4 Kurt Gerber
* When an API request to create a case, upload images or edit cases is received, follow the following use workflow:
14
#  Authenticate with the API Token to ensure user has access to API
15
#  Check if the Authenticated User has an 'unexpired' UserToken
16
## A time limit is used to designate stale/fresh User Tokens
17 1 Kurt Gerber
18 7 Kurt Gerber
* *Use case 1: User has no UserToken:*
19 4 Kurt Gerber
# User has to authenticate to receive a UserToken 
20
# Response is sent and the UserToken is included. This is the initial handshake
21
# Time stamp is updated
22
23
* *Use case 2:  User has an Unexpired UserToken:*
24
# Request is accepted
25
# Time stamp is extended
26
# Response is served
27
28
* *Use case 3: User has an Expired UserToken:*
29
#  User is re-authenticated with the API Token
30
# UserToken is refreshed
31
# Response is sent and the new UserToken is included
32
#  Time stamp is updated
33
34
* *Use case 4: User has Incorrect UserToken:*
35
#  Invalid Response is sent
36
37
38
h2. Case locking mechanism
39
40
*Problem:*
41
* The web application contains a locking mechanism: A draft version is locked as long as a case open in an editor/form. (* Timeout?*)
42
* This locking mechanism doesn't work with an offline application, because:
43
** The server only knows when he sends or receives data, but it can't tell, if sent data is used for editing or view only. 
44
** Locking as long as the application is offline won't work, as that can take days.
45
46
* *Possible solutions:*
47
48
49
* The server receives case data (JSON)  as POST on  respective API endpoint (for a certain configuration/identifier):
50
51
# Checking, if the latest version of the case is either _'active'_ or  _'draft'_
52
# When latest version is _'draft'_, compares the last update timestamp to the timestamp of the UserToken 
53
54
* *Use case 1: The latest version is _'active'_: *
55
# Creates a new draft version with the sent JSON
56
57
* *Use case 2: The latest version is not _'draft'_ and not _'active'_:*
58
# Data upload is rejected with: 'Case under review. Can't be updated'
59
60
* *Use case 3: The latest version is _'draft'_:*
61
# Checks if timestamp of last update on server is newer than the  UserToken timestamp
62
63
* *Use case 4: UserToken timestamp is newer than update timestamp on server:*
64
# Merge sent JSON to draft version.
65
66
* *User case 5: Update timestamp on server is newer than UserToken timestamp:*
67
# Case was updated over another device / or over website
68
# Data upload is rejected with: 'Newer version exists.'