Box API Refresh Token C#

In this article, we will see how to get refresh token for given previous refresh token which is catpured during initial authorization of box.

1. Register in Box for client id and client secret.

2. Pass client id , client secret and initial refresh token to get new access and refresh token.

        public BoxResponse BoxAPIRefreshBoxToken(BoxClientSettings BoxClientSettings)
            BoxResponse BoxResponse = new BoxResponse();

            using (var request = new HttpRequestMessage() { RequestUri = new Uri(BoxClientSettings.boxApiOauth2Url), Method = HttpMethod.Post })
                HttpContent content = new FormUrlEncodedContent(new[]
                 new KeyValuePair<string, string>("grant_type", "refresh_token"),
                 new KeyValuePair<string, string>("refresh_token", BoxClientSettings.boxRefreshToken),
                 new KeyValuePair<string, string>("client_id", BoxClientSettings.boxClientId),
                 new KeyValuePair<string, string>("client_secret", BoxClientSettings.boxClientSecret)
                request.Content = content;
                using (var response = _httpClient.SendAsync(request).Result)
                    if (!response.IsSuccessStatusCode)
                        throw new Exception("Box refresh token failed. A human needs to go to a browser and generate a fresh authorization code.");
                    JObject jObject = jObject = JObject.Parse(response.Content.ReadAsStringAsync().Result);
                    BoxResponse.boxAccessToken = (string)jObject["access_token"];
                    BoxResponse.boxRefreshToken = (string)jObject["refresh_token"];
            return BoxResponse;


Labels: box api c#, box api .net, box api refresh token c#, box api refresh token .net


Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker