mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-03-22 04:21:25 +00:00
Implement token-based login
Added drop-down to switch between username & password login or token login so login if using OAuth is possible.
This commit is contained in:
parent
3c8c263327
commit
540c70fe30
3 changed files with 182 additions and 52 deletions
35
lib/api.dart
35
lib/api.dart
|
|
@ -163,6 +163,7 @@ class InvenTreeFileService extends FileService {
|
|||
*
|
||||
* InvenTree implements token-based authentication, which is
|
||||
* initialised using a username:password combination.
|
||||
* Alternatively, an existing token provided by the user can be used for authentication.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
|
@ -540,6 +541,40 @@ class InvenTreeAPI {
|
|||
}
|
||||
}
|
||||
|
||||
Future<APIResponse> checkToken(UserProfile userProfile, String token) async {
|
||||
debug("Checking token @ ${_URL_ME}");
|
||||
|
||||
userProfile.token = token;
|
||||
profile = userProfile;
|
||||
|
||||
final response = await get(_URL_ME);
|
||||
|
||||
if (!response.successful()) {
|
||||
switch (response.statusCode) {
|
||||
case 401:
|
||||
case 403:
|
||||
showServerError(
|
||||
apiUrl,
|
||||
L10().serverAuthenticationError,
|
||||
L10().invalidToken,
|
||||
);
|
||||
default:
|
||||
showStatusCodeError(apiUrl, response.statusCode);
|
||||
}
|
||||
|
||||
debug("Request failed: STATUS ${response.statusCode}");
|
||||
|
||||
// reset token
|
||||
userProfile.token = "";
|
||||
profile = userProfile;
|
||||
} else {
|
||||
// save token
|
||||
await UserProfileDBManager().updateProfile(userProfile);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch a token from the server,
|
||||
* with a temporary authentication header
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue