-
Notifications
You must be signed in to change notification settings - Fork 2
[#89] JWT authentication and authorization #96
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -421,6 +421,92 @@ curl -X DELETE "http://localhost:8080/api/v1/components/long_calibration/operati | |||
| } | ||||
| ``` | ||||
|
|
||||
| ### Authentication Endpoints | ||||
|
|
||||
| #### POST /api/v1/auth/authorize | ||||
|
|
||||
| Authenticate using OAuth2 client credentials flow. Returns access and refresh tokens. | ||||
|
|
||||
| **Example (JSON):** | ||||
| ```bash | ||||
| curl -X POST http://localhost:8080/api/v1/auth/authorize \ | ||||
| -H "Content-Type: application/json" \ | ||||
| -d '{ | ||||
| "grant_type": "client_credentials", | ||||
| "client_id": "my_client", | ||||
| "client_secret": "my_secret" | ||||
| }' | ||||
| ``` | ||||
|
|
||||
| **Example (Form URL-encoded):** | ||||
| ```bash | ||||
| curl -X POST http://localhost:8080/api/v1/auth/authorize \ | ||||
| -H "Content-Type: application/x-www-form-urlencoded" \ | ||||
| -d 'grant_type=client_credentials&client_id=my_client&client_secret=my_secret' | ||||
| ``` | ||||
|
|
||||
| **Response (200 OK):** | ||||
| ```json | ||||
| { | ||||
| "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", | ||||
| "token_type": "Bearer", | ||||
| "expires_in": 3600, | ||||
| "refresh_token": "dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4...", | ||||
| "scope": "admin" | ||||
| } | ||||
| ``` | ||||
|
|
||||
| **Response (401 Unauthorized - Invalid Credentials):** | ||||
| ```json | ||||
| { | ||||
| "error": "invalid_client", | ||||
| "error_description": "Invalid client credentials" | ||||
| } | ||||
| ``` | ||||
|
|
||||
| #### POST /api/v1/auth/token | ||||
|
|
||||
| Refresh an access token using a refresh token. | ||||
|
|
||||
| **Example:** | ||||
| ```bash | ||||
| curl -X POST http://localhost:8080/api/v1/auth/token \ | ||||
| -H "Content-Type: application/json" \ | ||||
| -d '{ | ||||
| "grant_type": "refresh_token", | ||||
| "refresh_token": "dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4..." | ||||
| }' | ||||
| ``` | ||||
|
|
||||
| **Response (200 OK):** | ||||
| ```json | ||||
| { | ||||
| "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", | ||||
| "token_type": "Bearer", | ||||
| "expires_in": 3600, | ||||
| "refresh_token": "bmV3IHJlZnJlc2ggdG9rZW4...", | ||||
|
||||
| "refresh_token": "bmV3IHJlZnJlc2ggdG9rZW4...", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright 2025 bburda | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| /** | ||
| * @file auth.hpp | ||
| * @brief Convenience header that includes all authentication components | ||
| * | ||
| * This header provides a single include for all authentication-related | ||
| * functionality in the ros2_medkit_gateway. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "ros2_medkit_gateway/auth/auth_config.hpp" | ||
| #include "ros2_medkit_gateway/auth/auth_manager.hpp" | ||
| #include "ros2_medkit_gateway/auth/auth_middleware.hpp" | ||
| #include "ros2_medkit_gateway/auth/auth_models.hpp" | ||
| #include "ros2_medkit_gateway/auth/auth_requirement_policy.hpp" |
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.
The
FetchContent_Declareforjwt-cpppulls third-party code directly from GitHub using only a mutable tag (v0.7.0), which allows upstream changes (or compromise) to silently alter the code executed in your build environment. This creates a supply chain risk where an attacker controlling or tampering with theThalhammer/jwt-cpprepository or tag could inject arbitrary code during your build, potentially compromising build artifacts or secrets. To mitigate this, pin the dependency to an immutable identifier (e.g., a specific commit SHA or verified release archive hash) and, where possible, add integrity checks (checksums/signatures) for the downloaded content.