Newbie OAuth issue: Error when trying to use the PHPoAuthLib OAuth lib - oauth

I've got an issue using this OAuth lib when connecting with twitter:
https://github.com/Lusitanian/PHPoAuthLib
I'm using the following url to connect:
http://www.myserver.com/oauth/examples/twitter.php?go=go
I'm getting the following error:
Fatal error: Uncaught exception 'OAuth\Common\Http\Exception\TokenResponseException' with message 'file_get_contents(https://api.twitter.com/oauth/request_token): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized ' in /webDeploy/V2/sites/wandexBB/oauth/src/OAuth/Common/Http/Client/StreamClient.php:75 Stack trace: #0 /webDeploy/V2/sites/wandexBB/oauth/src/OAuth/OAuth1/Service/AbstractService.php(52): OAuth\Common\Http\Client\StreamClient->retrieveResponse(Object(OAuth\Common\Http\Uri\Uri), Array, Array) #1 /webDeploy/V2/sites/wandexBB/oauth/examples/twitter.php(59): OAuth\OAuth1\Service\AbstractService->requestRequestToken() #2 {main} thrown in /webDeploy/V2/sites/wandexBB/oauth/src/OAuth/Common/Http/Client/StreamClient.php on line 75
It looks like the request body is empty.
I see in the code the following params are being used:
$_GET['oauth_token'],
$_GET['oauth_verifier'],
What are these params? I see in my twitter account I have various tokens available after I created my app on twitter, is it something to do with that?
I'm lost :/ This could be the wrong approach altogether.
Can anyone help with this?
Thanks in advance.

This lib seems to have a bug relating to the twitter implementation. Now using a different lib and got that going much more easily:
https://github.com/sudocode/ohmy-auth

Related

com.microsoft.graph.http.GraphServiceException: Error code: SyncStateInvalid

com.microsoft.graph.http.GraphServiceException: Error code: SyncStateInvalid
Error message: The sync state identified using the request token 'HzWyBB6EZsMOpd9NmgmVnqAnVEMAAAQ9rM8FAwAA' is no longer valid.
GET https://graph.microsoft.com/v1.0/users/6be2c2df-8e20-4f99/mailFolders/AQMkADlmY2YxNTY3LWVhNjItNDFhMS1iZDA0LWZ/messages/microsoft.graph.delta?$deltatoken=LztZwWjo5IivWBhyxw5rAHNeTrUj6tmJCwsicW9zTkZhNFWO0u7VKvvdkBxQHWUvDsSPLMpUBSlb3nEcc_qVbTk1hQlWa3MIyqHvnT47wRA.NIA-bd_JnbZrpOuTHnjHoWWo1K5QPy4CLrFTODjYn9c
Prefer : odata.maxpagesize=1
Prefer : IdType="ImmutableId"
SdkVersion : graph-java/v1.6.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
Hi guys, I'm getting the above SyncStateInvalid error, I've done a search, realizing that most people are facing SyncStateNotFound error instead.
Not sure if anyone faces this issue before and knows what is the fix.
I am trying to sync incremental mail messages based on the delta token.
I've tried to paste the same link in graph explorer, and was able to get result.

Data posting error through PHP Web service in IOS

I'm using this link How to send POST and GET request? . Method to POST my form data to a php web service but when i hit submit button it shows this error: requestReply:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'description' cannot be null' in /var/sites/p/pk.house/public_html/app_webservices/add_buyer_request.php:35
Stack trace:
0 /var/sites/p/pk.house/public_html/app_webservices/add_buyer_request.php(35): PDOStatement->execute()
1 {main}
thrown in /var/sites/p/pk.house/public_html/app_webservices/add_buyer_request.php on line 35
. I don't no how to solve it. i have searched a lot but all the results shows some PHP code.I have checked my service it is running fine, I don't know where the actual issue is coming can anyone guide me please how to handle this?

Amazon MWS Products API returns 401 error "Access denied"

I'm hopelessly stuck on trying to call Amazon MWS Products API. Particularly I'm trying to request this function
It requires building a pretty complicated request with a signature:
POST /Products/2011-10-01 HTTP/1.1
Content-Type: x-www-form-urlencoded
Host: mws.amazonservices.com
User-Agent: <Your User Agent Header>
AWSAccessKeyId=AKIAEXAMPLEFWR4TJ7ZQ
&Action=ListMatchingProducts
&MWSAuthToken=amzn.mws.4ea38b7b-f563-7709-4bae-87aeaEXAMPLE
&MarketplaceId=ATVPDKIKX0DER
&Query=0439708184
&SellerId=A1IMEXAMPLEWRC
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2012-12-12T22%3A23%3A50Z
&Version=2011-10-01
&Signature=V%2BEXAMPLERT%2Baj%2Fxwqo7y3PIifMFHeqFlNYW0EXAMPLEA%3D
I build this query with the help of this little library:
So my final url string looks like this:
https://mws.amazonservices.com/Products/2011-10-01?AWSAccessKeyId=<MY_ACCESS_KEY>&Action=ListMatchingProducts&MarketplaceId=A1PA6795UKMFR9&Query=0439708184&SellerId=<SELLER_ID>&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-19T16%3A50%3A13Z&Version=2011-10-01&Signature=mZt3OhM14gwLdsQ%2Bhxz5UFMzr7m2U36DvZ7RG3dcsTI%3D
And it seems that the url string is built correctly. I think so because if a parameter is missing or incorrect the API returns 400 error with explanation that this parameter is invalid. The same applies for the signature. If signature is incorrect the API returns error which clearly states that the signature is invalid. So, again, I think that the url must be ok. However the API returns 401 error and a html page which looks like this:
<?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<Error>
<Type>Sender</Type>
<Code>AccessDenied</Code>
<Message>Access denied</Message>
</Error>
<RequestID>7b12e3c8-7b1a-4b6e-b7ba-15ec8c4e0968</RequestID>
</ErrorResponse>
Access denied. And I have no idea why. I've spent several hours already trying to figure out what's wrong. Can anyone help me?
The reason for the problem was that I was calling American url https://mws.amazonservices.com instead of European one https://mws-eu.amazonservices.com. It would be really nice if Amazon response gave more context about the error than simply Access denied

