I am trying to authenticate my login via Google drive OAuth2
in my c# desktop app. And when the user enters Client ID
and Client secret
, the browser opens and asks for confirmation.
Also browser opens when user enters a wrong Client ID
and Client secret
and shows an error message on the Google web page...
So, haw can I authenticate without browser confirmation and handle all google OAuth2 errors inside my code and without any browser pages?
Here is my authentication code:
//...code
string[] scopes = new string[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile };
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "WrongID",
ClientSecret = "WrongSecret"
},
scopes, _authUserName,
CancellationToken.None, new FileDataStore(_authDataStorePath, true)).Result;
//...code
And when error occurs in this block, execution of code just stops and nothing happens.
UPDATE1:
OK, suppose that I know how to get the json file with tokens. Now, how can I make DriveService object with this file? Now I create it as follows:
DriveService _drive = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential, // How to make this credential from tokens?
ApplicationName = _applicationName
});
Also, how about catching Google OAuth exceptions
in my c# code? Couse now the Google just show me an error info in browser and my app just hangs...