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:
RaffaelW 2026-01-28 23:15:20 +01:00
parent 3c8c263327
commit 540c70fe30
3 changed files with 182 additions and 52 deletions

View file

@ -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