• Tew Wer
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Having a problem getting a salesforce access token. Getting the access token works fine in postman, but what I'm trying to do it in C# i'm getting an error.
I've tried to doing the equivlent to what I was doing in postman but I'm not sure if getting this right.
 
var client = new HttpClient();
        string baseAddress = @"https://test.salesforce.com/services/oauth2/token";

        string grant_type = "authorization_code";
        string client_id = "client_id here";
        string client_secret = "client_secret here";
        string auth_url = "https://test.salesforce.com/services/oauth2/authorize";
        string callback_url = "https://app.getpostman.com/oauth2/callback";
        string redirect_uri = "https://app.getpostman.com/oauth2/callback";

        var form = new Dictionary<string, string>
            {
                {"grant_type", grant_type},
                {"client_id", client_id},
                {"client_secret", client_secret},
                {"auth_url", auth_url},
                {"callback_url", callback_url},
                {"redirect_uri", redirect_uri}
            };

        HttpResponseMessage tokenResponse =  client.PostAsync(baseAddress, new FormUrlEncodedContent(form)).GetAwaiter().GetResult();
        var jsonContent =  tokenResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult();



This is the error I'm getting:
{ 
"error": "invalid_grant", 
"error_description":"invalid authorization code" 
}

 
Having a problem getting a salesforce access token. Getting the access token works fine in postman, but what I'm trying to do it in C# i'm getting an error.
I've tried to doing the equivlent to what I was doing in postman but I'm not sure if getting this right.
 
var client = new HttpClient();
        string baseAddress = @"https://test.salesforce.com/services/oauth2/token";

        string grant_type = "authorization_code";
        string client_id = "client_id here";
        string client_secret = "client_secret here";
        string auth_url = "https://test.salesforce.com/services/oauth2/authorize";
        string callback_url = "https://app.getpostman.com/oauth2/callback";
        string redirect_uri = "https://app.getpostman.com/oauth2/callback";

        var form = new Dictionary<string, string>
            {
                {"grant_type", grant_type},
                {"client_id", client_id},
                {"client_secret", client_secret},
                {"auth_url", auth_url},
                {"callback_url", callback_url},
                {"redirect_uri", redirect_uri}
            };

        HttpResponseMessage tokenResponse =  client.PostAsync(baseAddress, new FormUrlEncodedContent(form)).GetAwaiter().GetResult();
        var jsonContent =  tokenResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult();



This is the error I'm getting:
{ 
"error": "invalid_grant", 
"error_description":"invalid authorization code" 
}

 
Having a problem getting a salesforce access token. Getting the access token works fine in postman, but what I'm trying to do it in C# i'm getting an error.
I've tried to doing the equivlent to what I was doing in postman but I'm not sure if getting this right.
 
var client = new HttpClient();
        string baseAddress = @"https://test.salesforce.com/services/oauth2/token";

        string grant_type = "authorization_code";
        string client_id = "client_id here";
        string client_secret = "client_secret here";
        string auth_url = "https://test.salesforce.com/services/oauth2/authorize";
        string callback_url = "https://app.getpostman.com/oauth2/callback";
        string redirect_uri = "https://app.getpostman.com/oauth2/callback";

        var form = new Dictionary<string, string>
            {
                {"grant_type", grant_type},
                {"client_id", client_id},
                {"client_secret", client_secret},
                {"auth_url", auth_url},
                {"callback_url", callback_url},
                {"redirect_uri", redirect_uri}
            };

        HttpResponseMessage tokenResponse =  client.PostAsync(baseAddress, new FormUrlEncodedContent(form)).GetAwaiter().GetResult();
        var jsonContent =  tokenResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult();



This is the error I'm getting:
{ 
"error": "invalid_grant", 
"error_description":"invalid authorization code" 
}