Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
f0d7d0b4
Commit
f0d7d0b4
authored
Aug 05, 2020
by
manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added users, extracted jwt secret, protected endpoints
parent
1988488c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
8 deletions
+24
-8
.swagger.yml.swp
...stage-discovery-microservice/app/configs/.swagger.yml.swp
+0
-0
security_util.py
src/modules/security/security_util.py
+4
-2
swagger.yml
src/rest-gateway/app/configs/swagger.yml
+3
-1
user.py
src/rest-gateway/app/routes/user.py
+1
-1
token_service.py
src/rest-gateway/app/services/token_service.py
+16
-4
No files found.
src/data-hub/role-stage-discovery-microservice/app/configs/.swagger.yml.swp
0 → 100644
View file @
f0d7d0b4
File added
src/modules/security/security_util.py
View file @
f0d7d0b4
...
...
@@ -4,6 +4,7 @@ import network_constants
import
requests
import
json
from
typing
import
Dict
,
List
import
logging
class
TokenStash
:
'''
...
...
@@ -82,7 +83,8 @@ def _verify(token:str, roles:List[str]=[]):
token_info
=
decodeToken
(
token
,
roles
=
roles
)
return
token_info
except
Exception
as
e
:
print
(
"ERROR DURING TOKEN VALIDATION: "
+
str
(
e
))
LOGGER
=
logging
.
getLogger
(
__name__
)
LOGGER
.
error
(
"Token invalid: "
+
str
(
e
))
return
None
...
...
src/rest-gateway/app/configs/swagger.yml
View file @
f0d7d0b4
...
...
@@ -109,6 +109,8 @@ paths:
'
400'
:
description
:
wrong username or password
post
:
security
:
-
JwtAdmin
:
[]
operationId
:
"
routes.user.add"
tags
:
-
"
User"
...
...
src/rest-gateway/app/routes/user.py
View file @
f0d7d0b4
src/rest-gateway/app/services/token_service.py
View file @
f0d7d0b4
...
...
@@ -6,7 +6,6 @@ import jwt
from
datetime
import
datetime
,
timedelta
from
typing
import
Dict
SIGNING_KEY
=
"yteNrMy6142WKwp8fKfrHkS5nlFpxtHgOXJh1ZPsOrV_gTcsO9eMY7aB7HUzRbTRO9dmZhCl3FdPtuvMe3K8aBA_wc2MmHRo8IkUIGmvUJGsAxKFClN_6oNW5fEvoeVKiL1krA-qjWbR_em-WksePgPoTsySW7QbKdi4f7cwuyK2_JZ2fQj9hDKlfJ2GzMXkKiWcfyCTr30yC6BviAFeRDD_Bpvg6znsrXr53Tq66hnwDwQ6QU7aHVu-bERblKZTYuvkSxsov6yRMEVWQoiuBITsQtIOcgSWK4Dy3BjSbqoIcKw3WG-s3wx1lTen19QbEu8vJC64e0iGeGDWT6vbtg"
TOKEN_VALIDITY_IN_DAYS
=
1
def
verifyTokenRegular
(
token
,
required_scopes
)
->
Dict
:
...
...
@@ -42,6 +41,12 @@ class TokenService:
user
.
last_login
=
str
(
datetime
.
now
())
UserService
.
update
(
user
)
@
staticmethod
def
read_secret
()
->
str
:
with
open
(
'/srv/articonf/jwt_secret.txt'
,
'r'
)
as
file
:
secret
=
file
.
read
()
.
replace
(
'
\n
'
,
''
)
return
secret
@
staticmethod
def
generate_token
(
user
:
User
)
->
str
:
'''
...
...
@@ -50,6 +55,8 @@ class TokenService:
- created_at
- valid_until
'''
created_at
=
datetime
.
now
()
valid_until
=
created_at
+
timedelta
(
days
=
1
)
return
jwt
.
encode
(
...
...
@@ -58,7 +65,8 @@ class TokenService:
'created_at'
:
str
(
created_at
),
'valid_until'
:
str
(
valid_until
),
},
SIGNING_KEY
,
algorithm
=
'HS256'
TokenService
.
read_secret
(),
algorithm
=
'HS256'
)
.
decode
(
"utf-8"
)
@
staticmethod
...
...
@@ -80,7 +88,11 @@ class TokenService:
token
=
token
[
7
:]
try
:
payload
=
jwt
.
decode
(
token
,
SIGNING_KEY
,
algorithms
=
[
'HS256'
])
payload
=
jwt
.
decode
(
token
,
TokenService
.
read_secret
(),
algorithms
=
[
'HS256'
]
)
except
:
raise
ValueError
(
'Invalid JWT token (decoding failed)'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment