dev-master
9999999-dev
The Requires
by Harry Guo
0.1
0.1.0.0
The Requires
by Harry Guo
This package adds authenticate against Office 365 to a Laravel application., (*1)
The package is largely based on program logic from microsoftgraph/php-connect-sample
, but aimed to easier integration with Laravel 5, and utilized more Laravel native things., (*2)
(NOTE: packagist not updated yet, the following may not work), (*3)
First, run composer require singingfox/o365auth
under Laraval application root directory., (*4)
Add the following to composer.json
, (*5)
Singingfox\\O365Auth\\": "vendor/singingfox/o365auth/src
, (*6)
Add the following to config/app.php
, (*7)
Singingfox\O365Auth\O365AuthServiceProvider::class,
, (*8)
Run, (*9)
composer dump-autoload
, (*10)
Alternatively, add then following to composer.json
then run composer update
, (*11)
"required": [ ... "singingfox/o365auth": "*" ],
When installing this package, the following packages and their dependencies are going to be pulled in as well., (*12)
"league/oauth2-client": "^2.3.*", "microsoft/microsoft-graph": "^1.3.*"
Add the following to .env file, (*13)
O365_DOMAIN=ALLOWED-EMAIL-DOMAIN-NAME O365_CLIENT_ID=YOUR-APPLICATION-ID-OR-CLIENT-ID-IN-CREATED-MICROSOFT-APPLICATION O365_CLIENT_SECRET=YOUR-CLIENT-SECRETE-OR-CLIENT-PASSWORD-IN-CREATED-MICROSOFT-APPLICATION # This needs to be the full URL (https) O365_REDIRECT_URL=YOUR-REDIRECT-URL-IN-CREATED-MICROSOFT-APPLICATION
If not specified, a successful authentication will attempt to redirect application to the URL immediately prior to the authentication, or fall back to web root "/"., (*14)
Add a new view resources/views/errors/500.blade.php
. The content could be as simple as, (*15)
<h1>{{ $exception->getMessage() }}</h1>
This is optional, but if done, specific error message from this package, could be displayed. Otherwise, the following generic error message will be displayed for all errors:, (*16)
Whoops, looks like something went wrong.
, (*17)
At this time, the built-in program logic try to, (*18)
The following is a sample of what can be done after successful authentication:, (*19)
access_token
as stored in sessionGraph
object, and assign the token to itO365_AFTER_AUTH_URL
can be specified in .env
under Laraval application root, then a successful authentication process would be followed by some immediate actions, such as setting authenticated user locally, etc. The following sample route doesn't really do that. It only illustrates how to get a piece of user info -- email.Route::get("/o365-user/email", function () { if (session_status() == PHP_SESSION_NONE) session_start(); $graph = new \Microsoft\Graph\Graph(); $graph->setAccessToken($_SESSION['access_token']); $me = $graph->createRequest("get", "/me") ->setReturnType(\Microsoft\Graph\Model\User::class) ->execute(); return $me->getMail(); });
This authentication process can also be used to register new users that allows for access., (*20)