示例#1
0
文件: GetToken.cs 项目: Huddle/Puddle
        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;
        }
示例#2
0
文件: setToken.cs 项目: Huddle/Puddle
        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();
        }