ASP.net VB.net problem with API after publishing

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

I use the following VB.net code to authenticate against the Xero API. It worked fine on my local machine
but I published the site and changed the post back url from my local machine to that of the published site and it doesn't work

    Protected Function XeroAuthenticate(inpage As Page, authpagereturnedauthentication As Boolean, incode As String) As XeroCoreApi
        ' This procedure will return w working XeroCoreApi if successful and nothing otherwise
        ' Set client secrets for general use and then load any override ones from the web.config file
        Dim myxeroconsumer As New Consumer("xxx", "yyyy")
        Dim myxerouser = New ApiUser() With {.Name = "mxx@yahoo.com"}

        ' If user defined ID and Secrets exist then use those instead
        If Not System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientId") Is Nothing Then
            If Not System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientSecret") Is Nothing Then
                If System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientId").ToString <> "" Then
                    myxeroconsumer = New Consumer(System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientId").ToString, System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientSecret").ToString)
                End If
            End If
        End If

        ' Define Page Call Information
        'Dim myxerocallbackurl = "http://localhost:62054/Default.aspx"
        Dim myxerocallbackurl = "http://groundxero.azurewebsites.net/Default.aspx"
        Dim myxeromemorystore = New MemoryAccessTokenStore()
        Dim myxerorequestTokenStore = New MemoryRequestTokenStore()
        Dim myxerobaseapiurl = "https://api.xero.com"

        ' Authenticate with Xero
        Dim myxeroauthenticator As New PublicMvcAuthenticator(myxerobaseapiurl, myxerobaseapiurl, myxerocallbackurl, myxeromemorystore, myxeroconsumer, myxerorequestTokenStore)

        If authpagereturnedauthentication = False Then
            ' Redirect to the authentication page
            Dim requri As String = myxeroauthenticator.GetRequestTokenAuthorizeUrl(myxerouser.Name)
            If requri <> "" Then Response.Redirect(requri, True)
            Return Nothing
        Else
            ' Validate token using querystrings that have been returned from the authentication process
            Dim myxerotoken As IToken = myxeroauthenticator.RetrieveAndStoreAccessToken(myxerouser.Name, Request.QueryString("oauth_token").ToString, Request.QueryString("oauth_verifier").ToString, Request.QueryString("org").ToString)
            If Not myxerotoken Is Nothing Then
                Dim myxeroapi As New XeroCoreApi("https://api.xero.com", myxeroauthenticator, myxeroconsumer, myxerouser)
                Return myxeroapi
            Else
                Return Nothing
            End If
        End If
    End Function

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Services Manager
Commented:
Noticeably absent is any sort of error handling.
Can you put this code in a Try /Catch block and log the error? Or can you see the error in IIS log?

There could be numerous reasons it doesn't work on the server but works on your machine.
If I had to guess in the dark, I guess it's a protocol error.. due to security settings on the server versus your local machine. If you can verify that is the case, you can try the following...

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls

Open in new window


Also, if you had to register any DLL's to your machine to get this working, you would also have to do so on the server.  Make sure the server is using the same .NET version as well.
Murray BrownASP.net/VSTO Developer

Author

Commented:
Hi. So with error handling I get this error oauth_problem=parameter_rejected&oauth_problem_advice=Callback%20url%20is%20not%20in%20the%20registered%20callback%20domain
Murray BrownASP.net/VSTO Developer

Author

Commented:
"if you had to register any DLL's to your machine to get this working, you would also have to do so on the server"
How do I do this? Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial