I have a Blazor App which has a calendar. I want to sync the event from the app calendar, to the users Google Calendar.
I am using the 'Authorization Code Flow'.
I have succeeded in getting the first two steps done of the flow which is:
1.Getting an Authorization Code.
- Exchanging it for a token + refresh token.
I now want to use this token to insert an event into the calendar. I have not found a way to do this.
I did find this example which ALMOST does what I want it to do. However, it is meant for a Desktop Application, not a server to server scenario. The user has already given consent in steps 1 & 2, and now the server, at a later date, will use the token to insert into a new event.
var credentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret },
scopes, "[email protected]", CancellationToken.None, sqlServerDatabaseStore);
if(credentials.Token.IsExpired(SystemClock.Default))
{
await credentials.RefreshTokenAsync(CancellationToken.None);
}
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credentials
}
);
What I need is a way to create the "credentials" using the token, but I am not seeing how to do this.