From 35394e5d547baf8c1d2df4c27c30bd599882f188 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 17 Jul 2017 16:32:29 +0200 Subject: [PATCH] un objet UserCredential --- Yavsc/Helpers/GoogleHelpers.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Yavsc/Helpers/GoogleHelpers.cs b/Yavsc/Helpers/GoogleHelpers.cs index e35a9186..1b70e6d9 100644 --- a/Yavsc/Helpers/GoogleHelpers.cs +++ b/Yavsc/Helpers/GoogleHelpers.cs @@ -36,6 +36,9 @@ namespace Yavsc.Helpers using Yavsc.Services; using Google.Apis.Services; using Google.Apis.Compute.v1; + using Google.Apis.Auth.OAuth2.Flows; + using Google.Apis.Util.Store; + using Google.Apis.Auth.OAuth2.Responses; @@ -116,7 +119,14 @@ namespace Yavsc.Helpers ); return googleLogin; } - + public static async Task GetGoogleCredential(IDataStore store, string googleUserLoginKey) + { + if (string.IsNullOrEmpty(googleUserLoginKey)) + throw new InvalidOperationException("No Google login"); + var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer()); + var token = await store.GetAsync(googleUserLoginKey); + return new UserCredential(flow, googleUserLoginKey, token); + } public static async Task GetFreeTime (this ICalendarManager manager, string calId, DateTime startDate, DateTime endDate) { var evlist = await manager.GetCalendarAsync(calId, startDate, endDate, null) ;