Page 1 of 1

OAuth2 WinHttpSendRequest 12002

Posted: Fri Jan 29, 2021 10:49 pm
by mark.civ
Hi,

From the Package Manager, I am trying to use the Login Form to connect using OAuth2 to Google and Microsoft. I have entered the client id and secret for each in the configuration, and been to the third party sites and set up things there. When using the Login Form, I correctly navigate to the IDP site to sign in, and receive the code back through the browser url. At the point the POST is being performed to exchange the code for the access token, this is failing with a 'WinHttpSendRequest: 12002: The operation timed out' error.

I have also coded a simple request to test the issue (which fails with the same 12002 error code)

Code: Select all

Mthroutine Name(PostTokenRequest) Access(*PUBLIC)

Define_Com Class(#XPRIM_HttpRequest) Name(#Request)

#Request.Content.AddUrlEncodedFormValue( 'code' '#AuthorizationCode' )
#Request.Content.AddUrlEncodedFormValue( 'client_id' '#COM_SELF.GetOAuth2ClientID' )
#Request.Content.AddUrlEncodedFormValue( 'client_secret' '#COM_SELF.GetOAuth2ClientSecret' )
#Request.Content.AddUrlEncodedFormValue( 'grant_type' 'authorization_code' )
#Request.Content.AddUrlEncodedFormValue( 'redirect_uri' '#COM_SELF.GetOAuth2RedirectUri' )

#Request.DoPost Url('https://www.googleapis.com/oauth2/v4/token')

Define Field(#ResponseText) Type(*NVARCHAR)
#ResponseText := #Request.Response.AsString

Endroutine
Sending this exact same 'bogus' request in postman connects to the site, and yields an expected error from the IDP.

Code: Select all

{
    "error": "invalid_request",
    "error_description": "Invalid parameter value for redirect_uri: Missing scheme: #COM_SELF.GetOAuth2RedirectUri"
}
But, from within LANSA the https post produces the 12002 issue.

If I post to a localhost http from within LANSA the post works correctly.
If I post to the same https url using postman (as shown above), the post from postman works correctly

I have disabled my firewall, dropped off the company VPN, in case they were causing an issue; but to no avail.

Anyone experienced the issue? Any insight on fixing the issue?

I am in the middle of coding a SSO solution to a third party IDP, and am experiencing the same issue there, and with connecting to Azure AD. I am hoping it is likely something simple I have overlooked.

Re: OAuth2 WinHttpSendRequest 12002

Posted: Thu Feb 04, 2021 10:09 am
by Tim McEntee
Hi Mark

My experience with the HTTP response code is that any value that is not in the list of standard response codes 1nn to 5nn then the error is likely with your code. I recently got a zero which ended up being a fatal error with slashes in a windows path instead of backslashes. Also I got a 600 error which was something to do with my config.

Anyway I noticed that you have quotes around your method calls.
#Request.Content.AddUrlEncodedFormValue( 'client_id' '#COM_SELF.GetOAuth2ClientID' )
You need to check that your code is not setting the client_id to the string #COM_SELF.GetOAuth2ClientID instead of calling the method.

There is a section in the help that details how to produce logs for these calls which will allow you to inspect the values of each property.
https://docs.lansa.com/15/en/lansa018/i ... %7C_____14

Tim