cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
749
Views
0
Helpful
3
Replies

WebEx OAuth in c#

cgr-921
Level 1
Level 1

Are there any sample codes in c# that demonstrate an OAuth with WebEx and retrieve a token ?

3 Replies 3

cgr-921
Level 1
Level 1

Thanks for the response. Before I look into the wrapper, I was wondering if there's a simple way to just encode the client credentials (with clientid, clientsecret) and send a token request,

Similar to this:

HttpClient client = new HttpClient();

// Encode client credentials
string credentials = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));

// Prepare the request to get the access token
var tokenRequest = new HttpRequestMessage(HttpMethod.Post, tokenEndpoint);
tokenRequest.Headers.Add("Authorization", $"Basic {credentials}");
tokenRequest.Content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "client_credentials"),
new KeyValuePair<string, string>("scope", scope)
});

// Send the token request
HttpResponseMessage tokenResponse = await client.SendAsync(tokenRequest);

 

Also, my goal is to access recordings and download them. Would I still need OAuth or can it be done with a guest JWT ?

 

The Webex Rest API does not support basic auth for OAuth, ie. you must use the web form for authorization.

To access the recording endpoint, you'd need to be authenticated - a JWT will not work for that.

dtibbe
VIP Alumni
VIP Alumni

I did that some time ago.. My GUI app had a browser control. When trying to authorize, I ran the known flow. The redirect URL was basically a non-existing localhost-URL. That raised a HTTP/404 for sure. That one was catched by my app, extracted the URL and grabbed the token to use it in the final step. Worked fine.
The app itself used Darren's Webex Rest API wrapper Spark.Net: https://github.com/darrenparkinson/SparkDotNet (bit outdated, but the wrapper can be extended quite easily)

If you're planning to build a command line app, you may want to have a look at Service Apps as well: https://developer.webex.com/docs/service-apps