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
3e752fb6
Commit
3e752fb6
authored
Aug 04, 2020
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restGateway added user response to verify endpoint
parent
72f8b967
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
10 deletions
+17
-10
token_service.py
...tage-discovery-microservice/app/services/token_service.py
+2
-5
security_util.py
src/modules/security/security_util.py
+12
-3
user.py
src/rest-gateway/app/routes/user.py
+3
-2
No files found.
src/data-hub/role-stage-discovery-microservice/app/services/token_service.py
View file @
3e752fb6
# global import
from
security
import
security_util
import
logging
def
verifyTokenRegular
(
token
,
required_scopes
):
print
(
"gonna verify token: "
+
token
)
LOGGER
=
logging
.
getLogger
(
__name__
)
try
:
token_info
=
security_util
.
decodeToken
(
token
)
print
(
"TOKEN INFO: "
+
str
(
token_info
))
LOGGER
.
info
(
"TOKEN INFO: "
+
str
(
token_info
))
return
token_info
except
Exception
as
e
:
print
(
"ERROR DURING TOKEN VALIDATION: "
+
str
(
e
))
LOGGER
.
error
(
"ERROR DURING TOKEN VALIDATION: "
+
str
(
e
))
return
None
...
...
src/modules/security/security_util.py
View file @
3e752fb6
...
...
@@ -51,20 +51,29 @@ def decodeToken(token: str) -> Dict:
raise
ValueError
(
'Invalid JWT token (must be a Bearer string)'
)
token
=
token
[
7
:]
url
=
f
'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/tokens/{token}'
response
=
requests
.
post
(
f
'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/tokens/{token}'
,
url
,
verify
=
False
,
headers
=
{
'User-Agent'
:
'Chrome'
,
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
},
proxies
=
{
"http"
:
"http://proxy.uni-klu.ac.at:3128/"
,
"https"
:
"http://proxy.uni-klu.ac.at:3128/"
}
#
proxies = { "http":"http://proxy.uni-klu.ac.at:3128/", "https":"http://proxy.uni-klu.ac.at:3128/" }
)
if
response
.
status_code
!=
200
:
raise
ValueError
(
f
"Validation of token failed ({response.status_code})!"
)
# TODO replace with token information
data
=
json
.
dumps
(
response
.
text
)
if
not
"username"
in
data
:
print
(
"Verification Response (raw): "
+
response
.
text
)
print
(
"Verification Response: "
+
data
)
print
(
type
(
data
))
if
not
"username"
in
data
or
not
"role"
in
data
:
raise
ValueError
(
f
"Validation of token failed (missing field in verification response)!"
)
...
...
src/rest-gateway/app/routes/user.py
View file @
3e752fb6
...
...
@@ -7,6 +7,7 @@ from services.token_service import TokenService
from
flask
import
request
,
Response
import
bcrypt
import
jwt
import
json
def
secret
():
return
"Pineapple does not belong to pizza!"
...
...
@@ -22,9 +23,9 @@ def verify(token):
'''
try
:
TokenService
.
verify
(
"Bearer "
+
token
)
user
=
TokenService
.
verify
(
"Bearer "
+
token
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
,
response
=
json
.
dumps
(
user
.
to_serializable_dict
())
)
except
ValueError
as
e
:
return
Response
(
status
=
401
,
response
=
str
(
e
))
...
...
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