Google Authentication Process

I’m trying to write my own Google Calendar calendar access application. I am trying to use the example that Google provided for authentication, but it never starts the authentication function

private void Window_Initialized(object sender, EventArgs e) { var provider = new NativeApplicationClient( GoogleAuthenticationServer.Description); provider.ClientIdentifier = "<My Client Id here>"; provider.ClientSecret = "<My Client Secret here"; var auth = new OAuth2Authenticator<NativeApplicationClient>( provider, (p) => GetAuthorization(provider)); CalendarService service = new CalendarService(); CalendarsResource.GetRequest cr = service.Calendars.Get("{primary}"); if (cr.CalendarId != null) { Console.WriteLine("Fetching calendar"); //Google.Apis.Calendar.v3.Data.Calendar c = service.Calendars.Get("{primary}").Fetch(); } else { Console.WriteLine("Service not found"); } } 

Here is the code I use for authentication. I never see a publication in the console.

 private static IAuthorizationState GetAuthorization(NativeApplicationClient arg) { Console.WriteLine("Authorization Requested"); IAuthorizationState state = new AuthorizationState( new[] { CalendarService.Scopes.Calendar.GetStringValue() }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); Uri authUri = arg.RequestUserAuthorization(state); Process.Start(authUri.ToString()); // Request authorization from the user and get the code string authCode = Console.ReadLine(); // Retrieve the access token by using the authorization code: return arg.ProcessUserAuthorization(authCode, state); } 

Are there any better tutorials or am I doing something wrong?

+4
source share
3 answers

The sample code is broken. For the service to use your authenticator, you need to connect it. In the example, there is no connection between the service and the authenticator. Create the service as follows:

 var service = new CalendarService(new BaseClientService.Initializer() { Authenticator = auth }; 

Check out https://code.google.com/p/google-api-dotnet-client/ for the best documentation / working code.

+2
source

Check out the new docs . You will need to replace

 var auth = new OAuth2Authenticator<NativeApplicationClient>( provider, (p) => GetAuthorization(provider)); 

from

 AuthenticatorFactory.GetInstance().RegisterAuthenticator( () => new OAuth2Authenticator(provider, GetAuthentication)); 

As the comment says, when you call var service = new CalendarService() , a previously registered authenticator is automatically registered.

0
source

I think the above methods are related to the old version of the Google calendar DLL. Does anyone know about the documentation for the new version of the Google calendar, i.e.V 1.8.1.82. Google never provides good documentation for the .NET developer.s

0
source

Source: https://habr.com/ru/post/1402499/


All Articles