Twitter oauth2/token Tutorial always get error - twitter

I was follow the tutorial to make the request to obtain the response with token.But always get the error.
Here is the tutorial from...
https://dev.twitter.com/oauth/reference/post/oauth2/token
Here is the request from the postman I use.
POST /oauth2/token HTTP/1.1
Host: api.twitter.com
Authorization: Basic eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJnNmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw==
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Cache-Control: no-cache
Postman-Token: 7761e3d0-830e-eba4-00d7-9f964b3f3efb
grant_type=client_credentials
someone can help me? please.

Related

HTTP digest authentication fail due to wrong nonce-count in iOS 10

HTTP digest authentication no longer works in our app since iOS 10 due to wrong nonce-count in Authorization: Digest header generated by NSURLSession.
The same code works in iOS 9, but fail to auth in iOS 10
Create a POST request with NSURLRequest
Fire it with NSURLSession
Handle NSURLAuthenticationMethodHTTPDigest in urlSession(_:didReceive:completionHandler:) delegate
The server responds with a 401 and qop="auth" string as expected
The app requests again with the Authorization: Digest header set.
According to RFC2617:
nonce-count
This MUST be specified if a qop directive is sent (see above), and
MUST NOT be specified if the server did not send a qop directive in
the WWW-Authenticate header field. The nc-value is the hexadecimal
count of the number of requests (including the current request)
that the client has sent with the nonce value in this request. For
example, in the first request sent in response to a given nonce
value, the client sends "nc=00000001". The purpose of this
directive is to allow the server to detect request replays by
maintaining its own copy of this count - if the same nc-value is
seen twice, then the request is a replay. See the description
below of the construction of the request-digest value.
However, the nonce-count start at "nc=00000002" even for the first request in iOS 10, which cause the server to reject it.
Expect server response 200 OK
iOS 9 & Before:
POST /Tunnel/Message.aspx HTTP/1.1
Host: 172.18.70.12:3454
Accept: */*
Content-Type: application/xml
User-Agent: iViewer/1 CFNetwork/758.5.3 Darwin/15.6.0
Connection: keep-alive
Cookie:
AuthType: digest
Accept-Language: zh-tw
Content-Length: 69
Accept-Encoding: gzip, deflate
Authorization: Digest username="admin", realm="ND8422P",
nonce="cc17a78cdd96d54e012eadefe7d13d82", uri="/Tunnel/Message.aspx",
response="51587db4bcf6eeece68c4ec21108f170",
cnonce="47b8df8a980f280038834b7817250e90", nc=00000001, qop="auth"
<?xml version="1.0" encoding="UTF-8"?><GetServerInfo></GetServerInfo>
HTTP/1.0 200 OK
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/xml
Content-Length: 1127
iOS 10:
POST /Tunnel/Message.aspx HTTP/1.1
Host: 172.18.70.12:3454
Accept: */*
Content-Type: application/xml
User-Agent: iViewer/1 CFNetwork/808.0.2 Darwin/16.0.0
Connection: keep-alive
Cookie:
AuthType: digest
Accept-Language: en-us
Content-Length: 69
Accept-Encoding: gzip, deflate
Authorization: Digest username="admin", realm="ND8422P",
nonce="4b8bf8549da0c3010f031472e95f387d", uri="/Tunnel/Message.aspx",
response="91cf44bc0aadf2f743164d03b5c708c7",
cnonce="b5f9e6c69e19c1b396298d68f2aefe7e", nc=00000002, qop="auth"
<?xml version="1.0" encoding="UTF-8"?><GetServerInfo></GetServerInfo>
HTTP/1.0 401 Unauthorized
WWW-Authenticate: Digest qop="auth", realm="ND8422P", nonce="8e8b0538bb08876ac4d8203f1d14e9ac"
CSeq: 0
Is anyone facing the same issue?
The only related post I could find is:
Apple Developer Forums : Problem of the digest authentication, but no further information.
How do you fix it or get workaround on client app side without asking server side to ignore the wrong nonce-count?
Thanks.
Apple Developer Technical Support confirm that is a bug of iOS 10.
Hope it will be fixed soon.
Thank you for contacting Apple Developer Technical Support (DTS).
We believe this issue is a bug. Please file a bug report using the Bug Reporter tool https://developer.apple.com/bug-reporting/.
Update:
Apple fixed this issue in iOS 10.2 Beta 3
Chances are, the OS is sending a HEAD request first, and your server-side code isn't getting it. I would try running Charles Proxy to verify that this is what's happening.
That said, skipping a nonce count is not inherently an indication of any sort of attack. It could occur even in iOS 9 if a request got lost somehow (e.g. a network error). What's important is to ensure that the count doesn't go backwards. So I would argue that your server code is buggy and should not be rejecting that to begin with.
We have the same problem in our company as described here:
Cordova app can't connect with Dynamics NAV Web-Service (ODATA) after update to iOS 10
We can reproduce the issue both in our App and the Safari Browser with iOS 10 devices. There does not seem to be a simple client side workaround. We opened a Bug Report with Apple.
In our case the problem was solved with the 10.2 Beta release.

LinkedIN Oauth issue while getting accessToken

I was trying to integrate linkedIn oauth into my website, But I'm stuck on this error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.linkedin.com/uas/oauth2/accessToken. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
I'm getting this error when i was trying to get the accessToken using authorization code.
Request & response view from livehttpheaders are as follows
https://www.linkedin.com/uas/oauth2/accessToken
POST /uas/oauth2/accessToken HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Referer: https://www.clovedigital.com/oauth/oauth_lnk.pl?code=AQRLhiv3oDKfFdN2ccXtSCOaC3ujQncdJ1QeFYw_c6iQVvrvy_M4w13IYny3cIzpPWzBPmOaI8DMZFp8pjbBvJHeni4MhbF5ig27SLkmVUHHKQYwB2U&state=mbclqkji
Content-Length: 277
Origin: https://www.clovedigital.com
Connection: keep-alive
grant_type=authorization_code&code=AQRLhiv3oDKfFdN2ccXtSCOaC3ujQncdJ1QeFYw_c6iQVvrvy_M4w13IYny3cIzpPWzBPmOaI8DMZFp8pjbBvJHeni4MhbF5ig27SLkmVUHHKQYwB2U&redirect_uri=https%3A%2F%2Fwww.clovedigital.com%2Foauth%2Foauth_lnk.pl&client_id=xxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxx
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Content-Encoding: gzip
Content-Language: en-US
Content-Length: 220
Content-Type: application/json;charset=UTF-8
Even though the response code is 200, I haven't receive any accessToken as response. Instead I could see those Cross origin error message in console. Need help in resolving this issue

OAuth 2.0 Access Token Request using Google OAuth Playground

I'm trying to exchange an OAuth 2.0 Authorization Code for an Access Token using Google's OAuth Playground tool. So, I get to step 2 and there it shows the HTTP POST request it will be sending out to MY_SERVER (I obfuscated the exact IP address for security reasons).
To me this looks correct and if I use a POST tool with exactly this request, it does arrive on my server. Launching it from the Playground, it doesn't arrive on my web server (nothing in the logs).
Does anybody have an idea what might be going wrong?
THIS POST
POST /tb/html/token/ HTTP/1.1
Host: MY_SERVER.COM
Content-length: 170
content-type: application/x-www-form-urlencoded
user-agent: google-oauth-playground
code=Splxl0576dGF6567gFG&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=jarne&scope=&client_secret=some_secret&grant_type=authorization_code
RESULTS IN
HTTP/1.1 400 Bad Request
Content-length: 105
Content-type: text/plain
An error occured while connecting to the server: Unable to fetch URL: http://MY_SERVER.COM/tb/html/token/

How to share image to Path.com for iOS

I try the guide here: Path Developers Docs
I can get access token from Path API.
But I can not send post photo request "POST /1/moment/photo".
Does anyone can do it?
I used gtw-oauth2 to get access token from Path API.
If you see the request format
POST /oauth2/access_token HTTP/1.1
Host: partner.path.com
Content-Type: application/x-www-form-urlencoded
Content-Length: <LENGTH>
grant_type=authorization_code&client_id=CLIENT&client_secret=SECRET&code=CODE
Content-Length line is not required, in getting permanent access token
code=CODE - was very confusing, and i see you can get temporary access token, but can't get permanent access token, in this line, capital CODE MUST BE REPLACED WITH TEMPORARY ACCESS TOKEN
don't change grant_type=authorization_code only
I think this will help you a lot
POST /oauth2/access_token HTTP/1.1
Host: partner.path.com
Content-Type: application/x-www-form-urlencoded
Content-Length:
grant_type=authorization_code&client_id=CLIENT&client_secret=SECRET&code=CODE

AFNetworking - 401 response from https server (login action)

I know that this problem may be api specified but really need to try.
I have to requests. One made with ASIHTTP and the other one with AFNetworking. Server denies afnetworking with 401 code.
I have to adjust afnetworking to the working state, and have in mind that changes at the server side are impossible atm.
ASIHTTP (working one)
POST https://cant.post.address HTTP/1.1
Host: cant.post.address
Accept: application/json
User-Agent: My Application(iPhone; iPhone OS 6.1.3; pl_PL)
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Accept-Encoding: gzip
Connection: close
Proxy-Connection: close
Content-Length: 31
AFNETWORKING (getting denied with 401)
POST https://cant.post.address HTTP/1.1
Host: cant.post.address
Accept: application/json
Accept-Encoding: gzip, deflate
User-Agent: MyApp(iPhone; iOS 6.1.3; Scale/2.00)
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Accept-Language: pl;q=1, en;q=0.9, fr;q=0.8, de;q=0.7, ja;q=0.6, nl;q=0.5
Connection: keep-alive
Proxy-Connection: keep-alive
Content-Length: 31
There were some other headers but they were identical so I removed for simplicity. What could cause rejecting here? user-agent? Doubt that. What about Connection and Proxy-Connection? Can i change it to close in AFN?
401 is the HTTP status code "Unauthorized", which is sent back from the server when the provided credentials are invalid (incorrect username / password). Check that you're sending the correct information.
Also, JSON serialization is provided automatically when AFHTTPClient is configured correctly. See the example app in the AFNetworking repository to see how that is done.

Resources