Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Openlobby Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
TO
openlobby
Openlobby Server
Commits
d81ccef2
Commit
d81ccef2
authored
7 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
Login by shortcut WIP.
parent
954ffb13
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
openlobby/mutations.py
+63
-1
63 additions, 1 deletion
openlobby/mutations.py
openlobby/openid.py
+19
-1
19 additions, 1 deletion
openlobby/openid.py
tests/snapshots/snap_test_management.py
+4
-16
4 additions, 16 deletions
tests/snapshots/snap_test_management.py
with
86 additions
and
18 deletions
openlobby/mutations.py
+
63
−
1
View file @
d81ccef2
...
...
@@ -3,6 +3,7 @@ from flask import g
import
graphene
from
graphene
import
relay
from
graphene.types.datetime
import
DateTime
from
graphql_relay
import
from_global_id
from
oic.oic
import
rndstr
from
oic.oic.message
import
AuthorizationResponse
import
time
...
...
@@ -13,9 +14,16 @@ from .auth import (
get_session_expiration_time
,
create_access_token
,
)
from
.documents
import
UserDoc
,
LoginAttemptDoc
,
SessionDoc
,
ReportDoc
from
.documents
import
(
UserDoc
,
LoginAttemptDoc
,
SessionDoc
,
ReportDoc
,
OpenIdClientDoc
,
)
from
.openid
import
(
init_client_for_uid
,
init_client_for_shortcut
,
register_client
,
get_authorization_url
,
set_registration_info
,
...
...
@@ -72,6 +80,59 @@ class Login(relay.ClientIDMutation):
return
Login
(
authorization_url
=
authorization_url
)
class
LoginByShortcut
(
relay
.
ClientIDMutation
):
class
Input
:
shortcut_id
=
relay
.
GlobalID
(
required
=
True
)
redirect_uri
=
graphene
.
String
(
required
=
True
)
authorization_url
=
graphene
.
String
()
@classmethod
def
mutate_and_get_payload
(
cls
,
root
,
info
,
**
input
):
shortcut_id
=
input
[
'
shortcut_id
'
]
redirect_uri
=
input
[
'
redirect_uri
'
]
type
,
id
=
from_global_id
(
shortcut_id
)
openid_client_data
=
OpenIdClientDoc
.
get
(
id
,
using
=
info
.
context
[
'
es
'
],
index
=
info
.
context
[
'
index
'
])
# prepare OpenID client
client
=
init_client_for_shortcut
(
openid_client_data
,
redirect_uri
)
# TODO
"""
# prepare login attempt details
state = rndstr(32)
nonce = rndstr()
expiration = get_login_attempt_expiration_time()
# save login attempt into ES
data = {
'
meta
'
: {
'
id
'
: client.client_id},
'
state
'
: state,
'
nonce
'
: nonce,
'
client_id
'
: client.client_id,
'
client_secret
'
: client.client_secret,
'
openid_uid
'
: openid_uid,
'
redirect_uri
'
: redirect_uri,
'
expiration
'
: expiration,
}
login_attempt = LoginAttemptDoc(**data)
login_attempt.save(using=info.context[
'
es
'
], index=info.context[
'
index
'
])
# already registered user?
user = UserDoc.get_by_openid_uid(openid_uid, **info.context)
is_new_user = user is None
# get OpenID authorization url
authorization_url = get_authorization_url(client, state, nonce, is_new_user)
"""
authorization_url
=
'
http://localhost/foo
'
return
LoginByShortcut
(
authorization_url
=
authorization_url
)
class
LoginRedirect
(
relay
.
ClientIDMutation
):
class
Input
:
...
...
@@ -184,6 +245,7 @@ class NewReport(relay.ClientIDMutation):
class
Mutation
(
graphene
.
ObjectType
):
login
=
Login
.
Field
()
login_by_shortcut
=
LoginByShortcut
.
Field
()
login_redirect
=
LoginRedirect
.
Field
()
logout
=
Logout
.
Field
()
new_report
=
NewReport
.
Field
()
This diff is collapsed.
Click to expand it.
openlobby/openid.py
+
19
−
1
View file @
d81ccef2
from
oic.oic
import
Client
from
oic.oic.message
import
RegistrationResponse
,
ClaimsRequest
,
Claims
from
oic.oic.message
import
(
ProviderConfigurationResponse
,
RegistrationResponse
,
ClaimsRequest
,
Claims
,
)
from
oic.utils.authn.client
import
CLIENT_AUTHN_METHOD
from
.settings
import
SITE_NAME
...
...
@@ -12,6 +17,19 @@ def init_client_for_uid(openid_uid):
return
client
def
init_client_for_shortcut
(
data
,
redirect_uri
):
client
=
Client
(
client_authn_method
=
CLIENT_AUTHN_METHOD
)
set_registration_info
(
client
,
data
[
'
client_id
'
],
data
[
'
client_secret
'
],
redirect_uri
)
info
=
{
'
issuer
'
:
data
[
'
issuer
'
],
'
authorization_endpoint
'
:
data
[
'
authorization_endpoint
'
],
'
token_endpoint
'
:
data
[
'
token_endpoint
'
],
'
userinfo_endpoint
'
:
data
[
'
userinfo_endpoint
'
],
}
client
.
provider_info
=
ProviderConfigurationResponse
(
**
info
)
return
client
def
register_client
(
client
,
redirect_uri
):
params
=
{
'
redirect_uris
'
:
[
redirect_uri
],
...
...
This diff is collapsed.
Click to expand it.
tests/snapshots/snap_test_management.py
+
4
−
16
View file @
d81ccef2
...
...
@@ -80,7 +80,7 @@ snapshots['test_create_index__check_mappings 1'] = {
'
client_secret
'
:
{
'
type
'
:
'
keyword
'
},
'
is
S
hortcut
'
:
{
'
is
_s
hortcut
'
:
{
'
type
'
:
'
boolean
'
},
'
issuer
'
:
{
...
...
@@ -89,9 +89,6 @@ snapshots['test_create_index__check_mappings 1'] = {
'
name_x
'
:
{
'
type
'
:
'
keyword
'
},
'
redirect_uri
'
:
{
'
type
'
:
'
keyword
'
},
'
token_endpoint
'
:
{
'
type
'
:
'
keyword
'
},
...
...
@@ -208,7 +205,7 @@ snapshots['test_init_alias 1'] = {
'
client_secret
'
:
{
'
type
'
:
'
keyword
'
},
'
is
S
hortcut
'
:
{
'
is
_s
hortcut
'
:
{
'
type
'
:
'
boolean
'
},
'
issuer
'
:
{
...
...
@@ -217,9 +214,6 @@ snapshots['test_init_alias 1'] = {
'
name_x
'
:
{
'
type
'
:
'
keyword
'
},
'
redirect_uri
'
:
{
'
type
'
:
'
keyword
'
},
'
token_endpoint
'
:
{
'
type
'
:
'
keyword
'
},
...
...
@@ -336,7 +330,7 @@ snapshots['test_reindex__check_new_index 1'] = {
'
client_secret
'
:
{
'
type
'
:
'
keyword
'
},
'
is
S
hortcut
'
:
{
'
is
_s
hortcut
'
:
{
'
type
'
:
'
boolean
'
},
'
issuer
'
:
{
...
...
@@ -345,9 +339,6 @@ snapshots['test_reindex__check_new_index 1'] = {
'
name_x
'
:
{
'
type
'
:
'
keyword
'
},
'
redirect_uri
'
:
{
'
type
'
:
'
keyword
'
},
'
token_endpoint
'
:
{
'
type
'
:
'
keyword
'
},
...
...
@@ -464,7 +455,7 @@ snapshots['test_init_documents 1'] = {
'
client_secret
'
:
{
'
type
'
:
'
keyword
'
},
'
is
S
hortcut
'
:
{
'
is
_s
hortcut
'
:
{
'
type
'
:
'
boolean
'
},
'
issuer
'
:
{
...
...
@@ -473,9 +464,6 @@ snapshots['test_init_documents 1'] = {
'
name_x
'
:
{
'
type
'
:
'
keyword
'
},
'
redirect_uri
'
:
{
'
type
'
:
'
keyword
'
},
'
token_endpoint
'
:
{
'
type
'
:
'
keyword
'
},
...
...
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