Skip to content

Commit b7f8daa

Browse files
author
Max Schlosser
committed
Add authentication
1 parent ec9b92f commit b7f8daa

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
11
# Authentication
22

3-
Coming soon...
3+
All authentication processes in the app rely on the Astra API.
4+
Astra API provide a JWT session token which encodes basic user information as well as a separate
5+
session token that can be used for the HSMWmobil app service, therefore serving as authorization
6+
means for both major APIs used in this project.
7+
8+
This page explains the basic authentication features of the app, their interconnection and how
9+
they are used within the app.
10+
The base components are shown in the following figure:
11+
12+
![Authentication system overview](app/img/auth.png)
13+
14+
[//]: # (TODO: Add Login Workflow)
15+
16+
## AuthController
17+
18+
The `AuthController` is the logical pivot of the system and will be the access point you will
19+
deal with when extending the app. As it is injected globally, you can access it at any time
20+
using the `BuildContext` like that:
21+
```dart
22+
context.read<AuthController>()
23+
```
24+
25+
The following variables are the most important ones you might use:
26+
- `isAuthenticated`: Whether the user is logged in and the current session is still valid.
27+
- `currentAccount`: The account data the user is currently logged in with.
28+
- `currentSession`: The last session requested from the auth service.
29+
- `wasAuthenticatedInPast`: Whether a user has been logged in and authenticated in the past, no
30+
matter the current authentication state.
31+
32+
## AccountData
33+
The `AccountData` provided by the controller gives you the possibility to directly access the
34+
user's login data through an encrypted secure storage.
35+
While this is a security risk in most apps, we need it as we need to inject those data in many
36+
web views (such as emails, learning management systems, ...).
37+
In the future, it would be better to allow such processes through the session token, however
38+
this is currently not possible.
39+
Use the following variables to use the data in the app:
40+
- `username`: The user's login ID.
41+
- `password`: The corresponding password.
42+
43+
## AuthSession
44+
The `AuthSession` represents the actual session one may authenticate with through the Astra
45+
Service JWT.
46+
Although you might probably not access them directly yourself, the following variables are used by
47+
other app components:
48+
- `jwt`: The JWT.
49+
- `user`: The user object decoded from the JWT payload.
50+
- `appServiceToken`: The session token for the HSMWmobil app service, decoded from the JWT payload.
51+
- `isExpired`: Whether the JWT is expired already or not.
52+
53+
## AuthUser
54+
As said earlier, the session encodes user-specific information which are parsed in a separate
55+
`AuthUser` object within the session. There are some interesting variables we can use:
56+
- `id`: The unique user ID given by Astra service.
57+
- `universityId`: The unique user ID used by HSMWmobil app service.
58+
- `displayName`: The user's real name representation (should follow the schema `Last Name, First
59+
Name`).
60+
- `groups`: The HSMWmobil app service the user belongs to.
61+
- `networkShares`: The available network share paths, as given by the HSMWmobil app service.
62+
63+
## Specific Authed Repositories
64+
As described in [app architecture reference](Base-Architecture.md), there are clients which
65+
automatically inject session data in service requests, so endpoints which require authorization
66+
can be accessed. There are two usable classes for this:
67+
- `AppApiClient` for requests to the HSMWmobil app service (injecting `appServiceToken` from
68+
class `AuthSession`)
69+
- `AstraApiClient` for requests to the Astra service (injecting `jwt` from class `AuthSession`)

Writerside/topics/app/img/auth.png

51 KB
Loading

0 commit comments

Comments
 (0)