Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
test-it
test_oauth2_django
Commits
0fb2d27b
Commit
0fb2d27b
authored
Nov 06, 2017
by
Sharad Heft
Browse files
Refactor some of the profile retrieval code.
parent
8b5c4705
Changes
2
Hide whitespace changes
Inline
Side-by-side
test_oauth/backend.py
View file @
0fb2d27b
...
...
@@ -6,16 +6,19 @@ from django.db import transaction
from
test_oauth.models
import
TESTOAuth2Data
,
Character
from
test_oauth.session
import
TESTOAuth2Session
class
TESTOAuth2Backend
(
ModelBackend
):
def
authenticate
(
self
,
token
=
None
,
id
=
None
,
username
=
None
,
**
profile
):
if
id
is
None
or
username
is
None
or
token
is
None
:
def
authenticate
(
self
,
token
=
None
,
**
kwargs
):
if
token
is
None
:
return
None
profile
=
TESTOAuth2Session
(
token
=
token
).
profile
user
,
_
=
get_user_model
().
objects
.
get_or_create
(
pk
=
id
,
username
=
username
pk
=
profile
[
'id'
]
,
username
=
profile
[
'
username
'
]
)
data
,
_
=
TESTOAuth2Data
.
objects
.
update_or_create
(
...
...
test_oauth/views.py
View file @
0fb2d27b
...
...
@@ -29,8 +29,6 @@ def callback(request):
.
fetch_token
(
code
=
request
.
GET
[
'code'
])
)
session
=
TESTOAuth2Session
(
token
=
token
)
auth
.
login
(
request
,
auth
.
authenticate
(
token
=
token
,
**
session
.
profile
))
auth
.
login
(
request
,
auth
.
authenticate
(
token
=
token
))
return
redirect
(
getattr
(
settings
,
'TEST_OAUTH_REDIRECT'
,
'/'
))
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