Create Meeting from ASP.Net Page with OAuth Example

We are using JWT without any issues as the JWT is going to deprecated so we need to shift to OAuth, I am using the following code

var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
var now = DateTime.UtcNow;
var apiSecret = “My Secreat Key”;
byte symmetricKey = Encoding.ASCII.GetBytes(apiSecret);

        var tokenDescriptor = new SecurityTokenDescriptor
        {
            Issuer = "My Issuers Code",
            Expires = now.AddSeconds(300),
            SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256),
        };

        var token = tokenHandler.CreateToken(tokenDescriptor);
        var tokenString = tokenHandler.WriteToken(token);

        var client = new RestClient("https://api.zoom.us/v2/users/milaapmp@gmail.com/meetings");
        var request = new RestRequest("", Method.Post);
        request.RequestFormat = DataFormat.Json;
        request.AddJsonBody(new { topic = "Meeting Topic", duration = "10", start_time = "2023-04-30T18:20:00", type = "2" });

        request.AddHeader("authorization", String.Format("Bearer {0}", tokenString));
        RestResponse restResponse = client.Execute(request);
        HttpStatusCode statusCode = restResponse.StatusCode;
        int numericStatusCode = (int)statusCode;
        var jObject = JObject.Parse(restResponse.Content);

        Host.Text = (string)jObject["start_url"];
        Join.Text = (string)jObject["join_url"];
        Code.Text = Convert.ToString(numericStatusCode);

Can I use the same code just change the OAuth Client Key and Secret or any changes, If you have any example of sample code request to share

Thanks
tarun

Hi @milaapmp
Thanks for reaching out to us! I am happy to help here!

The only thing that you need to change is the way yo generate your token.
For the JWT app, you use your API key and secret to generate a JWT token.

In the case of the Server to Server oauth app, you will need to make a post request to our Oauth endpoint using your client ID, client secret, and account ID, to get the access_token.

Then that token will be used in the same way that you are currently using it.

Here is a link to our Docs:
https://developers.zoom.us/docs/internal-apps/#use-account-credentials-to-get-an-access-token

Cheers,
Elisa

Hi Elisa,

Thanks for response, I have used the code to generate the token.

var client = new RestClient(“Sign In | Zoom”);
var request = new RestRequest(“”, Method.Post);
request.AddHeader(“Authorization”, “HSrRBUOaUTbUL6bV1UXKTGXvgKem5PY2”);

        RestResponse response = client.Execute(request);
        Label1.Text = response.Content;

I refer the code from the given link below, but the token is not generating, it will shift to zoom

Request to help

Best Regards
Tarun

Sorry for the last response, but I am able to generate the token, request to check and confirm

https://mpmilaap.in/Create?code=qoWZSLAuLi7SrnMGQf-QLmQlCYmksPReA

Now where I need to pass it with Client Secret

Thanks

hey @milaapmp
Could you please confirm if you are trying to migrate to Server to Server Oauth or Just OAuth admin level app?

Hi, As I just want to create and manage meetings from my portal as I was using JWT then I was able to create meetings from my portal.

I need that

Thanks

Hey @milaapmp
So your best choice here would be to user our Server to Sever OAuth app
The only thing that changes is the token generation (the API calls will remain the same)

With the JWT app type you use your API key and Secret to create a JWT token.
With the Server to Server OAuth endpoint, you will use the credentials associated with your app (account ID, client ID and client Secret) to request an access_token to our OAuth endpoint

Here’s a helpful post on how to generate access tokens using Postman

Hi Elisa,
I am Tarun Bamba

I have created the OAuth App in the panel ,
Using the following ASP.Net code , I am not able to get the token , can you help me out where I am missing, I followed the steps from documentation, also test with postman

Thanks

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

public class ZoomMeeting
{
private const string BaseUrl = “https://api.zoom.us/v2”;
private const string ClientId = “My_CLIENT_ID”;
private const string ClientSecret = “My_CLIENT_SECRET”;

public async Task<string> CreateMeeting()
{
    // Step 1: Get an access token
    var accessToken = await GetAccessToken();

    if (string.IsNullOrEmpty(accessToken))
    {
        // Handle error when unable to retrieve the access token
        return "Failed to retrieve access token";
    }

    // Step 2: Create a meeting
    var httpClient = new HttpClient();
    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

    var request = new
    {
        topic = "Sample Meeting",
        type = 2, // Scheduled meeting
        start_time = DateTime.UtcNow.AddMinutes(10).ToString("yyyy-MM-ddTHH:mm:ssZ"), // Start time in UTC
        duration = 60, // Duration in minutes
        timezone = "America/Los_Angeles",
        settings = new
        {
            join_before_host = true,
            mute_upon_entry = true,
            auto_recording = "cloud"
        }
    };

    var json = Newtonsoft.Json.JsonConvert.SerializeObject(request);
    var content = new StringContent(json);
    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

    var createMeetingUrl = $"{BaseUrl}/users/me/meetings";
    var response = await httpClient.PostAsync(createMeetingUrl, content);

    if (response.IsSuccessStatusCode)
    {
        var result = await response.Content.ReadAsStringAsync();
        // Parse the JSON response to get the meeting details
        // You can retrieve the join URL, meeting ID, and other information from the response
        return result;
    }

    // Handle error when unable to create the meeting
    return "Failed to create meeting";
}

private async Task<string> GetAccessToken()
{
    var httpClient = new HttpClient();
    var request = new
    {
        grant_type = "client_credentials",
        client_id = ClientId,
        client_secret = ClientSecret
    };

    var json = Newtonsoft.Json.JsonConvert.SerializeObject(request);
    var content = new StringContent(json);
    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

    var tokenUrl = "https://zoom.us/oauth/token";
    var response = await httpClient.PostAsync(tokenUrl, content);

    if (response.IsSuccessStatusCode)
    {
        var result = await response.Content.ReadAsStringAsync();
        dynamic jsonResult = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
        return jsonResult.access_token;
    }

    return null;
}

}

Hi @milaapmp
Thanks for reaching out to us!
It looks like you are passing the wrong grant_type when generating your access_token,.
Make sure that the grant_type is account_credentials instead of client_credentials
Screenshot 2023-06-16 at 10.32.05 AM

Let me know if that helps!
Cheers,
Elisa

Hi there i create C# application and i configer Client ID, Client Secret in me application, and i also have redirect url. and this is final look of request to authorize use (step1): var authorizeUrl = $“Error - Zoom”; but is whill not working i get whole html code if sign in pageof zoomauthorize in my response body. Note i call a request using swagger

Hi @zainnabbas.ibs
Thanks for reaching out to us.
It looks like you are using an Oauth app for authorization and to generate your access token.
Here is a link to our Docs:

Dear Elisa,

Greetings.

We have created a page with all OAuth feature http://mpmilaap.in.net/zoomtest
This is a test link where we are click on the create button it will move to Zoom page, after login it will back with token and create the meeting successfully, but it will accept our registered zoom id only, other will not work

Can you help me that once we click on the create button on the given URL , it will create the meeting link without Zoom Login,

Thanks

Tarun Bamba

Hi @milaapmp
Thanks for reaching out to us.
If you want users outside of your account to use your app, you will need to publish your app in the Zoom Marketplace

But then from marketplace every user can use it, If I want to restrict for 20 users ?

@milaapmp
You can publish your app and have it private in the Marketplace team
And only share the app with the users that you want to use your app

Hi my code is following to create meeting using zoom from asp.net c#
public async Task CreateMeeting()
{
// Step 1: Get an access token
var accessToken = await GetAccessToken();

        if (string.IsNullOrEmpty(accessToken))
        {
            // Handle error when unable to retrieve the access token
            return "Failed to retrieve access token";
        }

        // Step 2: Create a meeting
        var httpClient = new HttpClient();
        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

        var request = new
        {
            topic = "Sample Meeting",
            type = 2, // Scheduled meeting
            start_time = DateTime.UtcNow.AddMinutes(10).ToString("yyyy-MM-ddTHH:mm:ssZ"), // Start time in UTC
            duration = 60, // Duration in minutes
            timezone = "America/Los_Angeles",
            settings = new
            {
                join_before_host = true,
                mute_upon_entry = true,
                auto_recording = "cloud"
            }
        };

        var json = Newtonsoft.Json.JsonConvert.SerializeObject(request);
        var content = new StringContent(json);
        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        var createMeetingUrl = $"{BaseUrl}/users/me/meetings";
        var response = await httpClient.PostAsync(createMeetingUrl, content);

        if (response.IsSuccessStatusCode)
        {
            var result = await response.Content.ReadAsStringAsync();
            // Parse the JSON response to get the meeting details
            // You can retrieve the join URL, meeting ID, and other information from the response
            return result;
        }

        // Handle error when unable to create the meeting
        return "Failed to create meeting";
    }

    private async Task<string> GetAccessToken()
    {
        var httpClient = new HttpClient();
        var request = new
        {
            grant_type = "account_credentials",
            client_id = ClientId,
            client_secret = ClientSecret
        };

        var json = Newtonsoft.Json.JsonConvert.SerializeObject(request);
        var content = new StringContent(json);
        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        var tokenUrl = "https://zoom.us/oauth/token";
        var response = await httpClient.PostAsync(tokenUrl, content);

        if (response.IsSuccessStatusCode)
        {
            var result = await response.Content.ReadAsStringAsync();
            dynamic jsonResult = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
            return jsonResult.access_token;
        }

        return null;
    }

But it showing error " The request was aborted: Could not create SSL/TLS secure channel."
when hit this " await httpClient.PostAsync" while creating token.
what is the solution for this
kindly help

Hi @dibakar.info05
I have not seen this error myself.
Could you please try generating an access token with postman and making an API call to make sure that this is not an issue on our end?

Hi Iam not using Postman.I am using Oauth not server to serverOauth.is this code is ok?Or is it possible to create meeting from localhost?

I see @dibakar.info05
sorry for the confusion.
Here is a sample app that uses the user-level oauth and it showcases token generation

Hi Dibakar

I’m .Net Developer and having problem with GetAccessToken too. I dont understand why is so hard.

Have you managed to get the access token? If yes, could you help me please?