initSessionUsernamePassword method
Request a session token to uses other API endpoints using a username
and password
.
If getFullSession
is set to true, will also return the session details in session.
If sendInQuery
is set to true, will send the credentials in the query string instead of the header.
Will throw an Exception if the session can't be initialized.
Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#init-session.
Implementation
@override
Future<Map<String, dynamic>> initSessionUsernamePassword(
String username, String password,
{bool getFullSession = false, bool sendInQuery = false}) async {
final Map<String, String> headers = {
'Content-Type': 'application/json',
...?appToken != null ? {'App-Token': appToken!} : null,
...?!sendInQuery
? {
'Authorization':
'Basic ${base64Encode(utf8.encode('$username:$password'))}'
}
: null,
};
final uri = sendInQuery
? '$host/initSession?get_full_session=$getFullSession&login=$username&password=$password'
: '$host/initSession?get_full_session=$getFullSession';
final response = await _innerClient.get(Uri.parse(uri), headers: headers);
if (response.statusCode != 200) {
throw GlpiException.fromResponse(
response.statusCode, json.decode(response.body));
}
return Future.value(json.decode(response.body));
}