Skip to content

Commit 5800975

Browse files
author
Jack Zabolotnyi
committed
Allow user to define custom state for each authorization url
1 parent 5687111 commit 5800975

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ API_SECRET = 'daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG'
7171
RETURN_URL = 'http://localhost:8000'
7272

7373
authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values())
74+
# Optionally one can send custom "state" value that will be returned from OAuth server
75+
# It can be used to track your user state or something else (it's up to you)
76+
# Be aware that this value is sent to OAuth server AS IS - make sure to encode or hash it
77+
#authorization.state = 'your_encoded_message'
7478
print authentication.authorization_url # open this url on your browser
7579
application = linkedin.LinkedInApplication(authentication)
7680
```

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ LinkedIn redirects the user back to your website's URL after granting access (gi
3838
API_KEY = "wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl"
3939
API_SECRET = "daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG"
4040
RETURN_URL = "http://localhost:8000"
41+
# Optionally one can send custom "state" value that will be returned from OAuth server
42+
# It can be used to track your user state or something else (it's up to you)
43+
# Be aware that this value is sent to OAuth server AS IS - make sure to encode or hash it
44+
#authorization.state = 'your_encoded_message'
4145
authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values())
4246
print authentication.authorization_url
4347
application = linkedin.LinkedInApplication(authentication)

linkedin/linkedin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ def __init__(self, key, secret, redirect_uri, permissions=None):
8686

8787
@property
8888
def authorization_url(self):
89-
self.state = self._make_new_state()
9089
qd = {'response_type': 'code',
9190
'client_id': self.key,
9291
'scope': (' '.join(self.permissions)).strip(),
93-
'state': self.state,
92+
'state': self.state or self._make_new_state(),
9493
'redirect_uri': self.redirect_uri}
9594
# urlencode uses quote_plus when encoding the query string so,
9695
# we ought to be encoding the qs by on our own.

0 commit comments

Comments
 (0)