Authenticate using the Web-Server Authentication Flow
masterThe Web-Server flow allows users to authenticate with their own credentials.
- Generate Authorization URL: Use
Common.FormatAuthUrlto create a URL that directs the user to Salesforce. Replacelogin.salesforce.comwithtest.salesforce.comif using a sandbox. - Handle Callback: After the user logs in, retrieve the
codefrom the callback and useWebServerAsyncto request the access token.
// 1. Create the auth URL
var url = Common.FormatAuthUrl(
"https://login.salesforce.com/services/oauth2/authorize",
ResponseTypes.Code,
"YOURCONSUMERKEY",
HttpUtility.UrlEncode("YOURCALLBACKURL"));
// 2. After user callback, exchange code for token
await auth.WebServerAsync("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURCALLBACKURL", code);