0
using (var client = new HttpClient())
        {
            var request = new FormUrlEncodedContent(new Dictionary<string, string>
            {                   
                { "client_id", consumerKey},
                { "client_secret", consumerSecret},
                { "redirect_uri", "https://localhost:44324/"},
                { "response_type", "token"}
            });
            request.Headers.Add("X-PrettyPrint", "1");
            var response = client.PostAsync(loginURL, request).Result;
            jsonResponse = response.Content.ReadAsStringAsync().Result;
        }

The above code is redirecting me to salesforce login page and after entering the credentials it redirects to the callback url with the access token value in it.

https://localhost:44324/#access_token=00D5g000004EZsd%21ARIAQIknKTgasR0GjL1sxS.AuzMhTr.QNh2MU.qE9yPVCgvrPOKO9wmmU98YS3zFDZ0i7xr9Q9OsiN6rqNVB7k_wYg80PLBt&instance_url=https%3A%2F%2Faccenture854-dev-ed.my.salesforce.com&id=https%3A%2F%2Flogin.salesforce.com%2Fid%2F00D5g000004EZsdEAG%2F0055g000002qAkZAAU&issued_at=1613988715969&signature=E9OwlwTp%2FftrP%2FWN0xocr5hqLUE1Ra5oO6GZ6YVgaPE%3D&scope=full&token_type=Bearer

Now is there a way I can get this access token from above url in my asp.net code?

0

I think Oauth flow you are using is not correct.You are using webserver flow,In this flow you need the user to enter the username and password and authorize post which it gives you the access token in the callback URI.

you need to use one of the below 2 flows if you want to do it without user interaction.

Oauth2 username/password flow

Oauth2 JWT flow for server to server integration.

username/password flow is not something recommended by salesforce and should only be used as an exception.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.