Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
411d39de
Commit
411d39de
authored
Dec 13, 2013
by
Chris Rossi
Committed by
Diana Huang
Jan 16, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Script to log in to LinkedIn API.
parent
b2db05fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
lms/djangoapps/linkedin/management/commands/login.py
+72
-0
lms/djangoapps/linkedin/models.py
+9
-0
No files found.
lms/djangoapps/linkedin/management/commands/login.py
0 → 100644
View file @
411d39de
"""
Log into LinkedIn API.
"""
import
json
import
urllib2
import
urlparse
import
uuid
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
,
CommandError
from
...models
import
LinkedInTokens
class
Command
(
BaseCommand
):
"""
Can take a sysadmin through steps to log into LinkedIn API so that the
findusers script can work.
"""
args
=
''
help
=
(
'Takes a user through the steps to log in to LinkedIn as a user '
'with API access in order to gain an access token for use by the '
'findusers script.'
)
def
handle
(
self
,
*
args
,
**
options
):
"""
"""
api
=
getattr
(
settings
,
"LINKEDIN_API"
,
None
)
if
not
api
:
raise
CommandError
(
"LINKEDIN_API is not configured"
)
state
=
str
(
uuid
.
uuid4
())
url
=
(
"https://www.linkedin.com/uas/oauth2/authorization"
"?response_type=code"
"&client_id=
%
s&state=
%
s&redirect_uri=
%
s"
%
(
api
[
'CLIENT_ID'
],
state
,
api
[
'REDIRECT_URI'
]))
print
"Let's log into your LinkedIn account."
print
"Start by visiting this url:"
print
url
print
print
"Within 30 seconds of logging in, enter the full URL of the "
print
"webpage you were redirected to: "
redirect
=
raw_input
()
query
=
urlparse
.
parse_qs
(
urlparse
.
urlparse
(
redirect
)
.
query
)
assert
query
[
'state'
][
0
]
==
state
,
(
query
[
'state'
][
0
],
state
)
code
=
query
[
'code'
][
0
]
url
=
(
"https://www.linkedin.com/uas/oauth2/accessToken"
"?grant_type=authorization_code"
"&code=
%
s&redirect_uri=
%
s&client_id=
%
s&client_secret=
%
s"
%
(
code
,
api
[
'REDIRECT_URI'
],
api
[
'CLIENT_ID'
],
api
[
'CLIENT_SECRET'
]))
try
:
response
=
urllib2
.
urlopen
(
url
)
.
read
()
except
urllib2
.
HTTPError
,
e
:
print
"!!ERROR!!"
print
e
print
e
.
read
()
raise
CommandError
(
"Unable to retrieve access token"
)
access_token
=
json
.
loads
(
response
)[
'access_token'
]
try
:
tokens
=
LinkedInTokens
.
objects
.
get
()
tokens
.
access_token
=
access_token
tokens
.
authorization_code
=
code
except
LinkedInTokens
.
DoesNotExist
:
tokens
=
LinkedInTokens
(
access_token
=
access_token
,
authorization_code
=
code
)
tokens
.
save
()
lms/djangoapps/linkedin/models.py
View file @
411d39de
...
...
@@ -12,3 +12,12 @@ class LinkedIn(models.Model):
user
=
models
.
OneToOneField
(
User
,
primary_key
=
True
)
has_linkedin_account
=
models
.
NullBooleanField
(
default
=
None
)
emailed_courses
=
models
.
TextField
(
default
=
"[]"
)
# JSON list of course ids
class
LinkedInTokens
(
models
.
Model
):
"""
For storing access token and authorization code after logging in to
LinkedIn.
"""
access_token
=
models
.
CharField
(
max_length
=
255
)
authorization_code
=
models
.
CharField
(
max_length
=
255
)
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