GRAPH has no authentication method included, so you will need to install one with oauth2.
You can do that via composer require league/oauth2-client
GRAPH will use Guzzle HTTP client which is preinstalled, so you're good to go with this.
Unfortunately in my coding I encountered that http_errors are internally handled by middleware and there was no way round so my app was crashing without anything I could do to catch the exceptions.
I therefore built an own Guzzle client with http_errors disabled and gave that one over to GRAPH . This way I can look for errors, if there are none, I can continue.
See the following example of how to use our custom GUZZLE client.
Let's assume our project is Larvel based, so we'll go with that assumption. But it will work with any other PHP just as good.
In order to make everything work smooth you'll need some few PHP files created.
Inside our app we will need a controller for authentication.
In Laravel we would do that by
You might say, that I could use env('OAUTH_APP_ID') and put all my variables to my .env file. Yes' - you're right, but if I don't pay attention and forget to use
php artisan config:clear
My app won't work.
It's not really a big deal to have it here, so I put my vars inside of my PHP.
If you want so I could also access these vars from anywhere in my AuthController, as I need to authenticate anyway.
Let's now create our TokenStorage.
Add to your app folder a folder named TokenStore
Please take note that we are working with callbacks in order to get our access tokens, so we need to provide the corresponding function for this callback "localhost\mscallback" or however you want to name this endpoint, also replace localhost with your domain. We will do that later.
This is the content of our TokenCache.php:
You see that we point each route to a specific function inside of our AuthController.
You see that we point each route to a specific function inside of our AuthController.
To have a very rudimentary Login and Logout possibility for connection with GRAPH you can use the following HTML:
If you have questions feel free to ask me or leave me a comment.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.