BCXAPI.Service.RefreshAccessToken C# (CSharp) Method

RefreshAccessToken() public method

call this when you get a TokenExpired exception and store the new access token for future requests
public RefreshAccessToken ( ) : dynamic
return dynamic
        public dynamic RefreshAccessToken()
        {
            try
            {
                string url = string.Format(_RefreshTokenURL);
                string post_body = string.Format(_RefreshTokenPostBody, System.Web.HttpUtility.UrlEncode(_clientID),
                    System.Web.HttpUtility.UrlEncode(_redirectURI),
                    System.Web.HttpUtility.UrlEncode(_clientSecret), System.Web.HttpUtility.UrlEncode(_accessToken.refresh_token));
                var wr = System.Net.HttpWebRequest.Create(url);
                wr.Method = "POST";
                byte[] byteArray = Encoding.UTF8.GetBytes(post_body);
                wr.ContentType = "application/x-www-form-urlencoded";
                wr.ContentLength = byteArray.Length;
                using (System.IO.Stream dataStream = wr.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }

                var resp = (System.Net.HttpWebResponse)wr.GetResponse();
                using (var sw = new System.IO.StreamReader(resp.GetResponseStream()))
                {
                    _accessToken = Json.Decode(sw.ReadToEnd());
                }
                return _accessToken;
            }
            catch
            {
                throw new Exceptions.UnauthorizedException();
            }
        }