function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Blagoj PetrovskiBlagoj Petrovski 

Authenticating using AuthenticationClient.UsernamePasswordAsync() throws exception with message "retry your request"

When I try to authenticate to SalesForce in order to get access to the data I get this message: "retry your request".
The authentication was successful till this morning. I know that for unsuccessful authentication you should receive different error (authentication failure).

How to overcome this issue?

This is my code:
 string securityToken = ConfigurationManager.AppSettings["SecurityToken"];
            string ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"];
            string ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"];
            string Username = ConfigurationManager.AppSettings["Username"];
            string Password = ConfigurationManager.AppSettings["Password"] + securityToken;
            string IsSandboxUser = ConfigurationManager.AppSettings["IsSandboxUser"];

            var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
                ? "https://test.salesforce.com/services/oauth2/token"
                : "https://login.salesforce.com/services/oauth2/token";

            var auth = new AuthenticationClient(new HttpClient());
            try
            {
                await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);
            }
            catch (Exception ex)
            {
                throw;
            }
Sabin DongolSabin Dongol
Hi Blagoj,

Please try adding this line of code:
               
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);

I had the same issue. It worked for me.
Christopher D. EmersonChristopher D. Emerson
Thanks Sabin! Fixed issue for me too!