Skip to content

Commit

Permalink
Merge pull request #2 from RonasIT/1-init-package
Browse files Browse the repository at this point in the history
Fix logical errors
  • Loading branch information
astorozhevsky authored Nov 4, 2024
2 parents f554609 + d668a65 commit 098560f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ composer require ronasit/laravel-clerk
```

2. Publish the package configuration:

```sh
php artisan vendor:publish --provider=RonasIT\\Clerk\\ClerkServiceProvider`
php artisan vendor:publish --provider=RonasIT\\Clerk\\Providers\\ClerkServiceProvider
```

3. Add a new `clerk` guard within the `guards` array in your `config/auth.php` file:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"extra": {
"laravel": {
"providers": [
"RonasIT\\Clerk\\ClerkServiceProvider"
"RonasIT\\Clerk\\Providers\\ClerkServiceProvider"
]
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/Auth/ClerkGuard.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Guards;
namespace RonasIT\Clerk\Auth;

use Illuminate\Support\Arr;
use Lcobucci\JWT\Encoding\JoseEncoder;
Expand Down Expand Up @@ -127,16 +127,14 @@ protected function validateToken(Token $decoded): void
throw new TokenValidationException('Token is expired or not yet valid');
}

if ($decoded->hasBeenIssuedBy(config('clerk.allowed_issuers'))) {
if (!$decoded->hasBeenIssuedBy(config('clerk.allowed_issuer'))) {
throw new TokenValidationException('Token was issued by not allowed issuer.');
}

$origin = $decoded->claims()->get('azp');

if (!empty($origin)) {
if (!in_array($origin, config('clerk.allowed_origins'))) {
throw new TokenValidationException('Token was received from not allowed origin.');
}
if (!empty($origin) && !in_array($origin, config('clerk.allowed_origins'))) {
throw new TokenValidationException('Token was received from not allowed origin.');
}

$signerKey = InMemory::file(base_path(config('clerk.signer_key_path')), config('clerk.secret_key'));
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(

public function getAuthIdentifierName(): string
{
return 'external_id';
return 'externalId';
}

public function getAuthIdentifier(): string
Expand Down
10 changes: 9 additions & 1 deletion src/Providers/ClerkServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace RonasIT\Clerk\Providers;

use App\Guards\ClerkGuard;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;
use RonasIT\Clerk\Auth\ClerkGuard;
use RonasIT\Clerk\Contracts\UserRepositoryContract;
use RonasIT\Clerk\Repositories\UserRepository;

class ClerkServiceProvider extends ServiceProvider
{
Expand All @@ -15,6 +17,12 @@ public function boot(): void
callback: fn ($app) => app(ClerkGuard::class)->setRequest($app->make('request'))
);

$this->app->bind(UserRepositoryContract::class, UserRepository::class);

$this->mergeConfigFrom(__DIR__ . '/../../config/clerk.php', 'clerk');

$this->publishes([
__DIR__ . '/../../config/clerk.php' => config_path('clerk.php'),
], 'config');
}
}

0 comments on commit 098560f

Please sign in to comment.