コード例 #1
0
        /// <summary>
        /// Authenticate the user with password for no specific scopes.
        /// </summary>
        /// <param name="serviceAcc">OpenStack service account.</param>
        /// <param name="project">OpenStack project.</param>
        /// <returns>Authentication response from the rest api with the authentication token.</returns>
        /// <exception cref="OpenStackAPIException">Is thrown when the request is malformed and the API returns non 201 code.</exception>
        public async Task <AuthenticationResponse> AuthenticateAsync(OpenStackServiceAccDTO serviceAcc, OpenStackProjectDTO project)
        {
            var    requestObject = AuthenticationRequest.CreateScopedAuthenticationPasswordRequest(serviceAcc, project);
            string requestBody   = JsonConvert.SerializeObject(requestObject, IgnoreNullSerializer.Instance);

            RestRequest request = new RestRequest($"v{OpenStackSettings.OpenStackVersion}/auth/tokens", Method.Post)
                                  .AddStringBody(requestBody, DataFormat.Json);

            RestResponse response = await _basicRestClient.ExecuteAsync(request);

            AuthenticationResponse result = ParseHelper.ParseJsonOrThrow <AuthenticationResponse, OpenStackAPIException>(response, HttpStatusCode.Created);

            result.AuthToken = (string)response.Headers.Single(p => p.Name == "X-Subject-Token").Value;

            return(result);
        }