Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kort-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Libraries
kort-client
Commits
77233a2b
Verified
Commit
77233a2b
authored
2 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Change authentication method to client credentials
parent
61401a1a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
kort_client/api.py
+8
-22
8 additions, 22 deletions
kort_client/api.py
kort_client/cli.py
+2
-24
2 additions, 24 deletions
kort_client/cli.py
kort_client/config.py
+0
-1
0 additions, 1 deletion
kort_client/config.py
pyproject.toml
+0
-1
0 additions, 1 deletion
pyproject.toml
with
10 additions
and
48 deletions
kort_client/api.py
+
8
−
22
View file @
77233a2b
...
...
@@ -3,7 +3,7 @@ from urllib.parse import urljoin
import
click
import
requests
as
requests
from
requests
_oauthlib
import
OAuth2Session
from
requests
import
request
from
.config
import
settings
...
...
@@ -29,7 +29,7 @@ class KortAPI:
def
__init__
(
self
):
self
.
settings
=
settings
self
.
oauth
=
self
.
_get_oauth_session
()
self
.
_validate_settings
()
def
get_printer
(
self
)
->
dict
[
str
,
Any
]:
r
=
self
.
_do_request
(
"
GET
"
,
"
printer
"
)
...
...
@@ -79,25 +79,6 @@ class KortAPI:
if
not
self
.
settings
.
access_token
:
raise
ConfigurationException
(
"
No access_token set.
"
)
def
_get_oauth_session
(
self
)
->
OAuth2Session
:
self
.
_validate_settings
()
def
token_saver
(
token
):
self
.
settings
.
access_token
=
token
self
.
settings
.
save_settings
()
oauth
=
OAuth2Session
(
self
.
settings
.
client_id
,
token
=
self
.
settings
.
access_token
,
auto_refresh_url
=
urljoin
(
self
.
settings
.
base_url
,
"
oauth/token/
"
),
auto_refresh_kwargs
=
dict
(
client_id
=
self
.
settings
.
client_id
,
client_secret
=
self
.
settings
.
client_secret
,
),
token_updater
=
token_saver
,
)
return
oauth
def
_do_request
(
self
,
method
:
str
,
url
:
str
,
attrs
:
Optional
[
Sequence
]
=
None
,
**
kwargs
)
->
dict
[
str
,
Any
]:
...
...
@@ -107,7 +88,12 @@ class KortAPI:
url
=
url
.
format
(
*
attrs
)
url
=
urljoin
(
settings
.
base_url
,
url
)
try
:
r
=
self
.
oauth
.
request
(
method
,
url
,
**
kwargs
)
r
=
request
(
method
,
url
,
auth
=
(
self
.
settings
.
client_id
,
self
.
settings
.
client_secret
),
**
kwargs
)
if
not
r
.
ok
:
click
.
secho
(
"
Error {}: {}
"
.
format
(
r
.
status_code
,
r
.
text
),
fg
=
"
red
"
)
raise
KortAPIException
(
"
Error {}: {}
"
.
format
(
r
.
status_code
,
r
.
text
))
...
...
This diff is collapsed.
Click to expand it.
kort_client/cli.py
+
2
−
24
View file @
77233a2b
import
json
from
urllib.parse
import
urljoin
import
click
from
requests_oauthlib
import
OAuth2Session
from
kort_client.api
import
KortAPI
from
kort_client.run
import
PrintClient
...
...
@@ -41,28 +39,6 @@ def setup(config_file):
settings
.
client_secret
=
config
[
"
client_secret
"
]
settings
.
base_url
=
config
[
"
base_url
"
]
scope
=
[
"
card_printer
"
]
oauth
=
OAuth2Session
(
settings
.
client_id
,
scope
=
scope
,
redirect_uri
=
"
urn:ietf:wg:oauth:2.0:oob
"
)
authorization_url
,
state
=
oauth
.
authorization_url
(
urljoin
(
settings
.
base_url
,
"
oauth/authorize
"
)
)
click
.
echo
(
"
Please go to {} and authorize access
"
.
format
(
authorization_url
))
code
=
click
.
prompt
(
"
Paste the authorization code here
"
,
type
=
str
)
token
=
oauth
.
fetch_token
(
urljoin
(
settings
.
base_url
,
"
oauth/token/
"
),
code
=
code
,
include_client_id
=
True
,
client_secret
=
settings
.
client_secret
,
)
click
.
echo
(
token
)
settings
.
access_token
=
token
settings
.
save_settings
()
api
=
KortAPI
()
...
...
@@ -71,6 +47,8 @@ def setup(config_file):
api
.
set_printer_status
(
printer_id
,
"
offline
"
,
"
Newly registered printer
"
)
click
.
echo
(
"
Successfully registered printer
"
)
@cli.command
()
def
config
():
...
...
This diff is collapsed.
Click to expand it.
kort_client/config.py
+
0
−
1
View file @
77233a2b
...
...
@@ -4,5 +4,4 @@ settings = usersettings.Settings("org.aleksis.apps.kort.client")
settings
.
add_setting
(
"
client_id
"
,
str
,
default
=
""
)
settings
.
add_setting
(
"
client_secret
"
,
str
,
default
=
""
)
settings
.
add_setting
(
"
base_url
"
,
str
,
default
=
""
)
settings
.
add_setting
(
"
access_token
"
,
dict
,
default
=
{})
settings
.
load_settings
()
This diff is collapsed.
Click to expand it.
pyproject.toml
+
0
−
1
View file @
77233a2b
...
...
@@ -14,7 +14,6 @@ python = "^3.9"
click
=
"^8.0.4"
usersettings
=
"^1.1.5"
requests
=
"^2.27.1"
requests-oauthlib
=
"^1.3.1"
pycups
=
"^2.0.1"
usb-barcode-scanner-julz
=
"^0.2"
...
...
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