|
|
@ -74,8 +74,8 @@ namespace Yavsc.Services
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ClientSecrets = new ClientSecrets
|
|
|
|
ClientSecrets = new ClientSecrets
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ClientId = _googleSettings.ClientId,
|
|
|
|
ClientId = _googleSettings.ServiceAccount.client_id,
|
|
|
|
ClientSecret = _googleSettings.ClientSecret
|
|
|
|
ClientSecret = _googleSettings.ServiceAccount.client_secret
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Scopes = new[] { scopeCalendar },
|
|
|
|
Scopes = new[] { scopeCalendar },
|
|
|
|
DataStore = dataStore
|
|
|
|
DataStore = dataStore
|
|
|
@ -259,8 +259,14 @@ namespace Yavsc.Services
|
|
|
|
_logger.LogInformation("Got a Google token");
|
|
|
|
_logger.LogInformation("Got a Google token");
|
|
|
|
var c = SystemClock.Default;
|
|
|
|
var c = SystemClock.Default;
|
|
|
|
if (token.IsExpired(c)) {
|
|
|
|
if (token.IsExpired(c)) {
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(token.RefreshToken))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError("no refresh token to exploit and actual one expired : {}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
token = await RefreshToken(token);
|
|
|
|
token = await RefreshToken(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
UserCredential cred = new UserCredential(_flow,login.ProviderKey,token);
|
|
|
|
UserCredential cred = new UserCredential(_flow,login.ProviderKey,token);
|
|
|
|
_logger.LogInformation("Got creadential");
|
|
|
|
_logger.LogInformation("Got creadential");
|
|
|
|
return new CalendarService(new BaseClientService.Initializer()
|
|
|
|
return new CalendarService(new BaseClientService.Initializer()
|
|
|
@ -273,12 +279,13 @@ namespace Yavsc.Services
|
|
|
|
public async Task<TokenResponse> RefreshToken(TokenResponse oldResponse)
|
|
|
|
public async Task<TokenResponse> RefreshToken(TokenResponse oldResponse)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string ep = " https://www.googleapis.com/oauth2/v4/token";
|
|
|
|
string ep = " https://www.googleapis.com/oauth2/v4/token";
|
|
|
|
|
|
|
|
_logger.LogInformation($"rt:{oldResponse.RefreshToken}");
|
|
|
|
// refresh_token client_id client_secret grant_type=refresh_token
|
|
|
|
// refresh_token client_id client_secret grant_type=refresh_token
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
using (var m = new SimpleJsonPostMethod(ep)) {
|
|
|
|
using (var m = new SimpleJsonPostMethod(ep)) {
|
|
|
|
return await m.Invoke<TokenResponse>(
|
|
|
|
return await m.Invoke<TokenResponse>(
|
|
|
|
new { refresh_token= oldResponse.RefreshToken, client_id=_googleSettings.ClientId,
|
|
|
|
new { refresh_token= oldResponse.RefreshToken, client_id=_googleSettings.ServiceAccount.client_id,
|
|
|
|
client_secret=_googleSettings.ClientSecret,
|
|
|
|
client_secret=_googleSettings.ServiceAccount.client_secret,
|
|
|
|
grant_type="refresh_token" }
|
|
|
|
grant_type="refresh_token" }
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|