Guide me implementing OAuth2 storage classes in thephpleague library - php

I am developing an oAuth 2.0 server using thephpleague library provided by Alex Bilbie. But, after the initializing the authorization server, when I declare the storage classes it throws an following error.
"Fatal error: Class 'Storage\SessionStorage' not found"
Please help me to resolve this. I read your post about this problem here:- Guide me implementing Oauth2 PHP server using thephpleague library
Please let me know how can I implement the storage classes. My current code:
require_once "/../vendor/autoload.php";
$server = new \League\OAuth2\Server\AuthorizationServer;
$server->setSessionStorage(new Storage\SessionStorage);
$server->setAccessTokenStorage(new Storage\AccessTokenStorage);
$server->setClientStorage(new Storage\ClientStorage);
$server->setScopeStorage(new Storage\ScopeStorage);
$server->setAuthCodeStorage(new Storage\AuthCodeStorage);
$authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant();
$server->addGrantType($authCodeGrant);

The library that you use requires implementing your own storage classes, see http://oauth2.thephpleague.com/implementing-storage-interfaces/. The class names that you use are from an example implementation https://github.com/thephpleague/oauth2-server/tree/master/examples/relational/Storage that uses Capsule as its storage backend. If you want to use Capsule as you backend, you'll need to download those example implementation classes and install https://github.com/illuminate/database.

Related

HybridAuth 3.0 - fresh install - getting: Class 'Hybridauth\Hybridauth\Provider\Facebook' not found

all. I've installed HybridAuth 3.0 and went step-by-step through the Install instructions using composer. I've used the example code and am able to get an initial HybridAuth class instantiated. However, when I continue on to the example with using the Facebook provider class, I'm getting the error, "Class 'Hybridauth\Hybridauth\Provider\Facebook' not found". I'm also using this in a Drupal 7 environment but have other classes like this that autoload just fine so I'm hopeful that little extra detail has no bearing on the problem.
I tried this both with the composer autoloader and the basic autoloader included with the library (as described in the Installation instructions). They both have the same error when attempting to find the Facebook class which is down in the /src/Provider directory. It does this for other classes as well.
That said, using the Hybridauth\Hybridauth "unified interface" works fine and is my current workaround as it allows one to work with multiple providers at one time. But I'm wondering what I'm doing wrong to not be able to load a specific provider as shown in their Introduction documentation.
This works:
// Include Composer's autoloader
include 'vendor/autoload.php';
// Import Hybridauth's namespace
use Hybridauth\Hybridauth;
// Now we may proceed and instantiate Hybridauth's classes
$instance = new Hybridauth([ /* ... */ ]);
This gives an error:
// Include Composer's autoloader
include 'vendor/autoload.php';
// Import Hybridauth's namespace
use Hybridauth\Hybridauth;
$adapter = new Hybridauth\Provider\Facebook([ /* ... */ ]);

Getting started with Google Storage

I am having really difficult time trying to connect Google Storage. All I need is to be able to upload PDF file to a bucket that I've created on Google Storage Console. The documentation seems to be all over the place and lacking simple examples of PHP code. So here's what I've done so far:
Installed cloud storage
$ composer require google/cloud-storage
Added billing as per Google's requirement. Enabled Cloud Storage API. Created project and added a bucket.
Attempted to use the following example:
require '../vendor/autoload.php';
define("PROJECT_ID", "my-project");
define("BUCKET_NAME", "my-bucket");
$client = new Google_Client();
$client->setApplicationName("API_Cloud_Storage");
$client->useApplicationDefaultCredentials();
$client->setScopes(["https://www.googleapis.com/auth/cloud-platform"]);
$service = new Google_Service_Storage($client);
$request = $service->buckets->listBuckets(PROJECT_ID);
foreach ($request["items"] as $bucket)
printf("%s\n", $bucket->getName());
Keep on getting error on
Fatal error: Uncaught Error: Class 'Google_Client' not found in /home/domain/public_html/test.php:11 ...
I know the vendor/autoload.php file is loading because I have no issues with AWS in a different script.
I didn't even pass the first line. What am I missing?
You have the documentation page for Cloud Storage Client Libraries with a PHP sample and detailed instructions. There's also a link to the GitHub repo for that quickstart, in addition to the one shared by ceejayoz in the comments.

Class not found in Google Cloud app

I am getting the following error:
Fatal error: Class 'Google\Cloud\Datastore\DatastoreClient' not found in /base/data/home/apps/e~brookes-room-usage/1.3998538263957262‌​38/record-usage.php on line 84
so presumably I have failed to point my app correctly to that class.
I have enabled the Datastore API on the cloud console.
I have tried to find documentation relating to how to set up a PHP connection to the Datastore API.
I tried to create a settings.yml file using the instructions here but I didn't know what my client ID or my client secret were.
# Google credentials and configuration
google_client_id: YOUR_CLIENT_ID
google_client_secret: YOUR_CLIENT_SECRET
google_project_id: YOUR_PROJECT_ID
# options are "cloudsql", "mongodb", or "datastore"
bookshelf_backend: datastore
(source on Github)
What do I need to get my PHP app on Google Cloud to recognise Google\Cloud\Datastore\DatastoreClient and connect to the Datastore API so that I can retrieve and post data?
I think you forgot to include google/cloud-datastore library. Install via composer as below.
$ composer require google/cloud-datastore
and you can use as below.
<?php
require 'vendor/autoload.php';
use Google\Cloud\Datastore\DatastoreClient;
$datastore = new DatastoreClient([
'projectId' => 'my_project'
]);
// Create an entity
$bob = $datastore->entity('Person');
$bob['firstName'] = 'Bob';
$bob['email'] = 'bob#example.com';
$datastore->insert($bob);
// Update the entity
$bob['email'] = 'bobV2#example.com';
$datastore->update($bob);
// If you know the ID of the entity, you can look it up
$key = $datastore->key('Person', '12345328897844');
$entity = $datastore->lookup($key);
More details: https://github.com/GoogleCloudPlatform/google-cloud-php#google-cloud-datastore-ga
I am already using this and working fine for me.
So it turns out that you can only run PHP with Datastore on a Google Cloud app on your local device, not on Google Appengine, unless you use a third-party library.
Which is why I am now writing my app in Python instead.
(Update: this may no longer be the case. This answer was written in 2017.)

How does PHP connection to firebase work?

If you have the time to read the firebase-php documentation, you can see there how to use the helper library to "connect" to firebase. But unfortunately, I think that the connection could only be established by phpunit, in other words, output can only be seen in the terminal. Since when you run the php pages in your browser, it will return fatal errors. Does anyone know how to use the helper library to connect to the firebase data without using phpunit? Thank you in advance.
Using the lib is very easy, when you just look at the source code of the tests.
There are two kinds of tests:
a real functionality test, which uses cURL requests to the server and therefore is slow during testing with PHPUnit
a mocked functionality test (stub), which simulates the connection to and the response from the server, which is faster during testing
Now, in order to use firebase-php, you would simply do the same things as in the real functionality test. Include the lib, prepare the connection object with login credentials and then call the method you want. The interface describes, which methods you can expect in the firebaseLib class -
or just look at the lib source itself.
This piece of code should get you started:
require '/path/to/libs/firebase-php/firebaseLib.php';
$url = '...';
$token = '...';
$firebase = new Firebase($url, $token);
$firebase->get('something/from/somewhere');
If you fetch the library via composer, you might declare an autoloading classmap, too. The author hasn't done this, yet.
{
"autoload": {
"classmap": ["vendor/ktamas77/firebase-php/firebaseLib.php"]
}
}
Then simply require Composer's Autoloader with require "vendor/autoload.php"; and new Firebase to autoload the class.
How to get the auth token
open your firebase console
go to project settings
go to the database
then copy the secret key

ez components and AWS PHP SDK makes ez components freak out

I try to work with ez Components and AWS PHP SDK at the same time.
I have a file called resize.php which is just handling resizing images using the ez Components ImageTransition tools.
I queue the image for resize in Amazon AWS SQS. If I load the AWS PHP SDK and ez Components in the same file, PHP always complains about not finding the ez Components classes.
Code looks something like this:
amazonSQS.php:
require 'modules/resize.php';
require 'modules/aws/sdk.class.php';
$sqs = new AmazonSQS();
$response = $sqs->send_message($queue_url, $message);
resize.php:
function resize_image($filename) {
$settings = new ezcImageConverterSettings(
array(
//new ezcImageHandlerSettings( 'GD', 'ezcImageGdHandler' ),
new ezcImageHandlerSettings( 'ImageMagick', 'ezcImageImagemagickHandler' ),
)
);
Error message:
Fatal error: Class 'ezcImageConverterSettings' not found in /home/www.com/public_html/modules/resize.php on line 10
If I call resize.php from another PHP file which has AWS not included, it works fine.
I load ezComponents like this:
require 'ezc/Base/ezc_bootstrap.php';
It is installed as a PEAR package.
Any idea someone?
The PHP classes of Apache Zeta / eZ Components can be conveniently used from within your PHP script. You don't have to use any require or include statements for any of the Apache Zeta Components classes that you use, this is because of the integrated autoload mechanism which can locate the classes for you when you instantiate or use them otherwise.
There are three different ways of getting the autoload mechanism going:
Normal autoload, if you require a custom autoload function
Bootstrap file, if you only use Apache Zeta autoloading
SPL autoload, if you need to register several autoload functions
These 3 ways are fully documented here

Categories