'Synchronous Xero like synchronous Google Ads?

I believe that this piece of C# runs an async method as part of the OAuth2 process:

            // Authorize the user using desktop application flow.
            Task<UserCredential> task = GoogleWebAuthorizationBroker.AuthorizeAsync(
                secrets,
                scopes.Split(','),
                "user",
                CancellationToken.None,
                new FileDataStore("BOGoogle-" + credPathSuffix, false)
            );
            UserCredential credential = task.Result;

I understand that task.Result is starts that task and waits for it to finish.

So I though I would use the same approach with Xero as it also has an async auth process:

            XeroConfiguration XeroConfig = new XeroConfiguration
            {
                ClientId = ini.IniReadValue("Xero", "CLIENT_ID", ""),
                ClientSecret = ini.IniReadValue("Xero", "CLIENT_SECRET", "")
            };

            var client = new XeroClient(XeroConfig);

            var task = Task.Run(async () => { await client.RequestClientCredentialsTokenAsync(); });
            task.Start();
            task.Wait();
            IXeroToken token = null;// task.Wait(;

Now that's incomplete code but it's as far as I got to because I couldn't get the code to move beyond the Task.Run().

Is this even going to work? Obviously, I don't understand async/await and all that. Any clues on how to sync the async the way the Google Ads appears to be done.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source