Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
scc-net
netvs
netvs-core
Commits
a8bbd23b
Commit
a8bbd23b
authored
Jul 01, 2020
by
janis.streib
🦉
Browse files
FMT
parent
ff93ed77
Pipeline
#94801
passed with stages
in 7 minutes and 23 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
middleware/net_suite/modules/login_oic/views.py
View file @
a8bbd23b
...
...
@@ -18,6 +18,7 @@ def get_client():
oic_client
.
store_registration_info
(
client_reg
)
return
oic_client
def
get_authorization_response
(
client
):
authorization_response
=
client
.
parse_response
(
AuthorizationResponse
,
...
...
@@ -25,6 +26,7 @@ def get_authorization_response(client):
sformat
=
'dict'
)
return
authorization_response
@
login_oic
.
route
(
'/api/login'
,
methods
=
[
'POST'
])
def
api_login
():
s
=
request
.
environ
[
'beaker.session'
]
...
...
@@ -39,7 +41,9 @@ def api_login():
"response_type"
:
"code"
,
"scope"
:
[
"openid"
,
'profile'
,
'email'
],
"nonce"
:
s
[
"nonce"
],
"redirect_uri"
:
app
.
config
.
get
(
'DEBUG_OIC_REDIR'
)
+
'/'
+
debug_t_host
.
split
(
'//'
,
1
)[
1
]
if
db
.
host_omdl
.
OP_ENV_IS_DEVEL
and
request
.
host
.
split
(
':'
)[
0
]
==
'localhost'
else
app
.
config
.
get
(
'OIC_REDIR'
),
"redirect_uri"
:
app
.
config
.
get
(
'DEBUG_OIC_REDIR'
)
+
'/'
+
debug_t_host
.
split
(
'//'
,
1
)[
1
]
if
db
.
host_omdl
.
OP_ENV_IS_DEVEL
and
request
.
host
.
split
(
':'
)[
0
]
==
'localhost'
else
app
.
config
.
get
(
'OIC_REDIR'
),
"state"
:
s
[
"state"
]
}
auth_req
=
oic_client
.
construct_AuthorizationRequest
(
request_args
=
args
)
...
...
@@ -50,6 +54,7 @@ def api_login():
s
.
save
()
return
jsonify
({
'login'
:
s
[
'login'
],
'token'
:
s
.
get
(
'login_token'
,
None
)})
def
user_from_userinfo
(
db
,
conn
,
userinfo
):
user
=
DBMgr
.
get_by_login_name
(
db
,
conn
,
userinfo
[
'preferred_username'
])
if
user
is
not
None
:
...
...
@@ -59,6 +64,7 @@ def user_from_userinfo(db, conn, userinfo):
last_name
=
userinfo
.
get
(
'sn'
,
None
),
email
=
userinfo
[
'email'
])
@
login_oic
.
route
(
'/api/oic_responder'
)
def
oic_responder
(
t_host
=
None
):
s
=
request
.
environ
[
'beaker.session'
]
...
...
@@ -80,6 +86,7 @@ def oic_responder(t_host=None):
s
.
save
()
return
redirect
(
'/oic_login'
)
@
login_oic
.
route
(
'/api/debug_oic_responder/<t_host>'
)
def
debug_oic_responder
(
t_host
=
None
):
if
not
(
db
.
host_omdl
.
OP_ENV_IS_DEVEL
and
t_host
is
not
None
and
t_host
.
split
(
':'
)[
0
]
==
'localhost'
):
...
...
@@ -90,7 +97,7 @@ def debug_oic_responder(t_host=None):
code
=
aresp
[
"code"
]
args
=
{
"code"
:
aresp
[
'code'
],
"redirect_uri"
:
app
.
config
.
get
(
'DEBUG_OIC_REDIR'
)
+
'/'
+
t_host
,
"redirect_uri"
:
app
.
config
.
get
(
'DEBUG_OIC_REDIR'
)
+
'/'
+
t_host
,
}
resp
=
oic_client
.
do_access_token_request
(
state
=
aresp
[
'state'
],
...
...
@@ -98,8 +105,8 @@ def debug_oic_responder(t_host=None):
authn_method
=
'client_secret_basic'
)
print
(
resp
)
userinfo
=
oic_client
.
do_user_info_request
(
state
=
aresp
[
"state"
])
new_target
=
'http://'
+
t_host
+
'/api/debug_oic_receiver'
return
render_template
(
'debug_forward.html'
,
**
{
'redir'
:
t_host
,
'new_target'
:
new_target
,
'userinfo'
:
userinfo
})
new_target
=
'http://'
+
t_host
+
'/api/debug_oic_receiver'
return
render_template
(
'debug_forward.html'
,
**
{
'redir'
:
t_host
,
'new_target'
:
new_target
,
'userinfo'
:
userinfo
})
@
login_oic
.
route
(
'/api/debug_oic_receiver'
,
methods
=
[
'POST'
])
...
...
@@ -109,7 +116,7 @@ def debug_oic_receiver():
s
=
request
.
environ
[
'beaker.session'
]
s
[
'login'
]
=
user_from_userinfo
(
db
,
get_db_conn
(),
request
.
form
)
s
.
save
()
return
redirect
(
'http://'
+
request
.
form
[
'redir'
]
+
'/oic_login'
)
return
redirect
(
'http://'
+
request
.
form
[
'redir'
]
+
'/oic_login'
)
@
login_oic
.
route
(
'/api/logout'
,
methods
=
[
'POST'
])
...
...
@@ -121,4 +128,3 @@ def api_logout():
s
.
delete
()
s
.
save
()
return
jsonify
({
'logout'
:
'success'
})
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