I'm trying to use the Paypal Permissions SDK: https://github.com/paypal/permissions-sdk-php
And in particular their code snippet:
// Pass in a dynamically created API credential object
$cred = new PPCertificateCredential("username", "password", "path-to-pem-file");
$cred->setThirdPartyAuthorization(new PPTokenAuthorization("accessToken", "tokenSecret"));
$response = $permissions->RequestPermissions($request, $cred);
However, I do not have an "accessToken" or "tokenSecret" and if I understand correctly, you need to use the Permissions API to retrieve those in the first place. Infinite loop???
Am I misunderstanding something?
or is there another way to call the API using dynamically set credentials?
or is their documentation incorrect?
I haven't made the permissions work 100% yet, but I have obtained the token and token_secret.
In the Permissions SDK, cd samples and do composer update. Than update your API credentials and run the samples to get the token and token_secret of third party merchant - no PEM file required there (the samples work, all code is there).
The certificate is needed later (I think, working on this now), when you need to use previously obtained permissions to create a single use authorisation in order to create a token.
BTW, I am really disappointed with PayPal documentation regarding these features. I've been having trouble setting this up for a couple of days already. And The Permissions SDK GitHub page contains bugs in samples..!
Related
I have read this SO:How upload to MY Google Drive account, not the users
and I found its possible, though I therefore decide not to use a service account and use my own google account's Drive space instead.
However, I found difficulties in understanding the exact steps to achieve this. I read the OAuth2.0, Drive API, and cros-upload sample from Google.
But I do not really know how to proceed to make an upload to MY drive instead of when the user logged in Google+, then it become uploading to their own drive.
I wonder if anyone know exact knowledge I should be obtaining and steps and implementation required to achieve this uploading file from any registered users to MY google Drive with Drive API. I am using PHP as bakend and AngularJS as front-end. So, if that made possible easier with either method or existing lib (which I can't find except Drive's doc on this), will be ideal, but a steps to build one will be wonderful as well.
More detail, in the post I showed on top, the 2nd answer's phrase of "do a one-off auth to get a refresh token, which you will store. You can then use this any time to generate the access token needed to invoke the actual Drive API. You can generate the refresh token using the Oauth Playground, so no need to write any code." get me really not clear exactly the steps that involved and api that I actually should be using to achieve it.
Thank You
To send files to Google Drive, you need an access token to use the Drive user's storage, this token expires in a few moments from creation.
To create an access token, you need a refresh token, which does not expire. This is the key to doing this.
Here is a simple file upload example using the PHP api:
https://github.com/numsu/google-drive-sdk-api-php-insert-file-parent-example
Set it up by following the readme.
To edit the code to send the files always to a single Drive from anywhere, you need to get the destination Drive's refresh token, in this case yours. You will get it by logging in to the service and granting privileges on the Google Consent screen. It will be saved in $_SESSION["credentials"]. Do a var_dump() on that and save the refresh token somewhere, in a file or a database where you can access it.
You can now remove anything that points to the user logging in with oAuth, this doesn't need that.
Next you need to get yourself an access token with the refresh token you have. This you can do with the google API function $client->refreshToken($refreshToken);
Next you just need to generate a new drive service class using the $client variable: $service = new Google_Service_Drive($client);
After that, to upload the file:
$file = new Google_Service_Drive_DriveFile();
$file->setTitle($title);
$file->setMimeType($mimeType);
$data = file_get_contents($filename);
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => $mimeType,
));
Good luck!
I've followed a couple of different guides on this, but I can't seem to get my head around the way in which Uservoice 3-legged OAuth works.
The guides I've followed:
https://github.com/uservoice/uservoice-php#verifying-a-uservoice-user
https://developer.uservoice.com/docs/api/php-sdk/ (See: Associating your users with their UserVoice profiles)
I can successfully redirect the user to the uservoice auth screen, which asks for permission, and on clicking "Allow Access" they are taken back to the correct callback URL, however this is where their documentation fails...
Following exactly what they suggest, I do the following:
$access_token = $client->login_with_verifier($_GET['oauth_verifier']);
However this fails of course unless I have a $client, so, I make that as I did on the last request... but then it complains that UserVoice\Client::$request_token isn't set on line 130 (see here).
And the only way to set that variable, is to recreate the auth link... which generates a whole new OAuth process, so it inevitably fails authentication.
I'm wondering if anybody knows how I can work around this?
Was able to put this down to a small bug in the package, and have submitted a pull request to fix this
https://github.com/uservoice/uservoice-php/pull/4
The latest specification for connecting to the BigCommerce API recommends using OAuth since the simple auth method will soon be deprecated.
I have been using the BigCommerce API within some PHP scripts that access the Store API for my store. These scripts do relatively simple things like update product names, update product prices, etc.
I'm confused as to how I transfer these scripts over to use the new OAuth system. Everything I am reading makes it seem like OAuth is based around developing an actual app that a user installs and authorizes to access their store. However, this is clearly not my use case, and has left me very confused.
A simple example would be a script to retrieve products from my store. I would simply run this code in a PHP file:
Bigcommerce::configure(array(
'store_url' => 'https://www.my-store.com',
'username' => 'my_username',
'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);
Bigcommmerce::getProducts();
How can I achieve this same thing using OAuth? Is it even possible?
I would probably create a quick "app" to get a Client ID, Client Secret & Token. Then use those credentials for authentication externally. So you would install an "authentication app" but execute your code from outside of BC.
Note that this is not that different from how an installed app that is iframed in works.
PS, I have not actually tried this but in theory it should work.
I realize this may be a bit off-topic as I see you're using PHP and my experience has been with C# but thought I'd add my comments on the issue so maybe someone will benefit:
I've been working on this same type of oauth token issue and the docs haven't been much help, but once I got going I finally managed to get the app setup by creating my SSL callback page locally on my server. Once I specified that URL in the app settings I was all set. The caveat being I had to do perform the 'install' from the server itself since it wasn't a public URL while logged into BC as the store owner. I was then able to get the temporary token from the querystring and post back to https://login.bigcommerce.com/oauth2/token and obtain the permanent token from the response stream.
One thing their API rep did mention that may be of interest is that eventually you're going to need to refresh the 'permanent' token every 60-90 days or so once they get their end in order.
#developerscott is perfectly correct, but just to add on to your question on how to achieve the same thing as your code using oAuth with the BC PHP API SDK
Once you have an oAuth access token and the client_id of an app you created, you can use them to utilize oAuth in your PHP scripts. You just need to provide those credentials into the Bigcommerce::configure() method like so, instead of the username and api_key properties:
Bigcommerce::configure(array(
'store_hash' => 'abcdef',
'client_id' => '123xxxx321',
'auth_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);
Bigcommmerce::getProducts();
I have been trying to implement the new scope features that were recently added to the LinkedIn API. I am currently using the "simple-linkedinphp" library for as my LinkedIn oauth lib (http://code.google.com/p/simple-linkedinphp/ ).
Following the directions on the LinkedIn docs, I added the "scope" param to my request token URL as such:
const _URL_REQUEST = 'https://api.linkedin.com/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress';
However, this had little effect. I still get the same o-auth dialogue as before without any additional permissions for the e-mail address. Anyone get this working correctly in PHP yet? Any help here would be appreciated.
You need to create new Application API keys and use those to see the updated authentication screens.
I am trying to get a list of all Google Apps users of a domain onto a public PHP website (without visitors of the site needing to login or do anything). I have a basic understanding of what needs to happen but can't quite piece it all together. It can't be as hard as it seems to me... could it?
Authentication and Authorization:
I'm pretty sure it needs to use OAuth 2.0 ... but am unsure whether it needs 2 legged or 3 legged. I got another section of the site working with ClientLogin but that won't pull in Google Apps profiles, only user's first and last names (I need the other profile fields). I have set up the API access within the account and have that side of things all set (I believe).
I have found this page, which shows how to construct a URL request to get all Profiles (in every language except PHP of course) but don't understand how to implement this.
http://code.google.com/googleapps/domain/profiles/developers_guide.html
I also tried this example but it just gives me a 401 after I enter the credentials. http://gdatatips.blogspot.com/2008/11/2-legged-oauth-in-php.html
I don't know which frameworks or includes are needed to accomplish this either. I have tried zend, OAuth.php and a whole bunch of other bootstraps... but keep getting lost as to what each is doing.
If someone could help me by outlining:
Which files/framework I need to upload and include as a bootstrap
What variables within those files I need to update with the Google credentials
How I integrate the Google Profiles "Retrieve all Profiles" request with PHP
An ELI5 (explain it like i'm 5) overview would be very much appreciated... I'm sorry for my apparent incompetence, but I have been reading articles for nearly a week and have not gotten anywhere.
Thank you in advance for any help provided.
Good question.
You'll need to implement the Google OAuth 2.0 process as it's described here (experimental?), because someone (you) will need to give your app the initial permissions to access Google Apps API. Steps are:
Register your domain with google (don't remember the link)
Redirect/send browser to an authentication url: https://accounts.google.com/o/oauth2/auth, with the appropriate request params (see the first link). You'll need access_type=offline, your scope would be https://apps-apis.google.com/a/feeds/user/
Get a code back, then exchange for a refresh_token, an access_token, and a value specifying when the access_token will expire. Store these in a database
Whenever you need to make an API call, check if your access_token has expired or not, and refresh when necessary, which is what the refresh_token is for. The refresh_token is valid as long as you don't revoke the access you gave to the app.
OAuth Playground helps a lot. Good luck.