Beispiel #1
0
        private AuthorisationResponse AuthenicateWithApi()
        {
            var authParameters = new List <Parameter>
            {
                new Parameter("content-type", "application/x-www-form-urlencoded", ParameterType.HttpHeader),
                new Parameter("client_id", _source.ClientId, ParameterType.GetOrPost),
                new Parameter("client_secret", _source.ClientSecret, ParameterType.GetOrPost),
            };

            var request = CreateRequest("auth/token", Method.POST, authParameters, addAuthorizationHeader: false);

            var response = _client.Execute <AuthorisationResponse>(request);

            if (!response.IsSuccessful)
            {
                throw new HttpRequestException($"Authentication with Ents24 failed with code: {response.StatusCode} - {response.StatusDescription}");
            }

            return(response.Data);
        }