public override async Task <AccessCredentials> GetCredentialsAsync()
    {
        if (credentials != null && !credentials.AreExpired())
        {
            return(credentials);
        }

        var requestBuilder = await BuildRequest();

        if (Client != null)
        {
            ResponseResult responseResult = null;
            try
            {
                responseResult = await Client.ExecuteTaskAsync(NoErrorHandlers, requestBuilder, isSts : true);

                AssumeRoleResponse assumeRoleResp = null;
                if (responseResult.Response.IsSuccessStatusCode)
                {
                    var contentBytes = Encoding.UTF8.GetBytes(responseResult.Content);

                    using (var stream = new MemoryStream(contentBytes))
                    {
                        assumeRoleResp =
                            (AssumeRoleResponse) new XmlSerializer(typeof(AssumeRoleResponse)).Deserialize(stream);
                    }
                }

                if (credentials == null &&
                    assumeRoleResp != null &&
                    assumeRoleResp.arr != null)
                {
                    credentials = assumeRoleResp.arr.Credentials;
                }
                return(credentials);
            }
            finally
            {
                responseResult?.Dispose();
            }
        }

        throw new ArgumentNullException(nameof(Client) + " should have been assigned for the operation to continue.");
    }
Exemple #2
0
    public override async Task <AccessCredentials> GetCredentialsAsync()
    {
        if (Credentials != null && !Credentials.AreExpired())
        {
            return(Credentials);
        }

        var requestBuilder = await BuildRequest();

        if (Client != null)
        {
            ResponseResult responseMessage = null;
            try
            {
                responseMessage = await Client.ExecuteTaskAsync(NoErrorHandlers, requestBuilder);
            }
            finally
            {
                responseMessage?.Dispose();
            }
        }

        return(null);
    }