PHP code example of grantholle / laravel-powerschool-auth
1. Go to this page and download the library: Download grantholle/laravel-powerschool-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
grantholle / laravel-powerschool-auth example snippets
return [
// These are nv('POWERSCHOOL_ADDRESS'),
'client_id' => env('POWERSCHOOL_CLIENT_ID'),
'client_secret' => env('POWERSCHOOL_CLIENT_SECRET'),
// User type configuration
'staff' => [
// Setting to false will prevent this user type from authenticating
'allowed' => true,
// This is the model to use for a given type
// Theoretically you could have different models
// for the different user types
'model' => \App\User::class,
// These attributes will be synced to your model
// PS attribute => your app attribute
// Put either OpenID implementation in this
// The app will parse whether the key exists in
// the response.
'attributes' => [
// These attributes are from OpenID 2.0
'firstName' => 'first_name',
'lastName' => 'last_name',
// Shared with 2.0 and Connect
'email' => 'email',
// These are OpenID Connect attributes
'given_name' => 'first_name',
'family_name' => 'last_name',
],
// The guard used to authenticate your user
'guard' => 'web',
// These is the properties used to look up a user's record
// OpenID identifier so they can be identified
// You will need to have this column already added to
// the given model's migration/schema.
'identifying_attributes' => [
'openid_claimed_id' => 'openid_identity',
],
// The path to be redirected to once they are authenticated
'redirectTo' => '',
],
// 'guardian' => [ ...
// 'student' => [ ...
];
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use GrantHolle\PowerSchool\Auth\Traits\AuthenticatesUsingPowerSchoolWithOpenId;
class PowerSchoolOpenIdLoginController extends Controller
{
use AuthenticatesUsingPowerSchoolWithOpenId;
}
// These paths can be whatever you want; the key thing is that they path for `authenticate`
// matches what you've configured in your plugin.xml file for the `path` attribute
Route::get('/auth/powerschool/openid', [\App\Http\Controllers\Auth\PowerSchoolOpenIdLoginController::class, 'authenticate']);
Route::get('/auth/powerschool/openid/verify', [\App\Http\Controllers\Auth\PowerSchoolOpenIdLoginController::class, 'login'])
->name('openid.verify');
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use GrantHolle\PowerSchool\Auth\Traits\AuthenticatesUsingPowerSchoolWithOpenId;
class PowerSchoolOpenIdLoginController extends Controller
{
use AuthenticatesUsingPowerSchoolWithOpenId;
/**
* This will get the route to the `login` function after
* the authentication request has been sent to PowerSchool
*
* @return string
*/
protected function getVerifyRoute(): string
{
return url('/auth/powerschool/openid/verify');
}
/**
* This will get the route that should be used after successful authentication.
* The user type (staff/guardian/student) is sent as the parameter.
*
* @param string $userType
* @return string
*/
protected function getRedirectToRoute(string $userType): string
{
$config = config("powerschool-auth.{$userType}");
return isset($config['redirectTo']) && !empty($config['redirectTo'])
? $config['redirectTo']
: '/home';
}
/**
* If a user type has `'allowed' => false` in the config,
* this is the response to send for that user's attempt.
*
* @return \Illuminate\Http\Response
*/
protected function sendNotAllowedResponse()
{
return response('Forbidden', 403);
}
/**
* Gets the default attributes to be filled for the user
* that wouldn't be
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use GrantHolle\PowerSchool\Auth\Traits\AuthenticatesUsingPowerSchoolWithOidc;
class PowerSchoolOidcLoginController extends Controller
{
use AuthenticatesUsingPowerSchoolWithOidc;
}
// These paths can be whatever you want; the key thing is that they path for the `login` route action to
// match what you've configured in your plugin.xml under `oauth`'s `redirect-uri` attribute file for the `path` attribute
Route::get('/auth/powerschool/oidc', [\App\Http\Controllers\Auth\PowerSchoolOidcLoginController::class, 'authenticate']);
Route::get('/auth/powerschool/oidc/verify', [\App\Http\Controllers\Auth\PowerSchoolOidcLoginController::class, 'login']);
// <oauth
// base-url="https://example.com"
// redirect-uri="/auth/powerschool/oidc/verify" <-- Has to match the route for the `login` action
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use GrantHolle\PowerSchool\Auth\Traits\AuthenticatesUsingPowerSchoolWithOidc;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
class PowerSchoolOidcController extends Controller
{
use AuthenticatesUsingPowerSchoolWithOidc;
protected function getRedirectUrl()
{
return url('/auth/powerschool/oidc');
}
/**
* Whether to have an extended authenticated session
*
* @return bool
*/
protected function remember(): bool
{
return false;
}
/**
* The scope that this will request from PowerSchool.
* By default it requests all scopes for the user.
*
* @param array $configuration
* @return array
*/
protected function getScope(array $configuration): array
{
return $configuration['scopes_supported'];
}
/**
* If a user type has `'allowed' => false` in the config,
* this is the response to send for that user's attempt.
*
* @return \Illuminate\Http\Response
*/
protected function sendNotAllowedResponse()
{
return response('Forbidden', 403);
}
/**
* Gets the default attributes to be added for this user
*
* @param Request $request
* @param Collection $data
* @return array
*/
protected function getDefaultAttributes(Request $request, Collection $data): array
{
return [];
}
/**
* The user has been authenticated.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @param \Illuminate\Support\Collection $data
* @return mixed
*/
protected function authenticated(Request $request, $user, Collection $data)
{
//
}
}