Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-python
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Custom issue tracker
Code
Merge requests
0
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
perxis
perxis-python
Merge requests
!3
Добавлен плагин аутентификации
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Добавлен плагин аутентификации
feature/auth
into
master
Overview
17
Commits
6
Pipelines
0
Changes
6
Merged
Andrei Biriukov
requested to merge
feature/auth
into
master
4 years ago
Overview
17
Commits
6
Pipelines
0
Changes
2
Expand
Created by: goshik-e
https://github.com/perxteam/perxis/issues/881
0
0
Merge request reports
Viewing commit
7893a4f6
Prev
Next
Show latest version
2 files
+
51
−
0
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)
7893a4f6
Add OAuth2Gateway for gRPC
· 7893a4f6
Georgiy Eterevskiy
authored
4 years ago
perxis/auth.py
0 → 100644
+
43
−
0
Options
import
time
import
grpc
from
oauthlib.oauth2
import
BackendApplicationClient
,
OAuth2Token
from
requests_oauthlib
import
OAuth2Session
class
OAuth2Gateway
(
grpc
.
AuthMetadataPlugin
):
_token
=
None
def
__init__
(
self
,
client_id
:
str
,
client_secret
:
str
,
token_url
:
str
,
audience
:
str
,
signature_header_key
:
str
=
'
Authorization
'
,
token_type
:
str
=
'
Bearer
'
)
->
None
:
self
.
_client_id
=
client_id
self
.
_client_secret
=
client_secret
self
.
_token_url
=
token_url
self
.
_audience
=
audience
self
.
_signature_header_key
=
signature_header_key
self
.
_token_type
=
token_type
self
.
oauth2
=
OAuth2Session
(
client
=
BackendApplicationClient
(
client_id
=
client_id
))
def
__call__
(
self
,
context
:
grpc
.
AuthMetadataContext
,
callback
:
grpc
.
AuthMetadataPluginCallback
)
->
None
:
callback
(((
self
.
_signature_header_key
,
f
'
{
self
.
_token_type
}
{
self
.
token
[
"
access_token
"
]
}
'
),),
None
)
@property
def
token
(
self
)
->
OAuth2Token
:
if
self
.
_token
is
None
:
self
.
_token
=
self
.
oauth2
.
fetch_token
(
token_url
=
self
.
_token_url
,
client_secret
=
self
.
_client_secret
,
audience
=
self
.
_audience
)
else
:
if
self
.
_token
.
expires_at
and
self
.
_token
.
expires_at
<
time
.
time
():
self
.
_token
=
self
.
oauth2
.
refresh_token
(
token_url
=
self
.
_token_url
,
client_secret
=
self
.
_client_secret
,
audience
=
self
.
_audience
)
return
self
.
_token
Loading