ZF2 - Apigility not creating new api

I have Apigility running successfully on an app and have decided to use it for a new one. The problem I am stumped with is that it refuses to create a new api and appears to "hang" on the "create new api" screen.
Here is a screenshot of where it hangs: http://screencast.com/t/7CI3TN38Fm
Any advise on how to bug test this or has anyone experienced similar issues?
EDIT
When checking the console I note the following errors:
http://screencast.com/t/gIbZEWMwo
http://cloud.examplesite.dev/apigility/api/fs-permissions Failed to load resource: the server responded with a status of 403 (Forbidden)
vendor-angular.js:2 TypeError: Cannot read property 'fs_perms' of undefined
at http://cloud.examplesite.dev/zf-apigility-admin/js/app.js:1:5838
at j (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:16336)
at http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:17013
at k.$eval (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:21222)
at k.$digest (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:19926)
at k.$apply (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:21541)
at f (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:2732)
at r (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:4556)
at XMLHttpRequest.w.onreadystatechange (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:5095)vendor-angular.js:2 (anonymous function)
http://cloud.examplesite.dev/apigility/api/cache-enabled Failed to load resource: the server responded with a status of 403 (Forbidden)
3http://cloud.examplesite.dev/apigility/api/module Failed to load resource: the server responded with a status of 403 (Forbidden)
http://cloud.examplesite.dev/apigility/ui#/api Failed to load resource: net::ERR_CACHE_MISS
vendor-angular.js:2 GET http://cloud.examplesite.dev/apigility/api/dashboard 403 (Forbidden)
vendor-angular.js:2 GET http://cloud.examplesite.dev/apigility/api/dashboard 403 (Forbidden)
EDIT
After further investigation it would appear ZfcRbac is the cause of the problem... to create the Api it needs to be commented out.
Not sure of the best method to work around this... will investigate and post the answer once I know.
What I did to resolve this was to create an autoload file: mydev.local.php and to include the following in it:
<?php
return [
'zfc_rbac' => [
'protection_policy' => \ZfcRbac\Guard\GuardInterface::POLICY_ALLOW
]
Problem solved. thanks!
];
This means that any route that is not in my guards is not protected... of course when going to live mode, the local override file is not included...
If you update Apigility to the dev-master this issue will go away.
In your composer.json use this
"require-dev":{
"zfcampus/zf-apigility-admin": "dev-master"
}
and please disable opcache in php.ini also.

AccessTokenAuthorizationCodeRequestC "error":"invalid_request"

At the second call to Client.ProcessUserAuthorization(); after I get the code from the oauth server, I get an exception: Error occurred while sending a direct message or getting the response.
Here is the last part from the log file taken with log4net, the full log is recorded in this gist: https://gist.github.com/tonyeung/5513769
2013-05-03 15:14:41,292 (GMT-5) [10] DEBUG DotNetOpenAuth.Messaging.Channel - Sending AccessTokenAuthorizationCodeRequestC request.
2013-05-03 15:14:41,393 (GMT-5) [10] DEBUG DotNetOpenAuth.Http - HTTP POST http://localhost:38828/OAuth/Token
2013-05-03 15:14:41,450 (GMT-5) [10] ERROR DotNetOpenAuth.Http - http://localhost:38828/OAuth/Token returned 400 BadRequest: Bad Request
2013-05-03 15:14:41,450 (GMT-5) [10] DEBUG DotNetOpenAuth.Http - WebException from http://localhost:38828/OAuth/Token:
{"error":"invalid_request"}
I've uploaded the solution to https://github.com/tonyeung/dotnetopenauth
The entry point is in the about action on the home controller of the Client project.
The solution is in VS2012, the latest nuget dnoa package. Nuget restore is on.
Please note that I'm implementing pieces as I need them in order to understand how the library works. I'm sure that this error is due to a missing implementation somewhere, but I'm not sure what it is?
So it looks like I was missing implementations for IsAuthorizationValid and CreateAccessToken in the Authorization Server. Please check the github repository for the stubs i put in that makes the error go away.
EDIT:
There was also a database validation error that I didn't trap. So basically any error on the server side will cause this message it looks like.
EDIT2:
There was also an issue where if the url of the page contains any non url encoded values it will throw an invalid request. In my case, my login page had a querystring parameter of returnUrl, and I had set it to /Home, which it DID NOT like, had to be: %2FHome

Resources