C# Dwolla: Get Dwolla OAuth2 Access Token

Back to Index

Sends a POST to get a Dwolla OAuth2 access token. Note: This is a simple POST to get a simple response that contains the OAuth2 access token. Fetching OAuth2 access tokens for Dwolla do not involve displaying a browser (it is not 3-legged OAuth2).

Documentation: https://docsv2.dwolla.com/#application-authorization

CURL Command

curl -X POST https://sandbox.dwolla.com/oauth/v2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=DWOLLA_KEY" \
-d "client_secret=DWOLLA_SECRET" \
-d "grant_type=client_credentials"

C# Example

Chilkat.Rest rest = new Chilkat.Rest();
bool success;

//  URL: https://sandbox.dwolla.com/oauth/v2/token
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = rest.Connect("sandbox.dwolla.com",port,bTls,bAutoReconnect);
if (success != true) {
    Debug.WriteLine("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
    Debug.WriteLine(rest.LastErrorText);
    return;
}

rest.AddQueryParam("client_id","DWOLLA_KEY");
rest.AddQueryParam("client_secret","DWOLLA_SECRET");
rest.AddQueryParam("grant_type","client_credentials");

string strResponseBody = rest.FullRequestFormUrlEncoded("POST","/oauth/v2/token");
if (rest.LastMethodSuccess != true) {
    Debug.WriteLine(rest.LastErrorText);
    return;
}

Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
jsonResponse.Load(strResponseBody);

string access_token;
string token_type;
int expires_in;

access_token = jsonResponse.StringOf("access_token");
token_type = jsonResponse.StringOf("token_type");
expires_in = jsonResponse.IntOf("expires_in");

Sample JSON Response Body

{
  "access_token": "x0M8TCnDUTuMhA2Gp7dZyAYL3iORQZYzLlZOn7EximEGSrddpC",
  "token_type": "bearer",
  "expires_in": 3604
}