You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/reference/qfieldcloud/auth.en.md
+87-10
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,8 @@ QFieldCloud and QField / QFieldSync clients allow authentication using regular u
13
13
14
14
OIDC can be used directly for signing up with QFieldCloud, or for signing in to an existing QFieldCloud account (matched via verified email address).
15
15
16
+
### QFieldCloud (Web)
17
+
16
18
Here is a sequence diagram of how a third-party login happens in QFieldCloud (in the browser):
17
19
18
20
```mermaid
@@ -52,6 +54,8 @@ sequenceDiagram
52
54
QFC -->>- User: Log user in (establish session)
53
55
```
54
56
57
+
### QField / QFieldSync
58
+
55
59
Here is a sequence diagram of how third-party authentication happens in QField and QFieldSync:
56
60
57
61
```mermaid
@@ -65,28 +69,31 @@ sequenceDiagram
65
69
66
70
User ->>+ QF: Open the QFieldCloud login dialog
67
71
68
-
QF ->> QFC: Ask for configured third-party ID providers
69
-
QFC -->> QF: Answer with the list of configured third-party ID providers
70
-
QF -->>- User: Display a button for each third-party ID provider
72
+
QF ->> QFC: Ask for list of identity providers
73
+
QFC -->> QF: Answer with list of identity providers
74
+
QF -->>- User: Display a button for each identity provider
71
75
72
76
User ->>+ QF: Click on 'Login with XYZ' provider button
73
77
74
78
Note over QF: A QgsAuthMethodConfig of type OAuth2 is created<br/>QGIS auth manager recognizes that the user is not authenticated yet<br/> QGIS auth manager then redirects to the IDP for authenticating the user
75
79
76
-
QF ->>+ IDP: Redirect to IDP for login
80
+
QF ->> IDP: Redirect to IDP for login
77
81
IDP -->> User: Display IDP's login form in a browser
78
82
User ->> IDP: Log in using IDP's credentials in the browser
79
-
IDP ->>- QF: Answer with auth details and an id_token token
83
+
IDP -->> QF: Answer with authorization code
84
+
QF ->> IDP: Exchange authorization code for access token and ID token
85
+
IDP -->> QF: Answer with access token and ID token
86
+
QF ->> QFC: Use ID token to authenticate user
87
+
88
+
Note over QFC: Validate ID token signature
80
89
81
-
QF ->>+ QFC: Ask for current user's informations
82
-
Note over QF,QFC: The id_token provided by IDP is in in the X-QFC-ID-Token HTTP header<br/>The IDP provider type (e.g. "google") is in the X-QFC-IDP-ID header
90
+
QFC -->> QF: Establish user session and return user info
83
91
84
-
QFC -->>- QF: Answer with user information (username, avatar, etc.)
85
92
QF -->>- User: User is logged in and authenticated
QF ->> QFC: Send a request (e.g. file Download/Upload)
89
-
Note over QF,QFC: The id_token provided by IDP is in in the X-QFC-ID-Token HTTP header<br/>The IDP provider type (e.g. "google") is in the X-QFC-IDP-ID header
96
+
Note over QF,QFC: Tokens are attached to requests in HTTP headers
90
97
QFC -->> QF: Reply to the request
91
98
end
92
99
@@ -95,3 +102,73 @@ sequenceDiagram
95
102
IDP -->> QF: Send a refreshed token
96
103
end
97
104
```
105
+
106
+
#### Details
107
+
108
+
1.**Open the QFieldCloud login dialog**
109
+
User clicks on the QFieldCloud login button in QField / QFieldSync<br/><br/>
110
+
111
+
2.**Ask for list of identity providers**
112
+
Query the QFieldCloud `api/v1/auth/providers` endpoint for a list of enabled identity providers, and their configuration details.<br/><br/>
113
+
114
+
3.**Answer with list of identity providers**
115
+
Return the list of enabled identity providers.
116
+
For each IDP this will include information to render the UI (title, logo, colors), and also the necessary OIDC configuration details for the given IDP. These include properties like the client ID, token URL, etc. for QField/QFieldSync to connect to the IDP.<br/><br/>
117
+
118
+
4.**Display a button for each identity provider**
119
+
For each enabled authentication method a login button is rendered.<br/><br/>
120
+
121
+
5.**Click on 'Login with XYZ' provider button**
122
+
User clicks the button to log in with a particular provider.
123
+
At this point, QField/QFieldSync will create a new `QgsAuthMethodConfig` of type OAuth2, and will use the OIDC configuration details received from QFieldCloud to configure it.<br/><br/>
124
+
125
+
6.**Redirect to IDP for login**
126
+
QField/QFieldSync will then open a browser window and send the user to the IDPs login page.
127
+
In the URL for that login page a redirect_url is included which points back to the callback at which QField/QFieldSync will receive the IDP's response that will include the authorization code.
128
+
For that purpose, QField/QFieldSync will spawn a temporary web server at `http://localhost:7070` which will receive that callback.<br/><br/>
129
+
130
+
7.**Display IDP's login form in a browser**
131
+
The IDP presents the user with a login page and a consent form.<br/><br/>
132
+
133
+
8.**Log in using IDP's credentials in the browser**
134
+
The user authenticates to the IDP, using whichever authentication method the IDP supports (username/password, client certificate, session, ...).<br/><br/>
135
+
136
+
9.**Answer with authorization code**
137
+
The IDP will redirect the user's browser back to the redirect_url, where QField/QFieldSync's temporary webserver will receive the callback, which includes the long lived OIDC authorization code.<br/><br/>
138
+
139
+
10.**Exchange authorization code for access token and ID token**
140
+
QField/QFieldSync will send the authorization code to the IDP's token endpoint, and exchange it for ID token, access token and refresh token.<br/><br/>
141
+
142
+
11.**Answer with access token and ID token**
143
+
The IDP verifies the authoritation code (with the addition of PKCE), and responds with ID token, access token and refresh token, which are short lived.<br/><br/>
144
+
145
+
12.**Use ID token to authenticate user**
146
+
QField/QFieldSync will send the ID token and access token to QFieldCloud, and request the user's profile information.<br/><br/>
147
+
148
+
13.**Establish user session and return user info**
149
+
QFieldCloud will verify the ID token's signature and authenticate the user. If successful, it responds with the user's profile information and a user session.<br/><br/>
150
+
151
+
14.**User is logged in and authenticated**
152
+
QField/QFieldSync will receive and store the user's profile information and authentication session.<br/><br/>
153
+
154
+
155
+
156
+
#### Request loop
157
+
158
+
15.**Send a request (e.g. file Download/Upload)**
159
+
Once a user has authenticated with the IDP, and QField/QFieldSync has received the OIDC tokens, it will attach the ID token and access token in subsequent requests to QFieldCloud as HTTP request headers.
160
+
(Technically speaking, it's actually the QGIS auth manager which will do this).
161
+
The access token is included as an `Authorization: Bearer <access_token>` HTTP header, and the ID token is included in the `X-QFC-ID-Token` HTTP header.
162
+
The IDP provider type (e.g. `google`) is included in the `X-QFC-IDP-ID` HTTP header, to let QFieldCloud know which IDP the token needs to be verified with.<br/><br/>
163
+
164
+
16.**Reply to the request**
165
+
QFieldCloud will authenticate the user, either through an existing session, or through the OIDC tokens, and respond to the request.<br/><br/>
166
+
167
+
168
+
#### Token refresh loop
169
+
170
+
17.**Ask for a new token**
171
+
QField/QFieldSync will regularly refresh the ID and access tokens by calling the IDP's token refresh endpoint and submitting the refresh token it received.<br/><br/>
172
+
173
+
18.**Send a refreshed token**
174
+
The IDP will respond with new ID and access tokens.<br/><br/>
0 commit comments