Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.3, 8.4]
laravel: ["10.*"]
laravel: ["11.*"]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
carbon: ^2.63

steps:
Expand Down Expand Up @@ -53,7 +52,7 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: List Installed Dependencies
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,23 @@ configure the required options inside the `services` configuration file.
'client_secret' => env('GITLAB_CLIENT_SECRET'),
'redirect' => null, // set in the controller no need to specify
'instance_uri' => env('GITLAB_INSTANCE_URI', 'https://gitlab.com/')
// 'host' => env('GITLAB_INSTANCE_URI', 'https://gitlab.com/') // if using the default Socialite Gitlab driver
],
```

> [!TIP]
> We do require also Socialite Providers Gitlab driver. So you need to include the `Identity::events()` in your app provider. If you want to use the Gitlab driver included in Laravel Socialite you can omitt `Identity::events()`. Remember to use `host` instead of `instance_uri` to configure the url of your Gitlab instance.

If you are using one of the community maintained [Socialite Providers](https://socialiteproviders.com/)
remember to register their events in your `EventsServiceProvider`.
remember to register their events in your `AppServiceProvider`.

If you are not using those providers this step is optional.

`oneofftech/laravel-connect-identity` provides out-of-the-box support for the `gitlab`
and `dropbox` driver. If you are using those two you might add the following call to
your `EventsServiceProvider`.
your `AppServiceProvider`.

```php

public function boot()
{
parent::boot();
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
],
"require": {
"php": "^8.2",
"illuminate/auth": "^10.0",
"illuminate/console": "^10.0",
"illuminate/encryption": "^10.0",
"illuminate/support": "^10.0",
"illuminate/view": "^10.0",
"illuminate/auth": "^11.0",
"illuminate/console": "^11.0",
"illuminate/encryption": "^11.0",
"illuminate/support": "^11.0",
"illuminate/view": "^11.0",
"laravel/socialite": "^5.0",
"socialiteproviders/gitlab": "^4.0",
"socialiteproviders/dropbox": "^4.1"
Expand All @@ -33,7 +33,7 @@
"larastan/larastan": "^2.9",
"mockery/mockery": "^1.4.4",
"phpunit/phpunit": "^10.5",
"orchestra/testbench": "^8.22"
"orchestra/testbench": "^9.9"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 2 additions & 4 deletions src/Auth/RedirectsUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ trait RedirectsUsers
{
/**
* Get the post register / login redirect path.
*
* @return string
*/
public function redirectPath()
public function redirectPath(): string
{
if (method_exists($this, 'redirectTo')) {
return $this->redirectTo();
}

return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/';
}
}
2 changes: 1 addition & 1 deletion src/Console/Commands/ScaffoldAuthenticationControllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function identifyApplicationNamespace()
$this->comment("Using [$this->namespace] as application namespace.");
}

$this->modelNamespace = is_dir(app_path('Models')) ? $this->namespace.'\\Models' : $this->namespace;
$this->modelNamespace = is_dir(app_path('Models')) ? $this->namespace.'Models' : $this->namespace;
} catch (RuntimeException $ex) {
$this->warn("Unable to identity the application namespace, assuming [$this->namespace].");
}
Expand Down
40 changes: 25 additions & 15 deletions src/Facades/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class Identity extends Facade
*
* @var string
*/
public static $userModel = 'App\\User';
public static $userModel = 'App\\Models\\User';

/**
* The identity model that should be used.
*
* @var string
*/
public static $identityModel = 'App\\Identity';
public static $identityModel = 'App\\Models\\Identity';

