cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Contributor

C# sample for getting token with TLS 1.2

Can someone give me a C# sample of getting access token with  TLS 1.2 please. My old version is working fine but the TLS 1.2 code I am not able to get to work. 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Active Contributor

Re: C# sample for getting token with TLS 1.2

I fugred it out by myselft after banging my head against the wall several hours! 

 

void GetTokenWithWebClient(string userid, string password, string msgBody, string uri)
{
//msgBody = "grant_type=password&username={0}&password={1}"
//uri = "https://api.getgo.com/oauth/v2/token"

string requestBody = string.Format(msgBody, userid, password);

WebClient client = new WebClient();

client.Headers.Add("Content-Type:application/x-www-form-urlencoded");
///Authorization parameter's value is from the website of GotoWebinar. On https://goto-developer.logmeininc.com/
///login with the user & pass on to this site, then click on applications to get key and secret. The large value after 'Basic' is
///Base64 representation of KeySmiley Frustratedecret. This is the way GotoWebinar require us to send data to get token.
client.Headers.Add("Authorization:Basic XXX"); //Replace XXX with Base64 value of clientid:clientsecret
var result = client.UploadString(uri, requestBody);
using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(result)))
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ResponseDirectLogin));
ResponseDirectLogin resp = (ResponseDirectLogin)ser.ReadObject(stream);
OauthToken = resp.AccessToken;
OrganizerKey = resp.OrganizerKey;
}
}

View solution in original post

9 REPLIES 9
Highlighted
LogMeIn Contributor

Re: C# sample for getting token with TLS 1.2

@sureshbabu  Sorry, was this in reference to our APIs?

 

 

Highlighted
Active Contributor

Re: C# sample for getting token with TLS 1.2

Yes. It would be really helpful, if you could give some C# samples for acquiring access tokens.

Highlighted
LogMeIn Contributor

Re: C# sample for getting token with TLS 1.2

@sureshbabu  In that case, you will want to work exclusively through the Developers site there:  https://goto-developer.logmeininc.com/gotowebinar-api-overview

 

Once set up, you may continue to explore the Resources listed within.

Highlighted
Active Contributor

Re: C# sample for getting token with TLS 1.2

Nope that did not fix my problem.  Right now I am stuck and not sure what to do

Highlighted
LogMeIn Contributor

Re: C# sample for getting token with TLS 1.2

@sureshbabu  Sorry, I am still unclear what your are trying to accomplish.  Could you elaborate on the ultimate goal here with GoToWebinar or integrating platforms?

Highlighted
Active Contributor

Re: C# sample for getting token with TLS 1.2

From our software, we use the legacy authentication of your service and get access token and register for webinars using C# code.   Now I am trying to use the new authenticaion  which would be effective by October and I cannot get it to work.  A guy named Steven responded from support of the site you mentioned but its endless back and forth without a resolution.

 

So what I am trying to achieve?

  Programmatically authorize a user and register for webinars using C#.  Someone from the API developer group can assist me on this.

Who could help me?

  Someone from developer group of this API could help me.

Highlighted
LogMeIn Contributor

Re: C# sample for getting token with TLS 1.2

@sureshbabu  Thank you for the explanation.  Unfortunately we don't offer direct support for APIs here, so your best option is to continue working with Customer Care email support.  The staff that monitors Developer Requests can usually get the answers, even when it lies outside of what we actually support, as in your case.

Highlighted
Active Contributor

Re: C# sample for getting token with TLS 1.2

I fugred it out by myselft after banging my head against the wall several hours! 

 

void GetTokenWithWebClient(string userid, string password, string msgBody, string uri)
{
//msgBody = "grant_type=password&username={0}&password={1}"
//uri = "https://api.getgo.com/oauth/v2/token"

string requestBody = string.Format(msgBody, userid, password);

WebClient client = new WebClient();

client.Headers.Add("Content-Type:application/x-www-form-urlencoded");
///Authorization parameter's value is from the website of GotoWebinar. On https://goto-developer.logmeininc.com/
///login with the user & pass on to this site, then click on applications to get key and secret. The large value after 'Basic' is
///Base64 representation of KeySmiley Frustratedecret. This is the way GotoWebinar require us to send data to get token.
client.Headers.Add("Authorization:Basic XXX"); //Replace XXX with Base64 value of clientid:clientsecret
var result = client.UploadString(uri, requestBody);
using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(result)))
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ResponseDirectLogin));
ResponseDirectLogin resp = (ResponseDirectLogin)ser.ReadObject(stream);
OauthToken = resp.AccessToken;
OrganizerKey = resp.OrganizerKey;
}
}

View solution in original post

Highlighted
New Contributor

Re: C# sample for getting token with TLS 1.2

Hello @sureshbabu / @AshC  : I am integrating GotoWebinar in c#.
Can someone please provide reference code or let me know how to get authorization code throught .net/c#.

I am able to get access token by manually passing "authorization code url" like below, but not able to get authorization code through code itself.
var oauth2Api = new OAuth2Api(VIHC_Constants.webinar_ClientID, VIHC_Constants.webinar_ClientSecret);
string authUrl = oauth2Api.GetOAuth2AuthorisationUrl(VIHC_Constants.webinar_ClientID);

//I get authUrl as expected. but then I have to do manual process but I want to do it automate through code.

var authCodeURI = new Uri("https://www.example.com/?code=eyJraWQiOiJvYXV0aHYyLmxtaS5jb20uMDIxOSIsImFsZyI6IlJTN....");
var client = new RestClient("https://api.getgo.com/oauth/v2/token");
client.Timeout = -1;
var authorizationValue = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{VIHC_Constants.webinar_ClientID}:{VIHC_Constants.webinar_ClientSecret}"));
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("authorization", "Basic "+authorizationValue);
request.AddHeader("Accept", "application/json");
request.AddParameter("application/x-www-form-urlencoded", "grant_type=authorization_code&code=" + responseKey + "&redirect_uri=https://www.example.com", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
dynamic resp = JObject.Parse(response.Content);
string token = resp.access_token;