public static GoogleAccount SaveAccount(IGoogleAuthBroker broker, UserCredential credential, DictionaryDataStore dataStore) { // Create the service. PlusService plusService = new PlusService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = broker.AppName, }); Person me = plusService.People.Get("me").Execute(); string id = me.Id; Log.Info("Authorized user: ", me.DisplayName); using (var json = Config) { if (!json.Value.Accounts.ContainsKey(id)) { json.Value.Accounts [id] = new GoogleAccountJson(); } GoogleAccountJson accJson = json.Value.Accounts [id]; accJson.AccessToken = credential.Token.AccessToken; accJson.RefreshToken = credential.Token.RefreshToken; accJson.Id = me.Id; accJson.Emails = (from email in me.Emails ?? new Person.EmailsData[0] select email.Value).ToArray(); accJson.DisplayName = me.DisplayName; } return(new GoogleAccount(broker: broker, id: id)); }
public static IEnumerable <GoogleAccount> List(IGoogleAuthBroker broker) { using (var json = Config) { string[] ids = json.Value.Accounts.Keys.ToArray(); foreach (string id in ids) { GoogleAccount acc = new GoogleAccount(broker: broker, id: id); yield return(acc); } } }
public GoogleAccount(IGoogleAuthBroker broker, string id) : this() { Broker = broker; using (var json = Config) { if (!json.Value.Accounts.ContainsKey(id)) { json.Value.Accounts [id] = new GoogleAccountJson(); } jsonAccount = json.Value.Accounts [id]; } }
public OAuth2Parameters GetOAuth2Parameters(IGoogleAuthBroker broker) { OAuth2Parameters parameters = new OAuth2Parameters { ClientId = broker.Secrets.ClientId, ClientSecret = broker.Secrets.ClientSecret, RedirectUri = RedirectUri, Scope = string.Join(" ", broker.Scopes), }; parameters.AccessToken = AccessToken; parameters.RefreshToken = RefreshToken; return(parameters); }
public GoogleAuthentication(IGoogleAuthBroker broker, GoogleAccount account) { Broker = broker; Account = account; }