Esempio n. 1
0
        public string GetAccessToken()
        {
            if(_token.IsExpired())
            {
                var request = new RefreshTokenRequest(Settings.Default.ClientId,GetRefreshToken());
                //encrypt the token
                byte[] unencryptedToken = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request));
                var encrypt = new EncryptData(unencryptedToken);
                byte[] encryptedToken = encrypt.EncryptedData;

                //save the encrypted token!
                SaveAccessToken.WriteToFile(Path, encryptedToken);
                //reset the acccess token to the new 1
                _token = JsonConvert.DeserializeObject<RootObject>(Encoding.UTF8.GetString(unencryptedToken));
            }
            return _token.access_token;
        }
Esempio n. 2
0
        protected override void ProcessRecord()
        {
            RootObject token;
            if (File.Exists(Path))
            {
               File.Delete(Path);
            }

            switch (ParameterSetName)
            {
                case "Password":
                    token = GetTokenWithPassword();
                    break;
                default:
                    token = GetTokenWithBrowser();
                    break;
            }

            //encrypt the token
            byte[] unencryptedToken = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(token));
            var encrypt = new EncryptData(unencryptedToken);
            byte[] encryptedToken = encrypt.EncryptedData;

            //save the encrypted token!
            SaveAccessToken.WriteToFile(Path,encryptedToken);

            base.ProcessRecord();
        }