示例#1
0
 /// <summary>
 /// 强制清除token以支持下次获取到新的token
 /// </summary>
 public void ClearToken()
 {
     using (this.asyncRoot.Lock())
     {
         this.token = null;
     }
 }
示例#2
0
        /// <summary>
        /// 获取token信息
        /// </summary>
        /// <returns></returns>
        public async Task <TokenResult> GetTokenAsync()
        {
            using (await this.asyncRoot.LockAsync().ConfigureAwait(false))
            {
                if (this.token == null)
                {
                    this.token = await this.RequestTokenAsync().ConfigureAwait(false);
                }
                else if (this.token.IsExpired() == true)
                {
                    this.token = this.token.CanRefresh() == true
                        ? await this.RefreshTokenAsync(this.token.Refresh_token).ConfigureAwait(false)
                        : await this.RequestTokenAsync().ConfigureAwait(false);
                }

                if (this.token == null)
                {
                    throw new TokenNullException();
                }
                return(this.token.EnsureSuccess());
            }
        }