Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Merge requests
!152
Add standard Bearer token header instedad of access_token header
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add standard Bearer token header instedad of access_token header
fix/NAT-425-add-gso-api-key
into
develop
Overview
0
Commits
1
Pipelines
1
Changes
2
Merged
Mohammad Torkashvand
requested to merge
fix/NAT-425-add-gso-api-key
into
develop
1 year ago
Overview
0
Commits
1
Pipelines
1
Changes
2
Expand
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
aa28e8cd
1 commit,
1 year ago
2 files
+
10
−
6
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
gso/auth/api_key_auth.py
+
6
−
4
Options
"""
Manage API key validation for FastAPI routes.
"""
"""
Manage API key validation for FastAPI routes.
"""
from
fastapi
import
Depends
,
HTTPException
,
status
from
fastapi
import
Depends
,
HTTPException
,
status
from
fastapi.security
.api_key
import
APIKeyH
ea
d
er
from
fastapi.security
import
HTTPAuthorizationCredentials
,
HTTPB
ea
r
er
from
gso.settings
import
load_oss_params
from
gso.settings
import
load_oss_params
API_KEY_NAME
=
"
access_token
"
security
=
HTTPBearer
()
api_key_header
=
APIKeyHeader
(
name
=
API_KEY_NAME
,
auto_error
=
True
)
async
def
get_api_key
(
api_key
:
str
=
Depends
(
api_key_header
))
->
str
:
async
def
get_api_key
(
credentials
:
HTTPAuthorizationCredentials
=
Depends
(
security
),
# noqa: B008
)
->
str
:
"""
Validate the provided API key against known third-party keys and returns it if valid, else raises HTTP 403.
"""
"""
Validate the provided API key against known third-party keys and returns it if valid, else raises HTTP 403.
"""
settings
=
load_oss_params
()
settings
=
load_oss_params
()
api_key
=
credentials
.
credentials
# TODO: This is a simulated database of API keys which should be replace with a real one
# TODO: This is a simulated database of API keys which should be replace with a real one
if
api_key
in
settings
.
THIRD_PARTY_API_KEYS
.
values
():
if
api_key
in
settings
.
THIRD_PARTY_API_KEYS
.
values
():
Loading