Hello everyone,
I'm a year young to C# and brand new to the concept of API's. Been having sometime struggling with the OAuth process using the OAuth2Helper class.
While I already have the AppKey and AppSecret from App Console, everytime I use the authorization code from GetAuthorizeURI (no redirectURI, I just copy/paste the authorization code into a WinForm), and push it into ProcessCodeFlowAsync(AuthCode, AppKey, AppSecret); I get an OAuth2Exception invalid_grant error. Anyone knows what's causing this?
Here's the code I'm working on.
public class Info {
public static DropboxTeamClient teamClient = new DropboxTeamClient(AccessToken);
public static DropboxClient admin = new DropboxClient(AccessToken);
public static string AuthorizationCode { get; set; }
public static async Task Authorize()
{
Uri redirect = new Uri("https://www.dropbox.com/oauth2/");
var getURL = DropboxOAuth2Helper.GetAuthorizeUri(AppKey);
System.Diagnostics.Process.Start(getURL.ToString());
var token = new GetAuthToken();
token.BringToFront();
Application.Run(token);
while (string.IsNullOrEmpty(AuthorizationCode))
{
MessageBox.Show("BEEP! NO PARAMETERS GIVEN", "Null Parameter");
token = new GetAuthToken();
Application.Run(token);
}
OAuth2Response AuthFlow;
bool i = true;
while (i)
{
try
{
AuthFlow = await DropboxOAuth2Helper.ProcessCodeFlowAsync(AuthorizationCode, AppKey, AppSecret);
break;
}
catch (OAuth2Exception e)
{
MessageBox.Show("BEEP! INCORRECT CODE GIVEN.", "Wrong Authorization Code");
token = new GetAuthToken();
Application.Run(token);
}
}
AuthFlow = await DropboxOAuth2Helper.ProcessCodeFlowAsync(AuthorizationCode, AppKey, AppSecret, null,null) ;
AccessToken = AuthFlow.AccessToken;
MessageBox.Show(string.Format("The access token is {0}.", AccessToken), "SUCCESS!");
}
}