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
6
Expand
Created by: goshik-e
https://github.com/perxteam/perxis/issues/881
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
3fd99447
6 commits,
3 years ago
6 files
+
170
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
perxis/auth.py
0 → 100644
+
53
−
0
Options
import
time
from
typing
import
Type
import
grpc
from
oauthlib.oauth2
import
Client
,
OAuth2Token
from
requests_oauthlib
import
OAuth2Session
class
OAuth2Plugin
(
grpc
.
AuthMetadataPlugin
):
_token
=
None
def
__init__
(
self
,
client
:
Type
[
Client
],
client_secret
:
str
,
token_url
:
str
,
audience
:
str
,
signature_header_key
:
str
=
'
Authorization
'
,
token_type
:
str
=
'
Bearer
'
)
->
None
:
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
=
client
)
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
:
def
fetch_token
()
->
OAuth2Token
:
return
self
.
oauth2
.
fetch_token
(
token_url
=
self
.
_token_url
,
client_secret
=
self
.
_client_secret
,
audience
=
self
.
_audience
)
def
refresh_token
()
->
OAuth2Token
:
return
self
.
oauth2
.
refresh_token
(
token_url
=
self
.
_token_url
,
client_secret
=
self
.
_client_secret
,
audience
=
self
.
_audience
)
if
self
.
_token
is
None
:
self
.
_token
=
fetch_token
()
if
self
.
_token
.
expires_at
and
self
.
_token
.
expires_at
<
time
.
time
():
if
'
refresh_token
'
in
self
.
_token
:
self
.
_token
=
refresh_token
()
else
:
self
.
_token
=
fetch_token
()
return
self
.
_token
Loading