initSessionUserToken method Null safety
override
Request a session token to uses other API endpoints using a userToken
.
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>> initSessionUserToken(String userToken,
{bool getFullSession = false, bool sendInQuery = false}) async {
if (userToken.isEmpty) {
throw ArgumentError('userToken must not be empty');
}
final Map<String, String> headers = {
'Content-Type': 'application/json',
...?appToken != null ? {'App-Token': appToken!} : null,
...?!sendInQuery ? {'Authorization': 'user_token $userToken'} : null,
};
final uri = sendInQuery
? '$host/initSession?get_full_session=$getFullSession&user_token=$userToken'
: '$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));
}