function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rollsroyc3Rollsroyc3 

HTTP 400 error on POST request getting token authentication

I am trying to authenticate my remote access app, I can successfully get the code in the first step but when I send the second post to https://login.salesforce.com/services/oauth2/token I get a 400 Bad Request. Here is the .net code I am using, anyone have any ideas why this might not be working?

 

 Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        'If Request.QueryString("code") Then
        Dim strCode = Request.QueryString("code")
        Dim strToken = getToken(strCode)
        ltlText.Text = strToken
        'Else

        'End If
    End Sub

    Private Function getToken(code As String) As String
        Dim URI As String = "https://login.salesforce.com/services/oauth2/token"
        Dim body As StringBuilder = New StringBuilder()

        body.Append("code=" & HttpUtility.UrlPathEncode(code) & "&")
        body.Append("grant_type=authorization_code&")
        body.Append("client_id=" & HttpUtility.UrlPathEncode(clientKey) & "&")
        body.Append("client_secret=" & HttpUtility.UrlPathEncode(clientSecret) & "&")
        body.Append("redirect_uri=" & HttpUtility.UrlPathEncode(redirectURL))

        Dim result As String = HttpPost(URI, body.ToString())

        Return result
    End Function

 

buthfabuthfa

You need to supply username and password as well and change grant type to password.

 

body.Append("username=" & HttpUtility.UrlPathEncode(username))
 body.Append("password=" & HttpUtility.UrlPathEncode(password + securitytoken))
cplusplus_pleasecplusplus_please
If you are trying to get authentication token, you have to read this article: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_concepts_security.htm

Since buthfa seems to be on the same page as you, I am not sure if I am out of place here



=============================
Developer for www.voicent.com
Voicent provides CRM, auto dialer, predictive dialer, reminder, and call center solution that is suitable for anyone in any level
Voicent strives to meet customer demands to integrate Voicent software with CRM of their choice.