# Access Token from Authorisation token

**URL:** <https://devforum.zoom.us/t/access-token-from-authorisation-token/101020>\
**Category:** Web\
**Created:** [January 1, 2024, 10:09pm UTC](https://devforum.zoom.us/t/access-token-from-authorisation-token/101020 "2024-01-01T22:09:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chuxyno](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chuxyno/32/53713_2.png) [@chuxyno](https://devforum.zoom.us/u/chuxyno)\
**Post date:** [January 1, 2024, 10:09pm UTC](https://devforum.zoom.us/t/access-token-from-authorisation-token/101020/1 "2024-01-01T22:09:59Z")

</div>

Could you help resolve why my C# method below, it isn’t generating access tokens from the Authorization Token? I keep getting BadRequest with any authorization token I get. See the methods below:

```auto
public static async Task<string> GetAccessTokenAsync2(string authorizationToken)
{
    Codes codes = new Codes();
    try
    {
        using (HttpClient _httpClient = new HttpClient())
        {
            var requestUri = "https://zoom.us/oauth/token";
            var request = new HttpRequestMessage(HttpMethod.Post, requestUri);
            MessageBox.Show($"Credentials: {codes.AppClientID} {codes.AppClientSecret}");
            request.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{codes.AppClientID}:{codes.AppClientSecret}")));
            request.Content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("code", authorizationToken),
                new KeyValuePair<string, string>("grant_type", "authorization_code"),
                new KeyValuePair<string, string>("redirect_uri", codes.RedirectUrl)
            });
            MessageBox.Show($"Credentials: {authorizationToken} {codes.RedirectUrl}");
            var response = await _httpClient.SendAsync(request);
            MessageBox.Show($"StatusCode: {response.StatusCode}");
            response.EnsureSuccessStatusCode();
            MessageBox.Show($"After ");
            var responseBody = await response.Content.ReadAsStringAsync();
            MessageBox.Show($"1");
            var jsonObject = JsonDocument.Parse(responseBody);

            if (jsonObject.RootElement.TryGetProperty("access_token", out var accessToken))
            {
                return accessToken.ToString();
            }
            else
            {
                // Handle the case where 'access_token' property is missing
                throw new InvalidOperationException("Access token not found in the response.");
            }
        }
    }
    catch (HttpRequestException ex)
    {
        // Handle HTTP request exceptions
        Console.WriteLine($"HTTP Request Exception: {ex.Message}");
        throw new Exception ($"HTTP Request Exception: {ex.Message}");
    }
    catch (System.Text.Json.JsonException ex)
    {
        // Handle JSON parsing exceptions
        Console.WriteLine($"JSON Parsing Exception: {ex.Message}");
        throw new Exception($"JSON Parsing Exception: {ex.Message}");
    }
    catch (Exception ex)
    {
        // Handle other exceptions
        Console.WriteLine($"Exception occurred: {ex.Message}");
        throw new Exception($"Exception occurred: {ex.Message}");
    }
}

```

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [January 3, 2024, 3:39am UTC](https://devforum.zoom.us/t/access-token-from-authorisation-token/101020/2 "2024-01-03T03:39:04Z")

</div>

@chuxyno I’ve just tested this, and your code works fine.

One important thing to take note is that your AppClientID, AppClientSecret and redirectURL must be correct.

Instead of using localhost for my redirectURL, I’ve used a tunnel service such as ngrok to ensure I have a valid publicly accessible URL.

There is nothing much I’ve changed in the code, except for commenting out some parts, and hiding my secret & clientID.

Are you using an OAuth app by the way?

```auto
    String AppClientID = "redacted";
    String AppClientSecret = "redacted";
    String redirectURL = "https://18cc-58-182-81-118.ngrok-free.app/redirectforoauth";

    var authorizationToken = context.Request.Query["code"].ToString();

  
    try
    {
        using (HttpClient _httpClient = new HttpClient())
        {
            var requestUri = "https://zoom.us/oauth/token";
            var request = new HttpRequestMessage(HttpMethod.Post, requestUri);
            //MessageBox.Show($"Credentials: {codes.AppClientID} {codes.AppClientSecret}");
            request.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{AppClientID}:{AppClientSecret}")));
            request.Content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("code", authorizationToken),
                new KeyValuePair<string, string>("grant_type", "authorization_code"),
                new KeyValuePair<string, string>("redirect_uri", redirectURL)
            });
            //MessageBox.Show($"Credentials: {authorizationToken} {codes.RedirectUrl}");
            var response = await _httpClient.SendAsync(request);
            //MessageBox.Show($"StatusCode: {response.StatusCode}");
            response.EnsureSuccessStatusCode();
            //MessageBox.Show($"After ");
            var responseBody = await response.Content.ReadAsStringAsync();
            //MessageBox.Show($"1");
            var jsonObject = JsonDocument.Parse(responseBody);

            if (jsonObject.RootElement.TryGetProperty("access_token", out var accessToken))
            {
               //return accessToken.ToString();
            }
            else
            {
                // Handle the case where 'access_token' property is missing
                throw new InvalidOperationException("Access token not found in the response.");
            }
        }
    }
    catch (HttpRequestException ex)
    {
        // Handle HTTP request exceptions
        Console.WriteLine($"HTTP Request Exception: {ex.Message}");
        throw new Exception($"HTTP Request Exception: {ex.Message}");
    }
    catch (System.Text.Json.JsonException ex)
    {
        // Handle JSON parsing exceptions
        Console.WriteLine($"JSON Parsing Exception: {ex.Message}");
        throw new Exception($"JSON Parsing Exception: {ex.Message}");
    }
    catch (Exception ex)
    {
        // Handle other exceptions
        Console.WriteLine($"Exception occurred: {ex.Message}");
        throw new Exception($"Exception occurred: {ex.Message}");
    }

```

---

<div class="post-metadata">

**Author:** ![chuxyno](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chuxyno/32/53713_2.png) [@chuxyno](https://devforum.zoom.us/u/chuxyno)\
**Post date:** [January 3, 2024, 11:12pm UTC](https://devforum.zoom.us/t/access-token-from-authorisation-token/101020/3 "2024-01-03T23:12:13Z")

</div>

Thanks, Chun, the issue wasn’t caused by this code.

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [January 10, 2024, 3:01am UTC](https://devforum.zoom.us/t/access-token-from-authorisation-token/101020/4 "2024-01-10T03:01:18Z")

</div>

@chuxyno , did you managed to find a solution to this?

---

<div class="post-metadata">

**Author:** ![chuxyno](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chuxyno/32/53713_2.png) [@chuxyno](https://devforum.zoom.us/u/chuxyno)\
**Post date:** [January 10, 2024, 9:10am UTC](https://devforum.zoom.us/t/access-token-from-authorisation-token/101020/5 "2024-01-10T09:10:22Z")

</div>

Sure, I did. The problem wasn’t from the code. Please close the ticket.

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [January 15, 2024, 3:42am UTC](https://devforum.zoom.us/t/access-token-from-authorisation-token/101020/6 "2024-01-15T03:42:17Z")

</div>

Closed on January 15, 2024, 3:42am UTC


