Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCR API Result URL Authentication Failure #36

Open
lordgreg opened this issue Dec 1, 2015 · 13 comments
Open

OCR API Result URL Authentication Failure #36

lordgreg opened this issue Dec 1, 2015 · 13 comments

Comments

@lordgreg
Copy link

lordgreg commented Dec 1, 2015

I've tried several times now, to open resultUrl which I get from scanning business card. Everytime I get

<?xml version="1.0" encoding="utf-8"?> <error>  InvalidAuthenticationInfo <message>Authentication information is not given in the correct format. Check the value of Authorization header. RequestId:19048c46-0001-000f-5576-2b1fec000000 Time:2015-11-30T13:56:28.6142735Z</message> </error>
  • i've tried using Basic Auth with User/Pass where user is APP and password is APP KEY/PASSWORD.
  • i've also tried with No Auth

So, what am I doing wrong then?

I'm using $http requests through Angular App. I've tried to request the GET with POSTMAN with the same result.

Thank you for your feedback.

@Dmitry-Me
Copy link
Contributor

Use no auth - the URL which you obtained from getTaskStatus contains an access token which should be enough. Use Fiddler or equivalent thereof to log actual requests and see whether they look right.

@lordgreg
Copy link
Author

lordgreg commented Dec 1, 2015

Thank you @Dmitry-Me for replying. As said, I've also tried calling the last resultUrl with No-Auth but then, I get 401. I'll post the Charles (proxy server) log asap 👍

@lordgreg
Copy link
Author

lordgreg commented Dec 1, 2015

Hi again ( @Dmitry-Me ). Here are my infos from Charles (mac proxy server):

getTaskStatus request:

GET /getTaskStatus?taskId=05ae5bd4-4d5a-4ab7-a6e3-67510c298fab HTTP/1.1
Host: cloud.ocrsdk.com
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 07CD202D-0D85-46E6-B6E4-6A556C1E51E2
Authorization: Basic -----my-basic-auth-here----------- (app_id:app_pass in base64)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

getTaskStatus response:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/xml; charset=utf-8
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
X-Thumbs-Up: Thumbs up for looking this deep!
Date: Tue, 01 Dec 2015 14:37:45 GMT
Content-Length: 463

<?xml version="1.0" encoding="utf-8"?><response><task id="05ae5bd4-4d5a-4ab7-a6e3-67510c298fab" registrationTime="2015-12-01T14:37:41Z" statusChangeTime="2015-12-01T14:37:42Z" status="Completed" filesCount="1" credits="10" resultUrl="https://ocrsdk.blob.core.windows.net/files/05ae5bd4-4d5a-4ab7-a6e3-67510c298fab.result?sv=2012-02-12&amp;se=2015-12-02T00%3A00%3A00Z&amp;sr=b&amp;si=downloadResults&amp;sig=AonOnG6OCU23ax3DuOKYGLzsJxdAVs8Xa6Ngz9WlxTo%3D" /></response>

download URL request:

GET /files/05ae5bd4-4d5a-4ab7-a6e3-67510c298fab.result?sv=2012-02-12&se=2015-12-02T00:00:00Z&sr=b&si=downloadResults&sig=AonOnG6OCU23ax3DuOKYGLzsJxdAVs8Xa6Ngz9WlxTo= HTTP/1.1
Host: ocrsdk.blob.core.windows.net
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 07CD202D-0D85-46E6-B6E4-6A556C1E51E2
Authorization: Basic -----my-basic-auth-here----------- (app_id:app_pass in base64)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

download URL response:

HTTP/1.1 400 Authentication information is not given in the correct format. Check the value of Authorization header.
Content-Length: 297
Content-Type: application/xml
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: e2f18ea1-0001-002a-4945-2c875f000000
Date: Tue, 01 Dec 2015 14:37:47 GMT

<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidAuthenticationInfo</Code><Message>Authentication information is not given in the correct format. Check the value of Authorization header.
RequestId:e2f18ea1-0001-002a-4945-2c875f000000
Time:2015-12-01T14:37:48.5723945Z</Message></Error>

@Dmitry-Me
Copy link
Contributor

The second GET should have no Authorization header

@lordgreg
Copy link
Author

lordgreg commented Dec 2, 2015

Hi @Dmitry-Me,

as said, I've tried to access it without AUTH request. As I've already said, I've tried that solution already. But I didn't tried it more times in a row. So, when making a request, I usually also got (403) error for resultUrl. 2nd request also fails. Usually, at 3rd or 4th request then it finally works.

Can you please tell me why is that so?

@Dmitry-Me
Copy link
Contributor

Do you have a piece of log showing how it takes several attempts?

@lordgreg
Copy link
Author

lordgreg commented Dec 2, 2015

Of course @Dmitry-Me

Test #1: SUCCESS

GET /getTaskStatus?taskId=8b4d063a-2e43-4377-962c-3dd7b3f99ca1 HTTP/1.1
Host: cloud.ocrsdk.com
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
Authorization: Basic --------
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

GET /files/8b4d063a-2e43-4377-962c-3dd7b3f99ca1.result?sv=2012-02-12&se=2015-12-02T22:00:00Z&sr=b&si=downloadResults&sig=9r3URfVYl3uhb/5U7L9N6Wpnk/5GMPacwsZ4zJeZEYs= HTTP/1.1
Host: ocrsdk.blob.core.windows.net
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

Test #2: FAIL

GET /getTaskStatus?taskId=67fa5730-7a84-402d-80e0-fe725511af11 HTTP/1.1
Host: cloud.ocrsdk.com
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
Authorization: Basic -------
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

GET /files/67fa5730-7a84-402d-80e0-fe725511af11.result?sv=2012-02-12&se=2015-12-02T22:00:00Z&sr=b&si=downloadResults&sig=vfCAC71J3ly+kbfxf+vI/+ZdRG4Sjr/a2RcCMW1gL+g= HTTP/1.1
Host: ocrsdk.blob.core.windows.net
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

response for fail:
<Error>
    <Code>AuthenticationFailed</Code>
    <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
        RequestId:d3db7673-0001-003a-3f00-2db1b9000000 Time:2015-12-02T12:53:09.1944683Z</Message>
    <AuthenticationErrorDetail>Signature size is invalid</AuthenticationErrorDetail>
</Error>

Test #3: FAIL

GET /getTaskStatus?taskId=01608d15-8dde-4da7-971d-767329cce758 HTTP/1.1
Host: cloud.ocrsdk.com
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
Authorization: Basic -------
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

GET /files/01608d15-8dde-4da7-971d-767329cce758.result?sv=2012-02-12&se=2015-12-02T22:00:00Z&sr=b&si=downloadResults&sig=Rp+W80Mv5SilL5y7el49gsRUKvhP3ZiHmwmhOJXILW0= HTTP/1.1
Host: ocrsdk.blob.core.windows.net
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

Test #4: SUCCESS

GET /getTaskStatus?taskId=3b2fd9f5-9762-4777-be41-f9c87c39aac7 HTTP/1.1
Host: cloud.ocrsdk.com
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
Authorization: Basic -------
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

Test #5: FAIL

GET /getTaskStatus?taskId=4425af22-9ada-40a2-8fa3-b9eef02f6177 HTTP/1.1
Host: cloud.ocrsdk.com
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
Authorization: Basic -------
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

GET /files/4425af22-9ada-40a2-8fa3-b9eef02f6177.result?sv=2012-02-12&se=2015-12-02T22:00:00Z&sr=b&si=downloadResults&sig=6KwgYSf/f+MGLkiCJuZDgHoNos4fmfy/AKF+puQMXp4= HTTP/1.1
Host: ocrsdk.blob.core.windows.net
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

response
<Error>
    <Code>AuthenticationFailed</Code>
    <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
        RequestId:6e3f1e6a-0001-0046-6801-2d2c8c000000 Time:2015-12-02T12:58:35.5973265Z</Message>
    <AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail>
</Error>

Test #6: SUCCESS

GET /getTaskStatus?taskId=f9b8a6c0-94ce-401d-9cbd-00b751f85def HTTP/1.1
Host: cloud.ocrsdk.com
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
Authorization: Basic -------
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

GET /files/f9b8a6c0-94ce-401d-9cbd-00b751f85def.result?sv=2012-02-12&se=2015-12-02T22:00:00Z&sr=b&si=downloadResults&sig=kO8SiLpmtn3fj7chhtPdsWkkXoCY1ngL20sEr2Pd/Ng= HTTP/1.1
Host: ocrsdk.blob.core.windows.net
Connection: keep-alive
Accept: application/json, text/plain, */*
X-DevTools-Emulate-Network-Conditions-Client-Id: 6A4769B6-DA9C-4644-A189-C9BD72CF9349
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) FischermobileCRM/0.1.0 Chrome/45.0.2454.85 Electron/0.34.1 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US

@Dmitry-Me
Copy link
Contributor

You can see that successful requests differ from failed ones in one aspect only - requests fails when there's at least one "plus" character in the "sig" parameter. Plus and slash are reserved characters and must be percent-encoded https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters

Which language/framework are you using? We'd like to make some effort to improve our code samples.

@lordgreg
Copy link
Author

lordgreg commented Dec 2, 2015

I thought that too @Dmitry-Me but the first Successful request SIG also has / in it. And it works. However, I'll try to encode url so we get %20 etc instead of special characters and report results again.

This is being developed in front-end JS (no Node app). Pure Angular way.

@Dmitry-Me
Copy link
Contributor

So technically it's just JavaScript, isn't it? Btw how will you guard your application password if it's client side code?

@lordgreg
Copy link
Author

lordgreg commented Dec 2, 2015

Exactly. The app is currently being developed. Later, we're going to send requests to our proxy, which will append app id and password to http requests so no credentials are going to be stored in app itself 👍

@lordgreg
Copy link
Author

lordgreg commented Dec 2, 2015

@Dmitry-Me

here's the update: I was always decoding URL which I got from TaskStatus Completed. Taking the URL directly from response and calling it without auth, it works.

So it was actually my error. I would suggest, however, that you update your DOC or code and comment in the info, NOT TO ENCODE the recieved url but just use it as is.

Thank you very much for your support @Dmitry-Me. You were really really helpful.

Kind regards,

Gregor

@Dmitry-Me
Copy link
Contributor

Well, the Node.js sample seems to do just that - https://github.com/abbyysdk/ocrsdk.com/blob/master/JavaScript/test.js#L61 How can that be improved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants