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
Commits
39a4619c
Commit
39a4619c
authored
4 years ago
by
Georgiy Eterevskiy
Browse files
Options
Downloads
Patches
Plain Diff
Add example for auth client
parent
82e53a7a
No related branches found
No related tags found
1 merge request
!5
Добавлены примеры использования, обновлены proto, произведен апгрейд зависимостей
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/collections_auth_client.py
+37
-0
37 additions, 0 deletions
examples/collections_auth_client.py
perxis/auth.py
+2
-2
2 additions, 2 deletions
perxis/auth.py
with
39 additions
and
2 deletions
examples/collections_auth_client.py
0 → 100644
+
37
−
0
View file @
39a4619c
import
logging
import
grpc
from
oauthlib.oauth2
import
BackendApplicationClient
from
perxis.auth
import
OAuth2Plugin
from
perxis.collections_perxis.collections_pb2
import
ListRequest
from
perxis.collections_perxis.collections_pb2_grpc
import
CollectionsStub
def
main
():
client_id
=
'
YGPQSAUPgco4iTQxNejtXDjFVwPmYT3n
'
client_secret
=
'
_d6F-VlQGmcsU25AXIoCU4EU3v56-28P6jwUHkutg_hSPseConphyLs3F-Buuq1h
'
token_url
=
'
https://adwz.auth0.com/oauth/token
'
audience
=
'
some
'
oauth2_plugin
=
OAuth2Plugin
(
client
=
BackendApplicationClient
(
client_id
=
client_id
),
client_secret
=
client_secret
,
token_url
=
token_url
,
audience
=
audience
)
call_credentials
=
grpc
.
metadata_call_credentials
(
oauth2_plugin
,
name
=
'
auth
'
)
channel_credentials
=
grpc
.
ssl_channel_credentials
()
composite_credentials
=
grpc
.
composite_channel_credentials
(
channel_credentials
,
call_credentials
)
with
grpc
.
secure_channel
(
'
envoy.perxis.pt.perx.ru:443
'
,
composite_credentials
)
as
channel
:
stub
=
CollectionsStub
(
channel
)
collections
=
stub
.
List
(
ListRequest
(
space_id
=
"
c1mrvup3e6litup7tf0g
"
,
env_id
=
"
master
"
))
print
(
collections
)
if
__name__
==
'
__main__
'
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
main
()
This diff is collapsed.
Click to expand it.
perxis/auth.py
+
2
−
2
View file @
39a4619c
...
...
@@ -11,7 +11,7 @@ class OAuth2Plugin(grpc.AuthMetadataPlugin):
_token
=
None
def
__init__
(
self
,
client
:
Type
[
Client
],
client_secret
:
str
,
token_url
:
str
,
audience
:
str
,
signature_header_key
:
str
=
'
A
uthorization
'
,
token_type
:
str
=
'
Bearer
'
)
->
None
:
signature_header_key
:
str
=
'
a
uthorization
'
,
token_type
:
str
=
'
Bearer
'
)
->
None
:
self
.
_client_secret
=
client_secret
self
.
_token_url
=
token_url
...
...
@@ -44,7 +44,7 @@ class OAuth2Plugin(grpc.AuthMetadataPlugin):
if
self
.
_token
is
None
:
self
.
_token
=
fetch_token
()
if
self
.
_token
.
expires_at
and
self
.
_token
.
expires_at
<
time
.
time
():
if
self
.
_token
[
'
expires_at
'
]
and
self
.
_token
[
'
expires_at
'
]
<
time
.
time
():
if
'
refresh_token
'
in
self
.
_token
:
self
.
_token
=
refresh_token
()
else
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment