Example #1
0
        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));
        }
Example #2
0
        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];
            }
        }