Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Helios 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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Helios Server
Commits
1aeec1c4
Commit
1aeec1c4
authored
9 years ago
by
Ben Adida
Browse files
Options
Downloads
Patches
Plain Diff
made login with clever work
parent
2b57d3c9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
helios_auth/auth_systems/clever.py
+33
-9
33 additions, 9 deletions
helios_auth/auth_systems/clever.py
helios_auth/media/login-icons/clever.png
+0
-0
0 additions, 0 deletions
helios_auth/media/login-icons/clever.png
with
33 additions
and
9 deletions
helios_auth/auth_systems/clever.py
+
33
−
9
View file @
1aeec1c4
...
...
@@ -7,11 +7,11 @@ from django.http import *
from
django.core.mail
import
send_mail
from
django.conf
import
settings
import
httplib2
,
json
import
httplib2
,
json
,
base64
import
sys
,
os
,
cgi
,
urllib
,
urllib2
,
re
from
oauth2client.client
import
OAuth2WebServerFlow
from
oauth2client.client
import
OAuth2WebServerFlow
,
OAuth2Credentials
# some parameters to indicate that status updating is not possible
STATUS_UPDATES
=
False
...
...
@@ -25,7 +25,8 @@ def get_flow(redirect_url=None):
client_secret
=
settings
.
CLEVER_CLIENT_SECRET
,
scope
=
'
read:students read:teachers read:user_id read:sis
'
,
auth_uri
=
"
https://clever.com/oauth/authorize
"
,
token_uri
=
"
https://clever.com/oauth/tokens
"
,
#token_uri="https://clever.com/oauth/tokens",
token_uri
=
"
http://requestb.in/1b18gwf1
"
,
redirect_uri
=
redirect_url
)
def
get_auth_url
(
request
,
redirect_url
):
...
...
@@ -35,25 +36,48 @@ def get_auth_url(request, redirect_url):
return
flow
.
step1_get_authorize_url
()
def
get_user_info_after_auth
(
request
):
flow
=
get_flow
(
request
.
session
[
'
clever-redirect-url
'
]
)
redirect_uri
=
request
.
session
[
'
clever-redirect-url
'
]
del
request
.
session
[
'
clever-redirect-url
'
]
flow
=
get_flow
(
redirect_uri
)
code
=
request
.
GET
[
'
code
'
]
credentials
=
flow
.
step2_exchange
(
code
)
# at this stage, just an access token
# do the POST manually, because OAuth2WebFlow can't do auth header for token exchange
http
=
httplib2
.
Http
(
"
.cache
"
)
auth_header
=
"
Basic %s
"
%
base64
.
b64encode
(
settings
.
CLEVER_CLIENT_ID
+
"
:
"
+
settings
.
CLEVER_CLIENT_SECRET
)
resp_headers
,
content
=
http
.
request
(
"
https://clever.com/oauth/tokens
"
,
"
POST
"
,
urllib
.
urlencode
({
"
code
"
:
code
,
"
grant_type
"
:
"
authorization_code
"
,
"
redirect_uri
"
:
redirect_uri
}),
headers
=
{
'
Authorization
'
:
auth_header
,
'
Content-Type
'
:
"
application/x-www-form-urlencoded
"
})
token_response
=
json
.
loads
(
content
)
access_token
=
token_response
[
'
access_token
'
]
# package the credentials
credentials
=
OAuth2Credentials
(
access_token
,
settings
.
CLEVER_CLIENT_ID
,
settings
.
CLEVER_CLIENT_SECRET
,
None
,
None
,
None
,
None
)
# get the nice name
http
=
httplib2
.
Http
(
"
.cache
"
)
http
=
credentials
.
authorize
(
http
)
(
resp_headers
,
content
)
=
http
.
request
(
"
https://api.clever.com/me
"
,
"
GET
"
)
# {"type":"student","data":{"id":"563395179f7408755c0006b7","district":"5633941748c07c0100000aac","type":"student","created":"2015-10-30T16:04:39.262Z","credentials":{"district_password":"eel7Thohd","district_username":"dianes10"},"dob":"1998-11-01T00:00:00.000Z","ell_status":"Y","email":"diane.s@example.org","gender":"F","grade":"9","hispanic_ethnicity":"Y","last_modified":"2015-10-30T16:04:39.274Z","location":{"zip":"11433"},"name":{"first":"Diane","last":"Schmeler","middle":"J"},"race":"Asian","school":"5633950c62fc41c041000005","sis_id":"738733110","state_id":"114327752","student_number":"738733110"},"links":[{"rel":"self","uri":"/me"},{"rel":"canonical","uri":"/v1.1/students/563395179f7408755c0006b7"},{"rel":"district","uri":"/v1.1/districts/5633941748c07c0100000aac"}]}
response
=
json
.
loads
(
content
)
user_id
=
response
[
'
data
'
][
'
id
'
]
user_name
=
"
%s %s
"
%
(
response
[
'
data
'
][
'
name
'
][
'
first
'
],
response
[
'
data
'
][
'
name
'
][
'
last
'
])
user_type
=
response
[
'
type
'
]
user_district
=
response
[
'
data
'
][
'
district
'
]
print
content
# watch out, response also contains email addresses, but not sure whether thsoe are verified or not
# so for email address we will only look at the id_token
return
{
'
type
'
:
'
clever
'
,
'
user_id
'
:
response
[
"
data
"
][
"
id
"
]
,
'
name
'
:
""
,
'
info
'
:
{
"
district
"
:
response
[
"
data
"
][
"
district
"
]
,
"
type
"
:
response
[
"
data
"
][
"
type
"
]
},
'
token
'
:
{
}}
return
{
'
type
'
:
'
clever
'
,
'
user_id
'
:
user_id
,
'
name
'
:
user_name
,
'
info
'
:
{
"
district
"
:
user_
district
,
"
type
"
:
user_
type
},
'
token
'
:
{
'
access_token
'
:
access_token
}}
def
do_logout
(
user
):
"""
...
...
This diff is collapsed.
Click to expand it.
helios_auth/media/login-icons/clever.png
0 → 100644
+
0
−
0
View file @
1aeec1c4
33.7 KiB
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