I'm working on a Desktop Application. I'm migrating it from .Net Framework 4.8 to .Net 7.0. The application accesses and works with Google.Sheets tables. However, in .Net 7, authorization using OAuth 2.0 using the GoogleWebAuthorizationBroker.AuthorizeAsync method throws an error. In .Net Framework 4.8 everything worked fine. I caught an error that the method cannot open the browser. I know that .Net 7, unlike .Net Framework 4.8, in order to run a file or open a link in the browser, you need to force the UseShellExecute property to true in ProcessStartInfo. In .Net 7 it is false by default, and in .Net Framework 4.8 it is false. It is possible that the GoogleWebAuthorizationBroker.AuthorizeAsync method uses ProcessStartInfo with the value UseShellExecute and, as a result, cannot launch the browser for authorization. How to solve the problem with OAuth 2.0 authorization in .Net 7?
` var secretFile = Path.Combine(resourcesfolder, "client_secrets.json");
string credPath = Path.Combine(Path.GetTempPath(), "googletoken.json");
string[] scopes = { "https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive" };
UserCredential googleCredential = null;
using (var stream = new FileStream(secretFile, FileMode.Open, FileAccess.Read))
{
try
{
googleCredential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.FromStream(stream).Secrets,
scopes,
"user", CancellationToken.None, new FileDataStore(credPath, true));
}
catch (Exception e)
{
var ie = e.InnerException;
Rhino.RhinoApp.WriteLine("Impossible to log in!");
}
}`
"Failed to launch browser with https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&code_challenge="
If the GoogleWebAuthorizationBroker.AuthorizeAsync method actually uses ProcessStartInfo to open the browser, then I don't know how to pass the UseShellExecute property value to it. No matter what I tried, nothing helps.