Reputation: 2657
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
This piece of code from here handles the authentication of an application and saves a user credential file.
But, it does so using a browser. I read, somewhere, that google no longer supports the checking of raw username & passwords, and instead have the user login via the browser.
Can I not embed a browser in my C# application, and have the authentication done in here, instead of annoyingly opening a browser?
Upvotes: 1
Views: 4855
Reputation: 22306
OAuth is an authorization protocol, not an authentication mechanism. Google's authentication is always done in a browser, and is no longer supported in embedded browsers. See https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html
There are solutions to avoid having to prompt a user via a browser each time. Specifically you can use a Service Account (which is creating a new Google account to act as a proxy - see https://developers.google.com/identity/protocols/OAuth2ServiceAccount) or request and save a Refresh Token (which is analogous to saving a username/password, but specific to the required Google service eg. Drive - see How do I authorise an app (web or installed) without user intervention? (canonical ?)).
Upvotes: 2