Skip to content

Commit e882a14

Browse files
authored
Added support for PKCE auth and JWT auth (#48)
* Added support for PKCE auth and JWT auth * removed debug statement
1 parent 2125990 commit e882a14

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def get_config_parser():
1818
USERNAME = config.get('Credentials', 'USERNAME')
1919
EXTENSION = config.get('Credentials', 'EXTENSION')
2020
PASSWORD = config.get('Credentials', 'PASSWORD')
21+
JWT = config.get('Credentials', 'JWT')
2122
APP_KEY = config.get('Credentials', 'APP_KEY')
2223
APP_SECRET = config.get('Credentials', 'APP_SECRET')
2324
SERVER = config.get('Credentials', 'SERVER')
24-
MOBILE = config.get('Credentials', 'MOBILE')
25+
MOBILE = config.get('Credentials', 'MOBILE')

ringcentral/platform/platform.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# encoding: utf-8
33

44
import sys
5+
import urllib.parse
56
from observable import Observable
67
from functools import reduce
78
from .auth import Auth
@@ -13,6 +14,7 @@
1314
URL_PREFIX = '/restapi'
1415
TOKEN_ENDPOINT = '/restapi/oauth/token'
1516
REVOKE_ENDPOINT = '/restapi/oauth/revoke'
17+
AUTHORIZE_ENDPOINT = '/restapi/oauth/authorize'
1618
API_VERSION = 'v1.0'
1719
ACCESS_TOKEN_TTL = 3600 # 60 minutes
1820
REFRESH_TOKEN_TTL = 604800 # 1 week
@@ -76,12 +78,20 @@ def logged_in(self):
7678
except:
7779
return False
7880

79-
def login(self, username='', extension='', password='', code='', redirect_uri=''):
81+
def login_url(self, redirect_uri, state='', challenge='', challenge_method='S256'):
82+
built_url = self.create_url( AUTHORIZE_ENDPOINT, add_server=True )
83+
built_url += '?response_type=code&client_id=' + self._key + '&redirect_uri=' + urllib.parse.quote(redirect_uri)
84+
if state:
85+
built_url += '&state=' + urllib.parse.quote(state)
86+
if challenge:
87+
built_url += '&code_challenge=' + urllib.parse.quote(challenge) + '&code_challenge_method=' + challenge_method
88+
return built_url
89+
90+
def login(self, username='', extension='', password='', code='', redirect_uri='', jwt='', verifier=''):
8091
try:
81-
if not code and not username and not password:
82-
raise Exception('Either code or username with password has to be provided')
83-
84-
if not code:
92+
if not code and not username and not password and not jwt:
93+
raise Exception('Either code, or username with password, or jwt has to be provided')
94+
if not code and not jwt:
8595
body = {
8696
'grant_type': 'password',
8797
'username': username,
@@ -91,12 +101,19 @@ def login(self, username='', extension='', password='', code='', redirect_uri=''
91101
}
92102
if extension:
93103
body['extension'] = extension
104+
elif jwt:
105+
body = {
106+
'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
107+
'assertion': jwt
108+
}
94109
else:
95110
body = {
96111
'grant_type': 'authorization_code',
97112
'redirect_uri': redirect_uri if redirect_uri else self._redirect_uri,
98113
'code': code
99114
}
115+
if verifier:
116+
body['code_verifier'] = verifier
100117
response = self._request_token(TOKEN_ENDPOINT, body=body)
101118
self._auth.set_data(response.json_dict())
102119
self.trigger(Events.loginSuccess, response)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '0.7.11'
3+
VERSION = '0.7.12'
44

55
setup(
66
name='ringcentral',

0 commit comments

Comments
 (0)