Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Redmine Login Laravel Package

ekreative/redmine_login

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require ekreative/redmine_login
    
  2. Register the Bundle in config/bundles.php (Symfony):

    return [
        // ...
        Ekreative\RedmineLoginBundle\EkreativeRedmineLoginBundle::class => ['all' => true],
    ];
    
  3. Configure Parameters in .env (Laravel/Symfony hybrid):

    REDMINE_URL=http://your-redmine-instance.com
    
  4. Add to config/services.php (Laravel):

    'redmine' => [
        'url' => env('REDMINE_URL'),
    ],
    
  5. Publish Config (if needed):

    php artisan vendor:publish --provider="Ekreative\RedmineLoginBundle\EkreativeRedmineLoginBundle"
    
  6. First Use Case:

    • Redirect users to Redmine for authentication via a custom route (e.g., /login/redmine).
    • Example route in routes/web.php (Laravel):
      Route::get('/login/redmine', [RedmineAuthController::class, 'redirectToRedmine']);
      

Implementation Patterns

Core Workflow

  1. Authentication Flow:

    • Redirect users to Redmine’s OAuth/SSO endpoint (if configured).
    • Handle callback via Ekreative\RedmineLoginBundle\Security\RedmineAuthenticationProvider.
    • Map Redmine user data to Laravel/Symfony users (e.g., via User model).
  2. User Provider Integration:

    • Extend Laravel’s Illuminate\Contracts\Auth\Authenticatable or Symfony’s UserInterface to include Redmine-specific fields (e.g., redmine_id, redmine_login).
    • Example Laravel User model trait:
      use Ekreative\RedmineLoginBundle\Traits\RedmineUserTrait;
      
  3. Role/Groups Sync:

    • Fetch Redmine group memberships and sync to Laravel’s roles table or Symfony’s ROLE_* roles.
    • Example:
      $redmineGroups = $redmineClient->getUserGroups($user->redmine_id);
      $user->syncRoles(array_map(fn($g) => 'GROUP_'.$g['name'], $redmineGroups));
      
  4. Session Handling:

    • Use middleware to validate Redmine sessions on protected routes:
      protected function authenticate(Request $request, Response $response) {
          if (!$request->user()->redmine_token) {
              return redirect()->route('login.redmine');
          }
          return $response;
      }
      
  5. API Integration:

    • Use the bundled RedmineClient to fetch user/project data:
      $client = new \Ekreative\RedmineLoginBundle\Client\RedmineClient(
          config('redmine.url'),
          $user->redmine_api_key
      );
      $projects = $client->getProjects();
      

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony Bundle:

    • The package targets Symfony, not Laravel. Use a wrapper like spatie/laravel-symfony-bundle or adapt the logic manually.
    • Key classes to replicate:
      • RedmineAuthenticationProvider (for auth logic).
      • RedmineUserProvider (for user resolution).
  2. Outdated Dependencies:

    • Last updated in 2017; test with Redmine’s current API (v4+). Override the RedmineClient to handle changes:
      class CustomRedmineClient extends \Ekreative\RedmineLoginBundle\Client\RedmineClient {
          public function getUserGroups($userId) {
              return $this->request('users/'.$userId.'/memberships');
          }
      }
      
  3. Token Management:

    • Redmine’s API keys may expire. Implement a token refresh mechanism:
      if (!$user->redmine_token) {
          $token = $this->generateRedmineToken($user->redmine_login);
          $user->update(['redmine_token' => $token]);
      }
      
  4. CSRF and Security:

    • Redmine callbacks may trigger CSRF. Use Laravel’s VerifyCsrfToken middleware or Symfony’s csrf_token validation.
  5. Performance:

    • Cache Redmine API responses (e.g., user groups) to avoid repeated calls:
      Cache::remember("redmine_groups_{$user->redmine_id}", now()->addHours(1), function() use ($user) {
          return $this->redmineClient->getUserGroups($user->redmine_id);
      });
      

Tips

  1. Custom User Mapping:

    • Override Ekreative\RedmineLoginBundle\Security\User\RedmineUser to map Redmine attributes to Laravel fields:
      class LaravelRedmineUser extends RedmineUser {
          public function getAuthIdentifierName() {
              return 'redmine_id'; // Use Redmine's user ID as Laravel's ID
          }
      }
      
  2. Debugging:

    • Enable verbose logging for Redmine API calls:
      'redmine' => [
          'url' => env('REDMINE_URL'),
          'debug' => env('APP_DEBUG'), // Pass to client constructor
      ];
      
  3. Testing:

    • Mock the RedmineClient in tests:
      $mockClient = Mockery::mock(\Ekreative\RedmineLoginBundle\Client\RedmineClient::class);
      $mockClient->shouldReceive('getUserInfo')->andReturn(['id' => 1, 'login' => 'test']);
      $this->app->instance(\Ekreative\RedmineLoginBundle\Client\RedmineClient::class, $mockClient);
      
  4. Fallback Auth:

    • Combine with Laravel’s default auth (e.g., email/password) using a custom guard:
      'guards' => [
          'web' => [
              'driver' => 'session',
              'provider' => 'users',
          ],
          'redmine' => [
              'driver' => 'session',
              'provider' => 'redmine',
          ],
      ],
      
  5. Extension Points:

    • Events: Listen for redmine.login.success to trigger post-auth actions:
      event(new RedmineLoginEvent($user));
      
    • Commands: Create an Artisan command to sync all Redmine users:
      php artisan redmine:sync-users
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui