Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Hiboo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cyrinux
Hiboo
Commits
0da8888b
Commit
0da8888b
authored
5 years ago
by
kaiyou
Browse files
Options
Downloads
Patches
Plain Diff
Store authorization codes in database
parent
098f3828
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hiboo/sso/oidc.py
+15
-18
15 additions, 18 deletions
hiboo/sso/oidc.py
migrations/versions/5271f611b98b_.py
+36
-0
36 additions, 0 deletions
migrations/versions/5271f611b98b_.py
with
51 additions
and
18 deletions
hiboo/sso/oidc.py
+
15
−
18
View file @
0da8888b
...
@@ -10,10 +10,6 @@ from hiboo import models, utils, identity
...
@@ -10,10 +10,6 @@ from hiboo import models, utils, identity
import
flask
import
flask
AUTHORIZATION_CODES
=
{}
NONCES
=
{}
class
Config
(
object
):
class
Config
(
object
):
"""
Handles service configuration and forms.
"""
Handles service configuration and forms.
"""
"""
...
@@ -90,27 +86,26 @@ class AuthorizationCodeGrant(grants_oauth2.AuthorizationCodeGrant):
...
@@ -90,27 +86,26 @@ class AuthorizationCodeGrant(grants_oauth2.AuthorizationCodeGrant):
def
create_authorization_code
(
self
,
client
,
grant_user
,
request
):
def
create_authorization_code
(
self
,
client
,
grant_user
,
request
):
code
=
gen_salt
(
48
)
# TODO
code
=
gen_salt
(
48
)
# TODO
nonce
=
request
.
data
.
get
(
'
nonce
'
)
authorization_code
=
AuthorizationCode
(
item
=
AuthorizationCode
(
code
=
code
,
nonce
=
request
.
data
.
get
(
'
nonce
'
),
code
=
code
,
client_id
=
client
.
client_id
,
client_id
=
client
.
client_id
,
redirect_uri
=
request
.
redirect_uri
,
redirect_uri
=
request
.
redirect_uri
,
scope
=
request
.
scope
,
scope
=
request
.
scope
,
user_id
=
grant_user
.
uuid
,
user_id
=
grant_user
.
uuid
nonce
=
nonce
)
)
AUTHORIZATION_CODES
[
code
]
=
item
models
.
db
.
session
.
add
(
authorization_code
)
NONCES
[
nonce
]
=
item
models
.
db
.
session
.
commit
()
return
code
return
code
def
parse_authorization_code
(
self
,
code
,
client
):
def
parse_authorization_code
(
self
,
code
,
client
):
code
=
AUTHORIZATION_CODES
.
get
(
code
)
return
AuthorizationCode
.
query
.
filter_by
(
if
code
and
code
.
client_id
==
client
.
client_id
:
client_id
=
client
.
client_id
,
return
code
code
=
code
).
first
()
def
delete_authorization_code
(
self
,
authorization_code
):
def
delete_authorization_code
(
self
,
authorization_code
):
del
AUTHORIZATION_CODES
[
authorization_code
.
code
]
mo
del
s
.
db
.
session
.
delete
(
authorization_code
)
del
NONCES
[
authorization_code
.
nonce
]
mo
del
s
.
db
.
session
.
commit
()
def
authenticate_user
(
self
,
authorization_code
):
def
authenticate_user
(
self
,
authorization_code
):
profile
=
models
.
Identity
.
query
.
get
(
authorization_code
.
user_id
)
profile
=
models
.
Identity
.
query
.
get
(
authorization_code
.
user_id
)
...
@@ -120,6 +115,7 @@ class AuthorizationCodeGrant(grants_oauth2.AuthorizationCodeGrant):
...
@@ -120,6 +115,7 @@ class AuthorizationCodeGrant(grants_oauth2.AuthorizationCodeGrant):
class
AuthorizationCode
(
models
.
db
.
Model
,
models_oauth2
.
OIDCAuthorizationCodeMixin
):
class
AuthorizationCode
(
models
.
db
.
Model
,
models_oauth2
.
OIDCAuthorizationCodeMixin
):
"""
Authorization code object for storage
"""
Authorization code object for storage
"""
"""
__tablename__
=
"
oidc_authorization_code
"
user_id
=
models
.
db
.
Column
(
models
.
db
.
Text
())
user_id
=
models
.
db
.
Column
(
models
.
db
.
Text
())
...
@@ -129,8 +125,9 @@ class OpenIDCode(oidc.grants.OpenIDCode):
...
@@ -129,8 +125,9 @@ class OpenIDCode(oidc.grants.OpenIDCode):
"""
"""
def
exists_nonce
(
self
,
nonce
,
request
):
def
exists_nonce
(
self
,
nonce
,
request
):
nonce
=
NONCES
.
get
(
nonce
)
return
bool
(
AuthorizationCode
.
query
.
filter_by
(
return
nonce
and
nonce
[
"
client_id
"
]
==
request
.
client_id
nonce
=
nonce
,
client_id
=
request
.
client_id
).
first
()
)
def
get_jwt_config
(
self
,
grant
):
def
get_jwt_config
(
self
,
grant
):
return
{
# TODO
return
{
# TODO
...
...
This diff is collapsed.
Click to expand it.
migrations/versions/5271f611b98b_.py
0 → 100644
+
36
−
0
View file @
0da8888b
"""
Add authorization codes in the database
Revision ID: 5271f611b98b
Revises: cfb466a78348
Create Date: 2019-11-03 17:57:55.989647
"""
from
alembic
import
op
import
sqlalchemy
as
sa
revision
=
'
5271f611b98b
'
down_revision
=
'
cfb466a78348
'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
op
.
create_table
(
'
oidc_authorization_code
'
,
sa
.
Column
(
'
code
'
,
sa
.
String
(
length
=
120
),
nullable
=
False
),
sa
.
Column
(
'
client_id
'
,
sa
.
String
(
length
=
48
),
nullable
=
True
),
sa
.
Column
(
'
redirect_uri
'
,
sa
.
Text
(),
nullable
=
True
),
sa
.
Column
(
'
response_type
'
,
sa
.
Text
(),
nullable
=
True
),
sa
.
Column
(
'
scope
'
,
sa
.
Text
(),
nullable
=
True
),
sa
.
Column
(
'
auth_time
'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'
nonce
'
,
sa
.
Text
(),
nullable
=
True
),
sa
.
Column
(
'
user_id
'
,
sa
.
Text
(),
nullable
=
True
),
sa
.
Column
(
'
uuid
'
,
sa
.
String
(
length
=
36
),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
(),
nullable
=
False
),
sa
.
Column
(
'
updated_at
'
,
sa
.
DateTime
(),
nullable
=
True
),
sa
.
Column
(
'
comment
'
,
sa
.
String
(
length
=
255
),
nullable
=
True
),
sa
.
PrimaryKeyConstraint
(
'
uuid
'
),
sa
.
UniqueConstraint
(
'
code
'
)
)
def
downgrade
():
op
.
drop_table
(
'
oidc_authorization_code
'
)
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