ICEMortgageTechnology / developerconnect-dotnet-bindings

43 stars 27 forks source link

Elli.Api.OAuth.Client.ApiException : Unexpected character encountered while parsing value: <. Path '', line 0, position 0. #20

Open ryanxjohnson opened 5 years ago

ryanxjohnson commented 5 years ago

Hello,

When trying to retrieve the access token I get this exception with the below stack trace:

Client Code:

            var credentials = new UserCredential
            {
                Password = "MyPassword",
                IdentityType = IdentityType.Lender,
                InstanceId = "MyInstanceId",
                UserName = "MyUserName",
            };

            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

            var accessToken = AccessToken.GetAccessToken(credentials);

StackTrace:

Elli.Api.OAuth.Client.ApiException : Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Elli.Api.OAuth.Client.ApiClient.Deserialize(IRestResponse response, Type type)
   at Elli.Api.OAuth.Api.TokenApi.GenerateTokenWithHttpInfo(String grantType, String username, String password, String scope, String redirectUri, String code, String session)
   at Elli.Api.Base.AccessToken.GetAccessToken(UserCredential credentials, String apiClientId, String clientSecret)
paulmoseley commented 5 years ago

Hey there Ryan. You may need to manually url-encode your client secret, if it has one or several special characters in it (I know ours does, and I got a similar error initially). Certain special characters (e.g. ^) need to be replaced with their escaped values (^, for example, needs to be replaced with the string %5E).

P.S. Think before you ink…join the umpqua sustainability movement and only print this email if absolutely necessary.

paul moseley software engineer tag – application and data engineering (ade) – integration systems mobile: 503-915-6163 Webhttp://www.umpquabank.com/ | Facebookhttp://www.facebook.com/umpquabank | Twitterhttp://www.twitter.com/umpquabank

From: Ryan Johnson notifications@github.com Sent: Wednesday, September 26, 2018 8:43 PM To: EllieMae/developerconnect-dotnet-bindings developerconnect-dotnet-bindings@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [EllieMae/developerconnect-dotnet-bindings] Elli.Api.OAuth.Client.ApiException : Unexpected character encountered while parsing value: <. Path '', line 0, position 0. (#20)

[External Email]

Hello,

When trying to retrieve the access token I get this exception with the below stack trace:

Client Code:

        var credentials = new UserCredential

        {

            Password = "MyPassword",

            IdentityType = IdentityType.Lender,

            InstanceId = "MyInstanceId",

            UserName = "MyUserName",

        };

        ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

        var accessToken = AccessToken.GetAccessToken(credentials);

StackTrace:

Elli.Api.OAuth.Client.ApiException : Unexpected character encountered while parsing value: <. Path '', line 0, position 0.

at Elli.Api.OAuth.Client.ApiClient.Deserialize(IRestResponse response, Type type)

at Elli.Api.OAuth.Api.TokenApi.GenerateTokenWithHttpInfo(String grantType, String username, String password, String scope, String redirectUri, String code, String session)

at Elli.Api.Base.AccessToken.GetAccessToken(UserCredential credentials, String apiClientId, String clientSecret)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/EllieMae/developerconnect-dotnet-bindings/issues/20, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AofC5wtY_-44QbM7ggVv6j7P6svOZuQlks5ufEkzgaJpZM4W721Y. This message, including any attachments, may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.

ryanxjohnson commented 5 years ago

Thank you for the quick reply @paulmoseley .

I url encoded the secret as well as the password, but I am still getting the same exception. It seems to do the API web request, but can't deserialize the response correctly.

Should the Authorization header have a space in the value? ie "Basic "

Also in the config file I noticed the apiHost value I got from this repo has "https://api.elliemae.com.com". Should the value be "https://api.elliemae.com" instead? Not sure if this is a typo.

If I do the same API call with "https://api.elliemae.com" I get this APIException (below) so I'm not sure if I'm dealing with an actual authentication issue or some parsing issue in the deserializer.

Elli.Api.OAuth.Client.ApiException: 'Error calling GenerateToken: {"error_description":"Invalid client or client credentials","error":"invalid_client"}
'

Thanks again.

paulmoseley commented 5 years ago

Hmm. The apiHost value should definitely be ‘https://api.elliemae.com’, no doubling of the .com 😊. Given that, the response you’re getting below (the ‘invalid client’ one) is probably the correct response. Not sure whether you also need to url-encode the password (mine doesn’t need url-encoding), so you could try un-encoding that, I guess (?).

Just noticed the most important thing, though, maybe. My successful access token call has 3 arguments in the GetAccessToken method call, not one. I think you need to include the client key and client secret in your call, like this:

var accessToken = AccessToken.GetAccessToken(credentials, encApiKeyClient, encApiKeySecret);

I got this 3-argument call from the sample code Ellie Mae included on its GitHub site. The related stuff in my web.config file looks like this:

When I used Postman to play around with this, and check things out, I saw that the Authorization Header that got auto-created when I used the ‘Authorization’ section to enter the client key and secret started with ‘Basic ‘. Not sure how or if that applies to direct calls from code.

Hope this helps!

P.S. Think before you ink…join the umpqua sustainability movement and only print this email if absolutely necessary.

paul moseley software engineer tag – application and data engineering (ade) – integration systems mobile: 503-915-6163 Webhttp://www.umpquabank.com/ | Facebookhttp://www.facebook.com/umpquabank | Twitterhttp://www.twitter.com/umpquabank

From: Ryan Johnson notifications@github.com Sent: Thursday, September 27, 2018 9:58 AM To: EllieMae/developerconnect-dotnet-bindings developerconnect-dotnet-bindings@noreply.github.com Cc: Paul Moseley PaulMoseley@UmpquaBank.com; Mention mention@noreply.github.com Subject: Re: [EllieMae/developerconnect-dotnet-bindings] Elli.Api.OAuth.Client.ApiException : Unexpected character encountered while parsing value: <. Path '', line 0, position 0. (#20)

[External Email]

Thank you for the quick reply @paulmoseleyhttps://github.com/paulmoseley .

I url encoded the secret as well as the password, but I am still getting the same exception. It seems to do the API web request, but can't deserialize the response correctly.

Should the Authorization header have a space in the value? ie "Basic "

Also in the config file I noticed the apiHost value I got from this repo has "https://api.elliemae.com.com". Should the value be "https://api.elliemae.com" instead? Not sure if this is a typo.

If I do the same API call with "https://api.elliemae.com" I get this APIException (below) so I'm not sure if I'm dealing with an actual authentication issue or some parsing issue in the deserializer.

Elli.Api.OAuth.Client.ApiException: 'Error calling GenerateToken: {"error_description":"Invalid client or client credentials","error":"invalid_client"}

'

Thanks again.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/EllieMae/developerconnect-dotnet-bindings/issues/20#issuecomment-425166827, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AofC52N4kSsyzfarAn1pcfREzW5TQxJBks5ufQOjgaJpZM4W721Y. This message, including any attachments, may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.

ryanxjohnson commented 5 years ago

Thank you for clearing up the URL issue. That helped narrow down the issue to an actual authentication error with our token, which we have now resolved.

This issue can be closed!

Ellie-cpawar commented 5 years ago

@ryanxjohnson Can you please close this issue if resolved?