Skip to content

Commit 05782bd

Browse files
committed
feat: add laravel-pure code sample
1 parent 5e7faa1 commit 05782bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+8910
-2
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ Here are some links you can use :
3232
## Examples provided in this repository
3333

3434
### ReactJS with 3rd-party libraries
35-
Example can be found [here](https://github.com/ivaoaero/OAuth-samples/tree/main/reactjs-with-lib)
35+
Example can be found [here (reactjs-with-lib)](https://github.com/ivaoaero/OAuth-samples/tree/main/reactjs-with-lib)
3636

3737
This example how to authenticate users on frontend-only applications without the need of a backend.
3838

3939
_PS: This is how IVAO 2.0 websites (Webeye, FPL, Tracker) are working_
4040

4141
### PHP without any libraries
42-
Example can be found [here](https://github.com/ivaoaero/OAuth-samples/tree/main/php-pure)
42+
Example can be found [here (php-pure)](https://github.com/ivaoaero/OAuth-samples/tree/main/php-pure)
4343

4444
This example shows both how to authenticate a user visiting your website as well as how to authenticate your backend application without any user interaction.
4545

46+
### Laravel without Socialite
47+
Example can be found [here (laravel-pure)](https://github.com/ivaoaero/OAuth-samples/tree/main/laravel-pure)
48+
49+
This example shows both how to authenticate a user visiting your website and how to store all his details in your database.
50+
4651
## How do I implement OAuth with IVAO APIs?
4752

4853
### Needed information

laravel-pure/.env

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
APP_NAME=IVAO-OAuth
2+
APP_ENV=local
3+
APP_KEY=base64:cf69jPbvFuhrg3NKy+8HO9xm0MoKiZzvzneaJagEqc4=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
LOG_CHANNEL=stack
8+
LOG_DEPRECATIONS_CHANNEL=null
9+
LOG_LEVEL=debug
10+
11+
DB_CONNECTION=sqlite
12+
13+
BROADCAST_DRIVER=log
14+
CACHE_DRIVER=file
15+
FILESYSTEM_DRIVER=local
16+
QUEUE_CONNECTION=sync
17+
SESSION_DRIVER=file
18+
SESSION_LIFETIME=120
19+
20+
IVAO_CLIENT_ID=57b2d957-38ff-4d1e-8d8f-7e5aa8d0d5fe
21+
IVAO_CLIENT_SECRET=VUFqej5bLDOBngOtUcQCF97U1o7MQDbu

laravel-pure/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

laravel-pure/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Laravel Pure Code Sample
2+
## Running the example locally
3+
### 1. Install the dependencies
4+
Run `composer install` in this folder to download all Laravel dependencies.
5+
6+
### 2. Initiate the database
7+
By default, we have configured a local sqlite database inside the `database` folder.
8+
9+
If you want to connect to another database, please edit the `.env` file and refer to the laravel documention for other configuration options.
10+
11+
Initiate the database structure with this command : `php artisan migrate`
12+
13+
### 3. Start the local server
14+
Run `php artisan serve` to start a local server on [localhost:8000](http://localhost:8000).
15+
16+
### 4. Enjoy
17+
The default configuration will log you in and display all your informations
18+
19+
## How does it work
20+
21+
### 1. Register the routes
22+
We need to tell Laravel about our 2 new routes, the one that will redirect the user to SSO and the one the user will be redirected to after a successful login.
23+
24+
They are located in the `routes/web.php` file
25+
26+
### 2. Add a controller
27+
28+
Now that the routes exist, we need to tell laravel what do to when a user is accessing them.
29+
30+
We have copied the example from `php-pure` into `app/Http/Controllers/IvaoController.php`
31+
32+
### 3. Specify the variables
33+
Inside `.env` we have specified the `IVAO_CLIENT_ID` and `IVAO_CLIENT_SECRET` values that will authenticate our application.
34+
35+
## Known bugs
36+
37+
### 127.0.0.1 Invalid Redirect URI
38+
If you open the URL on `http://127.0.0.1:8000` it won't work because the redirect url doesn't allow an IP. You have to open it from [http://localhost:8000](http://localhost:8000) to make it work.
39+
40+
## Contribution
41+
42+
Thank you for your contribution to this code sample and testing :
43+
- [Edgardo Alvarez (602243) CO-WM](https://github.com/edgardoalvarez100)
44+
- [DZ-WM (670202)](https://github.com/belmeg)

laravel-pure/app/Console/Kernel.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* Define the application's command schedule.
12+
*
13+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
14+
* @return void
15+
*/
16+
protected function schedule(Schedule $schedule)
17+
{
18+
// $schedule->command('inspire')->hourly();
19+
}
20+
21+
/**
22+
* Register the commands for the application.
23+
*
24+
* @return void
25+
*/
26+
protected function commands()
27+
{
28+
$this->load(__DIR__.'/Commands');
29+
30+
require base_path('routes/console.php');
31+
}
32+
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
6+
use Throwable;
7+
8+
class Handler extends ExceptionHandler
9+
{
10+
/**
11+
* A list of the exception types that are not reported.
12+
*
13+
* @var array<int, class-string<Throwable>>
14+
*/
15+
protected $dontReport = [
16+
//
17+
];
18+
19+
/**
20+
* A list of the inputs that are never flashed for validation exceptions.
21+
*
22+
* @var array<int, string>
23+
*/
24+
protected $dontFlash = [
25+
'current_password',
26+
'password',
27+
'password_confirmation',
28+
];
29+
30+
/**
31+
* Register the exception handling callbacks for the application.
32+
*
33+
* @return void
34+
*/
35+
public function register()
36+
{
37+
$this->reportable(function (Throwable $e) {
38+
//
39+
});
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6+
use Illuminate\Foundation\Bus\DispatchesJobs;
7+
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Routing\Controller as BaseController;
9+
10+
class Controller extends BaseController
11+
{
12+
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class HomeController extends Controller
8+
{
9+
public function index() {
10+
11+
return view('home', []);
12+
}
13+
}

0 commit comments

Comments
 (0)