Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
C# sample for getting a Concur OAuth token via native flow
/// <summary>
/// Get a Concur OAuth token using the "Native Flow"
/// </summary>
/// <param name="loginID">Concur login ID of the user that is requesting the token</param>
/// <param name="password">Password for the specified user</param>
/// <param name="appKey">Application authorization key identifying the application that the token will access
/// (the "Key" field from the "New/Modify Partner Application" dialog box on the Web Services administration page.)</param>
/// <returns>Access token, good for one year.</returns>
public string GetOAuthToken(string loginID, string password, string appKey)
// Base-64 encode the credentials for basic auth
string encodedCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(loginID + ":" + password));
// Create the request and add the credentials and app key to the HTTP headers
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("");
req.Method = "GET";
req.Headers.Add("Authorization", "Basic " + encodedCredentials);
req.Headers.Add("X-ConsumerKey", appKey);
// Make the request and get the response
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
// Load the XML response and parse the token
XmlDocument doc = new XmlDocument();
string token = doc.SelectSingleNode("/Access_Token/Token").InnerText;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment