• Rollsroyc3
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

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