-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Add OpenID Connect (OIDC) support! #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a20042c
feat: Add OpenID Connect (OIDC) support with configuration options, i…
NaysKutzu efc56bb
feat: Enhance OIDC provider management by adding client secret stripp…
NaysKutzu 211f3d3
feat: Enhance OIDC provider functionality by adding issuer URL valida…
NaysKutzu 55a9b01
fix: Validate client_secret input to ensure it is not empty before en…
NaysKutzu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of FeatherPanel. | ||
| * | ||
| * Copyright (C) 2025 MythicalSystems Studios | ||
| * Copyright (C) 2025 FeatherPanel Contributors | ||
| * Copyright (C) 2025 Cassian Gherman (aka NaysKutzu) | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published | ||
| * by the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * See the LICENSE file or <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace App\Chat; | ||
|
|
||
| use App\App; | ||
|
|
||
| /** | ||
| * OIDC provider model for CRUD operations on the featherpanel_oidc_providers table. | ||
| */ | ||
| class OidcProvider | ||
| { | ||
| private static string $table = 'featherpanel_oidc_providers'; | ||
|
|
||
| /** | ||
| * Create a new OIDC provider. | ||
| * | ||
| * @param array $data | ||
| * | ||
| * @return int|false | ||
| */ | ||
| public static function createProvider(array $data): int | false | ||
| { | ||
| $required = ['uuid', 'name', 'issuer_url', 'client_id', 'client_secret']; | ||
| foreach ($required as $field) { | ||
| if (!isset($data[$field]) || !is_string($data[$field]) || trim($data[$field]) === '') { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| $pdo = Database::getPdoConnection(); | ||
| $fields = array_keys($data); | ||
| $placeholders = array_map(fn ($f) => ':' . $f, $fields); | ||
| $sql = 'INSERT INTO ' . self::$table . ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $placeholders) . ')'; | ||
| $stmt = $pdo->prepare($sql); | ||
|
|
||
| if ($stmt->execute($data)) { | ||
| return (int) $pdo->lastInsertId(); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Update provider by UUID. | ||
| */ | ||
| public static function updateProvider(string $uuid, array $data): bool | ||
| { | ||
| if (empty($data)) { | ||
| return false; | ||
| } | ||
| unset($data['id'], $data['uuid']); | ||
|
|
||
| $pdo = Database::getPdoConnection(); | ||
| $fields = array_keys($data); | ||
| $set = implode(', ', array_map(fn ($f) => "$f = :$f", $fields)); | ||
| $sql = 'UPDATE ' . self::$table . ' SET ' . $set . ' WHERE uuid = :uuid'; | ||
|
|
||
| $params = $data; | ||
| $params['uuid'] = $uuid; | ||
| $stmt = $pdo->prepare($sql); | ||
|
|
||
| return $stmt->execute($params); | ||
| } | ||
|
|
||
| /** | ||
| * Delete provider by UUID. | ||
| */ | ||
| public static function deleteProvider(string $uuid): bool | ||
| { | ||
| $pdo = Database::getPdoConnection(); | ||
| $stmt = $pdo->prepare('DELETE FROM ' . self::$table . ' WHERE uuid = :uuid'); | ||
|
|
||
| return $stmt->execute(['uuid' => $uuid]); | ||
| } | ||
|
|
||
| /** | ||
| * Get provider by UUID. | ||
| */ | ||
| public static function getProviderByUuid(string $uuid): ?array | ||
| { | ||
| $pdo = Database::getPdoConnection(); | ||
| $stmt = $pdo->prepare('SELECT * FROM ' . self::$table . ' WHERE uuid = :uuid LIMIT 1'); | ||
| $stmt->execute(['uuid' => $uuid]); | ||
|
|
||
| return $stmt->fetch(\PDO::FETCH_ASSOC) ?: null; | ||
| } | ||
|
|
||
| /** | ||
| * Get all providers. | ||
| */ | ||
| public static function getAllProviders(): array | ||
| { | ||
| $pdo = Database::getPdoConnection(); | ||
| $stmt = $pdo->prepare('SELECT * FROM ' . self::$table . ' ORDER BY name ASC'); | ||
| $stmt->execute(); | ||
|
|
||
| return $stmt->fetchAll(\PDO::FETCH_ASSOC); | ||
| } | ||
|
|
||
| /** | ||
| * Get all enabled providers (safe for public exposure). | ||
| */ | ||
| public static function getEnabledProviders(): array | ||
| { | ||
| $pdo = Database::getPdoConnection(); | ||
| $stmt = $pdo->prepare('SELECT uuid, name FROM ' . self::$table . " WHERE enabled = 'true' ORDER BY name ASC"); | ||
| $stmt->execute(); | ||
|
|
||
| return $stmt->fetchAll(\PDO::FETCH_ASSOC); | ||
| } | ||
|
|
||
| /** | ||
| * Generate a UUID for providers. | ||
| */ | ||
| public static function generateUuid(): string | ||
| { | ||
| $bytes = random_bytes(16); | ||
| $bytes[6] = chr(ord($bytes[6]) & 0x0F | 0x40); | ||
| $bytes[8] = chr(ord($bytes[8]) & 0x3F | 0x80); | ||
| $hex = bin2hex($bytes); | ||
|
|
||
| return sprintf( | ||
| '%s-%s-%s-%s-%s', | ||
| substr($hex, 0, 8), | ||
| substr($hex, 8, 4), | ||
| substr($hex, 12, 4), | ||
| substr($hex, 16, 4), | ||
| substr($hex, 20, 12) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate
generateUuidacross multiple model classesLow Severity
OidcProvider::generateUuid()is an exact copy ofUser::generateUuid(), which itself is identical to existing implementations inNode::generateUuid(),Server::generateUuid(), andSpell::generateUuid(). This PR adds two more copies of the same UUID v4 generation logic instead of extracting it to a shared utility.Additional Locations (1)
backend/app/Chat/User.php#L417-L433