OAuth 2.0 and php slim - php

I am following this guide (http://www.lornajane.net/posts/2013/oauth-middleware-for-slim) to setup oAuth2 with php SLIM.
I dont't understand this part:
$auth = new \Service\Mysql\AuthService($this->mysql, $this->config);
$validated_user_id = $auth->verifyOAuth($authHeader);
$this->app->user_id = $validated_user_id;
Where can I take the class \Service\Mysql\AuthService and what is the variable config ?
Otherwise is there another guide with more details also without direct SLIM implementation ?
Thanks

That's the service class that will actually do the loading and storing of user details.
Then you should put your own class.
This could be useful: https://github.com/alexbilbie/oauth2-example-resource-server

Related

How to use OVH Api with Laravel

I'm working on an application that sends SMS to the customers we got.
I'm currently looking the doc (https://docs.ovh.com/fr/sms/envoyer_des_sms_avec_lapi_ovh_en_php/) => it's in french.
They're using a PHP Wrapper, but I really don't know how I can integrate the API to my Laravel Project.
Does someone know how it's working ?
First of all, install the package
composer require ovh/php-ovh-sms
Then, on the controller, you can use the API easily as stated in the documentation.
use \Ovh\Sms\SmsApi;
// Informations about your application
// You may set them to 'NULL' if you are using
// a configuraton file
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumerKey = "your_consumer_key";
$endpoint = 'ovh-eu';
// Init SmsApi object
$Sms = new SmsApi( $applicationKey, $applicationSecret, $endpoint, $consumerKey );
// Get available SMS accounts
$accounts = $Sms->getAccounts();
dd($accounts);
There is a Laravel notification channel specifically for this provider, this will make the whole process much easier, it will allow you to use Laravel's built in notifications functionality without having to write provider specific code.
http://laravel-notification-channels.com/ovh-sms/

HelloSign bundle not working in Symfony

I have installed the Hello Sign PHP SDK in a Symfony project and it does not work and requesting to add a "use" statement which I added and still not working. (https://github.com/HelloFax/hellosign-php-sdk)
This is the error I get when I used SDK
Attempted to load class "Client" from namespace
"AppBundle\Controller\HelloSign". Did you forget a "use" statement for
e.g. "HelloSign\Client", "Symfony\Component\BrowserKit\Client",
"Symfony\Component\HttpKernel\Client",
"Symfony\Bundle\FrameworkBundle\Client" or "GuzzleHttp\Client"
Then I used a PHP wrapper for Hello Sign called "bukashk0zzz/hellosign-bundle". And that too is requesting to add a "use" statement which I added but not working. (https://github.com/Bukashk0zzz/HelloSignBundle)
Here's that error.
Attempted to load class "TemplateSignatureRequest" from namespace
"AppBundle\Controller\HelloSign". Did you forget a "use" statement for
"HelloSign\TemplateSignatureRequest"?
My code is
require_once('../vendor/hellosign/hellosign-php-sdk/vendor/autoload.php');
$client = new HelloSign\Client('apikey');
$account = $client->getAccount();
How can I fix this?
Did you try:
$client = new \HelloSign\Client('apikey');
$account = $client->getAccount();
if hellosign-php-sdk is installed with composer
Hellosign has API developer support at apisupport#hellosign.com if you have any other questions. Please feel free to reach out there as well. Sounds like you got your answer though.

Using angelleye paypal with simplemvc framework

I have used composer to download the Angell EYE PayPal library into my vendor directory. Now I'm trying to call the class within a controller.
I've tried various methods:
Use \angelleye\PayPal;
at the top of page. I've tried using the require() method.
Within the controller I have used
$paypal = PayPal::PayPal($payment);
And a few other ways, but I just get the error Class not found at line 179 and I'm not sure why.
You just need to load a config file (depending on your framework) and the autoloader.
require_once('includes/config.php');
require_once('vendor/angelleye/paypal-php-library/autoload.php');
Of course, adjust the paths to suit where you have those saved, but the autoloader is what makes the classes available to you.
If you want more direct help you can submit a ticket here.
Thanks for response.
I actually managed to get it working on the framework.
I did nt have to load anything or require the class as the composer autoload must do it for me in the framework.
I simply added :
$PayPal = new \angelleye\PayPal\PayPal($PayPalConfig);
and it started to work.
Im guessing if i want to use the PayFlow i would call using:
$PayPal = new \angelleye\PayPal\PayFlow($PayPalConfig);
I will definately post back if the rest of the proccess fails to work.

Read HTTP headers in Controller (Zend Framework)

Long story short:
I'm building a skeleton application for Zend Framework and I got to the part where I need to setup the api module. I'm using Zend_Rest_Controller for this job. All is ok up to this part where I need to get the HTTP headers in a controller to verify the api key.
On various tutorials I've read on the web the thing is done via a front controller plugin, but I need it to be more "plug and play" than that (checking each time the config of the application, deciding which module is the api and so on).
I tried what seemed most obvious $this->getRequest()->getHeaders() but doesn't seem to work, at least not for the HTTP headers where I'll be seding my api key. Neither the reponse object.
Can anyone help me with this one?
I found a way of doing this after all :)
On the preDispatch() method in your controller you can do the following:
public function preDispatch()
{
$request = new Zend_Controller_Request_Http();
$key = $request->getHeader('x-apikey');
}
It seems that Zend_Controller_Request_Http object gives you acces to the headers. More info on the Zend_Controller_Request_Http you can find here
As Bogdan said, you can find that information in the Zend_Controller_Request_HTTP class. It can be found in the controller itself by doing :
$this -> getFrontController() -> getRequest() -> getHeader('Content-Type');
Unfortunatly, you can't access all headers at once but what ZF does is just use apache_request_headers() function if available on the server to get them.

Working example Zend_Rest_Controller with Zend_Rest_Client?

I am trying to write a short Rest Service with Zend Framework. But the documentation is not the best at this Part.
I have an ApiController extended Zend_Rest_Controller with all needed abstract methods. My goal is to get Post data and return something.
My client looks like this:
public function indexAction()
{
$url = 'http://localhost/url/public/api';
$client = new Zend_Rest_Client();
$client->setUri($url);
$client->url = 'http://www.google.de';
$result = $client->post();
}
but the provided "$client->url" is not inside the post array on Server side. Does I have to use Zend Rest Server inside the postAction on my ApiController?
If someone has an example how to send and to get the data with Zend Rest, that would be great.
Maybe this tutorial Create RESTful Applications Using The Zend Framework can help.
Have you tried setting it to access 127.0.0.1 rather than localhost? I know this can cause issues sometimes.

Categories