/**
* Get the registered name of the component.
Expand All @@ -53,24 +53,34 @@ protected static function getFacadeAccessor()
*/
public static function routes()
{
/**
* @var \Illuminate\Routing\Router
*/
$router = static::$app->make('router');

$namespace = '\\'.rtrim(self::$appNamespace, '\\');

$router->match(['get', 'post'], 'login-via/{provider}', "$namespace\Http\Controllers\Identities\Auth\LoginController@redirect")
->name('oneofftech::login.provider');
$router->get('login-via/{provider}/callback', "$namespace\Http\Controllers\Identities\Auth\LoginController@login")
->name('oneofftech::login.callback');
$router
->middleware('web')
->group(function ($groupRouter) use ($namespace) {
$groupRouter->match(['get', 'post'], 'login-via/{provider}', "$namespace\Http\Controllers\Identities\Auth\LoginController@redirect")
->name('oneofftech::login.provider');
$groupRouter->get('login-via/{provider}/callback', "$namespace\Http\Controllers\Identities\Auth\LoginController@login")
->name('oneofftech::login.callback');

$groupRouter->match(['get', 'post'], 'register-via/{provider}', "$namespace\Http\Controllers\Identities\Auth\RegisterController@redirect")
->name('oneofftech::register.provider');
$groupRouter->get('register-via/{provider}/callback', "$namespace\Http\Controllers\Identities\Auth\RegisterController@register")
->name('oneofftech::register.callback');

$groupRouter->match(['get', 'post'], 'connect-via/{provider}', "$namespace\Http\Controllers\Identities\Auth\ConnectController@redirect")
->middleware('auth')
->name('oneofftech::connect.provider');
$groupRouter->get('connect-via/{provider}/callback', "$namespace\Http\Controllers\Identities\Auth\ConnectController@connect")
->middleware('auth')
->name('oneofftech::connect.callback');
});

$router->match(['get', 'post'], 'register-via/{provider}', "$namespace\Http\Controllers\Identities\Auth\RegisterController@redirect")
->name('oneofftech::register.provider');
$router->get('register-via/{provider}/callback', "$namespace\Http\Controllers\Identities\Auth\RegisterController@register")
->name('oneofftech::register.callback');

$router->match(['get', 'post'], 'connect-via/{provider}', "$namespace\Http\Controllers\Identities\Auth\ConnectController@redirect")
->name('oneofftech::connect.provider');
$router->get('connect-via/{provider}/callback', "$namespace\Http\Controllers\Identities\Auth\ConnectController@connect")
->name('oneofftech::connect.callback');
}

/**
Expand Down
14 changes: 2 additions & 12 deletions stubs/Identities/Auth/ConnectController.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace App\Http\Controllers\Identities\Auth;

use App\User;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Oneofftech\Identities\Auth\ConnectUserIdentity;

class ConnectController extends Controller
Expand All @@ -25,18 +24,9 @@ class ConnectController extends Controller

/**
* Where to redirect users after connection.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
protected function redirectTo(): string
{
$this->middleware('auth');
return '/';
}
}
14 changes: 2 additions & 12 deletions stubs/Identities/Auth/LoginController.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Identities\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Oneofftech\Identities\Auth\AuthenticatesUsersWithIdentity;

class LoginController extends Controller
Expand All @@ -24,18 +23,9 @@ class LoginController extends Controller

/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
protected function redirectTo(): string
{
$this->middleware('guest');
return '/';
}
}
18 changes: 4 additions & 14 deletions stubs/Identities/Auth/RegisterController.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace App\Http\Controllers\Identities\Auth;

use App\User;
use App\Models\User;
use Illuminate\Support\Str;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use App\Providers\RouteServiceProvider;
use Illuminate\Support\Facades\Validator;
use Oneofftech\Identities\Auth\RegistersUsersWithIdentity;

Expand All @@ -27,19 +26,10 @@ class RegisterController extends Controller

/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
protected function redirectTo(): string
{
$this->middleware('guest');
return '/';
}

/**
Expand Down Expand Up @@ -68,7 +58,7 @@ class RegisterController extends Controller
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password'] ?? Str::random(20)),
'password' => Hash::make($data['password'] ?? Str::random(30)),
]);
}
}
28 changes: 16 additions & 12 deletions stubs/Identities/Models/Identity.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
namespace App;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Oneofftech\Identities\Facades\Identity as IdentityFacade;

class Identity extends Model
{

/**
* @var array
*/
protected $casts = [
'expires_at' => 'datetime',
'registration' => 'bool',
];

/**
* @var array
*/
Expand All @@ -39,11 +30,24 @@ class Identity extends Model
'refresh_token',
'expires_at',
];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'expires_at' => 'datetime',
'registration' => 'bool',
];
}

/**
* The user to whom this identity belongs.
*/
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(IdentityFacade::userModel());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateIdentitiesTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -35,4 +35,4 @@ public function down()
{
Schema::dropIfExists('identities');
}
}
};
10 changes: 1 addition & 9 deletions tests/Fixtures/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@

namespace Tests\Fixtures\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
abstract class Controller {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ class ConnectController extends Controller

use ConnectUserIdentity;

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Get a validator for an incoming connection request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,4 @@ class LoginController extends Controller
*/

use AuthenticatesUsersWithIdentity;

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ class RegisterController extends Controller

use RegistersUsersWithIdentity;

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}

/**
* Get a validator for an incoming registration request.
*
Expand Down
Loading