flip | 2016-10-12 16:11:39 UTC | #1
I took the oAuth Examples, and turned them into functions that will return the access token as a variable. I thought it might help anyone whom is having issue with the 3 authentication types.
Hope it helps.
[details=Client Cred] using ININ.PureCloud.OAuthControl;
var token = ClientCred({ClientID}, {ClientSecret});
public string ClientCred(string strCID, string strCSecret) {
///===================================================================================== ///Client Credital Auth ///=====================================================================================
var accessTokeninfo = Configuration.Default.ApiClient.PostToken(strCID, strCSecret);///Calling and getting the oauthtoken
Configuration.Default.AccessToken = accessTokeninfo.AccessToken;///assignign oauth to api
///MessageBox.Show("Acces Token: " + accessTokeninfo.AccessToken);///will display token Debug.Write(accessTokeninfo.AccessToken);
return (accessTokeninfo.AccessToken);
///===================================================================================== ///End ///===================================================================================== ///
[/details]
[details=Implicit Grant] using ININ.PureCloud.OAuthControl;
var token = impgrant( {Clientid});
public string impgrant(string strCID) {
///===================================================================================== ///Token Implicit Grant ///=====================================================================================
var oawbForm = new OAuthWebBrowserForm();
/// Set settings oawbForm.oAuthWebBrowser1.ClientId = strCID; oawbForm.oAuthWebBrowser1.RedirectUriIsFake = true; oawbForm.oAuthWebBrowser1.RedirectUri = "https://127.0.0.1:8080";
/// Open it var result = oawbForm.ShowDialog();
Console.WriteLine($"Result: " + result); Console.WriteLine($"AccessToken: " + oawbForm.oAuthWebBrowser1.AccessToken);
return (oawbForm.oAuthWebBrowser1.AccessToken);
///===================================================================================== ///End ///=====================================================================================
}
[/details]
[details=Code Authorization]
public string codeAuth(string strCID, string strCSecret)
using ININ.PureCloud.OAuthControl;
var token = codeAuth({ClientID}, {ClientSecret});
{
///===================================================================================== ///Token Code Authorization ///=====================================================================================
var oawbForm = new OAuthWebBrowserForm();
/// Set settings oawbForm.oAuthWebBrowser1.ClientId = strCID; oawbForm.oAuthWebBrowser1.ClientSecret = strCSecret; oawbForm.oAuthWebBrowser1.RedirectUriIsFake = true; oawbForm.oAuthWebBrowser1.RedirectUri = "https://127.0.0.1:8080";
/// Open it var result = oawbForm.ShowDialog();
Console.WriteLine($"Result: " + result); Console.WriteLine($"AccessToken: " + oawbForm.oAuthWebBrowser1.AccessToken);
return (oawbForm.oAuthWebBrowser1.AccessToken);
///===================================================================================== ///End ///=====================================================================================
}
[/details]
tim.smith | 2016-10-12 16:27:14 UTC | #2
Did you see the examples in the documentation?
Client Credentials Grant (sdk readme
var accessTokenInfo = Configuration.Default.ApiClient.PostToken("18a4c365-7ea3-4f0g-9fb7-884fb4d2e9c6",
"M7FfdYQyL5TA6BdbEZ8M9-Wx4uZai1rNQ7jcuFdcJJo");
Console.WriteLine("Access token=" + accessTokenInfo.AccessToken);
Implicit Grant using oauth control (oauth control readme
// Create form
var form = new OAuthWebBrowserForm();
// Set settings
form.oAuthWebBrowser1.ClientId = "babbc081-0761-4f16-8f56-071aa402ebcb";
form.oAuthWebBrowser1.RedirectUriIsFake = true;
form.oAuthWebBrowser1.RedirectUri = "http://localhost:8080";
// Open it
var result = form.ShowDialog();
Console.WriteLine($"Result: {result}");
Console.WriteLine($"AccessToken: {form.oAuthWebBrowser1.AccessToken}");
Implicit Grant without SDK tutorial
There isn't an auth code grant flow with the oauth browser; setting the client secret doesn't do anything and that property needs to be removed from the project. The browser control intentionally doesn't support the auth code flow because there's no purpose to using that flow in a C# desktop application. There is an ASP.NET tutorial for the auth code grant, however.
flip | 2016-10-12 16:51:02 UTC | #3
That is interesting because I have tested all three, and all three work as I have then written. Bug maybe?
tim.smith | 2016-10-12 17:06:58 UTC | #4
For the auth code example, did you use a client ID that's configured for the implicit grant type maybe? The oauth browser only has code for an implicit grant. It's hardcoded with response_type=token in the URL and won't work if you use a client ID that's configured for the auth code grant.
flip | 2016-10-12 17:11:51 UTC | #5
I am using the client id only for implicit grant, but the client cred( and code auth ) require the secret.
This is assuming that the purecloud integration on the website is setup for the respective type.
tim.smith | 2016-10-12 17:13:48 UTC | #6
I am using the client id only for implicit grant
That's why your code for the auth code grant "works". It's doing an implicit grant with a client ID that's configured for an implicit grant.
client cred( and code auth ) require the secret
Correct. They also require separate oauth client configurations because you have to set the grant type on each.
system | 2017-08-28 19:27:56 UTC | #7
This post was migrated from the old Developer Forum.
ref: 498