Skip to content

Commit 400eb0b

Browse files
committed
Release Version 11.3.0
Release Version 11.3.0
1 parent 2453487 commit 400eb0b

File tree

8 files changed

+177
-47
lines changed

8 files changed

+177
-47
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# LoginRadius Python SDK Change Log
22

33

4+
5+
6+
# Version 11.3.0
7+
8+
## Enhancements
9+
10+
- Added a feature to add ApiKey and ApiSecret directly in LoginRadius manual SOTT generation method.
11+
- Code optimization for better performance.
12+
- Added Licence and Contribution Guideline files.
13+
14+
## Breaking Changes
15+
16+
For developers migrating from v11.2.0, there will be 1 minor breaking change in terms of SDK implementation. In this version, we have added a feature to add ApiKey & ApiSecret directly into the manual SOTT generation method `get_sott()`.
17+
418
# Version 11.2.0
519

620
## Enhancements

CONTRIBUTING.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Contributing
2+
3+
[PYTHON SDK](https://github.com/LoginRadius/python-sdk) is [MIT](LICENSE) licensed and accepts contributions via GitHub pull requests. This document outlines some of the conventions on development workflow, commit message formatting, contact points, and other resources to make it easier to get your contribution accepted.
4+
5+
## Getting Started
6+
7+
- Fork the repository on GitHub.
8+
- If you find any bug or Improvement in our existing code-base, please create a pull request as mentioned in Contribution Flow.
9+
10+
## Contribution Flow
11+
12+
This is a rough outline of what a contributor's workflow looks like:
13+
14+
- Create a separate branch from the `dev` branch to base your work.
15+
- Make commits of logical units.
16+
- Make sure your commit messages are in the proper format (see below).
17+
- Push your changes to a topic branch in your fork of the repository.
18+
- Submit a pull request to the original repository.
19+
- **Please ensure that you raise a PR on the `dev` branch instead of `master`.**
20+
21+
#### Commit Messages
22+
23+
Please follow the below format while writing commit messages:
24+
25+
```
26+
title: One line description about your change
27+
<Blank Line>
28+
description: An optional description of your changes.
29+
```
30+
31+
Thanks for your contributions!
32+
33+
## Code of Conduct
34+
35+
### Our Pledge
36+
37+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
38+
39+
### Our Responsibilities
40+
41+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

LICENCE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2022 LoginRadius Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ You will need at least Python - 2.7 or greater. LoginRadius module utilizes the
2929
Using pip
3030

3131
```
32-
pip install loginradius-v2==11.2.0
32+
pip install loginradius-v2==11.3.0
3333
```
3434

3535
or with easy_install
3636

3737
```
38-
easy_install loginradius-v2==11.2.0
38+
easy_install loginradius-v2==11.3.0
3939
```
4040

4141
### Install From Source
@@ -4250,6 +4250,29 @@ else:
42504250
```
42514251

42524252
<br>
4253+
4254+
### Generate SOTT Manually
4255+
4256+
SOTT is a secure one-time token that can be created using the API key, API secret, and a timestamp ( start time and end time ). You can manually create a SOTT using the following utility function.
4257+
4258+
4259+
```
4260+
timeDifference='10' #(Optional) The time difference will be used to set the expiration time of SOTT, If you do not pass time difference then the default expiration time of SOTT is 10 minutes.
4261+
4262+
getLRserverTime=False #(Optional) If True it will call LoginRadius Get Server Time Api and fetch basic server information and server time information which is useful when generating an SOTT token.
4263+
4264+
# The LoginRadius API key and primary API secret can be passed additionally, If the credentials will not be passed then this SOTT function will pick the API credentials from the SDK configuration.
4265+
4266+
4267+
apiKey="" #(Optional) LoginRadius Api Key.
4268+
4269+
apiSecret = "" # (Optional) LoginRadius Api Secret (Only Primary Api Secret is used to generate the SOTT manually).
4270+
4271+
sott_data = loginradius.get_sott(timeDifference, getLRserverTime,apiKey,apiSecret)
4272+
4273+
print(sott_data)
4274+
```
4275+
42534276
## Demo
42544277
We have a demo web application using the Python SDK, which includes the following features:
42554278

demo/LoginRadius/__init__.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
__copyright__ = "Copyright 2019, LoginRadius"
2121
__email__ = "[email protected]"
2222
__status__ = "Production"
23-
__version__ = "11.2.0"
23+
__version__ = "11.3.0"
2424

2525
import json
2626
import sys
@@ -219,7 +219,8 @@ def get_digest(self, expiry_time, url, payload=None):
219219
if sys.version_info[0] >= 3:
220220
key_bytes = bytes(self.get_api_secret(), 'latin-1')
221221
data_bytes = bytes(signing_str, 'latin-1')
222-
dig = hmac.new(key_bytes, msg=data_bytes, digestmod=hashlib.sha256).digest()
222+
dig = hmac.new(key_bytes, msg=data_bytes,
223+
digestmod=hashlib.sha256).digest()
223224
if sys.version_info[0] >= 3:
224225
return base64.b64encode(dig).decode("utf-8")
225226
return base64.b64encode(dig)
@@ -243,7 +244,8 @@ def execute(self, method, resource_url, query_params, payload):
243244
'Accept-encoding': 'gzip'}
244245

245246
if "access_token" in query_params and "/auth" in resource_url:
246-
headers.update({"Authorization": "Bearer " + query_params['access_token']})
247+
headers.update({"Authorization": "Bearer " +
248+
query_params['access_token']})
247249
query_params.pop("access_token")
248250

249251
if "sott" in query_params:
@@ -306,7 +308,7 @@ def _get_json(self, url, payload, HEADERS):
306308
http = urllib3.ProxyManager(proxies['https'])
307309
else:
308310
http = urllib3.PoolManager()
309-
311+
310312
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
311313
r = http.request('GET', url, fields=payload, headers=HEADERS)
312314
if(r.status == 429):
@@ -354,7 +356,8 @@ def get_api_secret(self):
354356

355357
def _get_proxy(self):
356358
if self.IS_PROXY_ENABLE:
357-
proxies = {'https': 'https://' + self.USER_NAME + ':' + self.PASSWORD + '@' + self.HOST + ':' + self.PORT}
359+
proxies = {'https': 'https://' + self.USER_NAME + ':' +
360+
self.PASSWORD + '@' + self.HOST + ':' + self.PORT}
358361
else:
359362
proxies = {}
360363
return proxies
@@ -387,40 +390,49 @@ def is_null_or_whitespace(self, value):
387390
def get_validation_message(self, field):
388391
return "Invalid value for field " + str(field)
389392

390-
def get_sott(self, time='10', getLRserverTime=False):
391-
if getLRserverTime:
392-
result = self.configuration.get_server_info()
393+
#
394+
# Function to generate SOTT manually
395+
#
396+
def get_sott(self, timeDifference='', getLRserverTime=False, apiKey="", apiSecret=""):
397+
398+
time = '10'
399+
secret = self.API_SECRET
400+
key = self.API_KEY
401+
402+
if(not self.is_null_or_whitespace(timeDifference)):
403+
time = timeDifference
404+
405+
if(not self.is_null_or_whitespace(apiSecret)):
406+
secret = apiSecret
393407

408+
if(not self.is_null_or_whitespace(apiKey)):
409+
key = apiKey
410+
411+
now = datetime.utcnow()
412+
now = now - timedelta(minutes=0)
413+
now_plus_10m = now + timedelta(minutes=int(time))
414+
now = now.strftime("%Y/%m/%d %I:%M:%S")
415+
now_plus_10m = now_plus_10m.strftime("%Y/%m/%d %I:%M:%S")
416+
417+
if getLRserverTime:
418+
result = self.configuration.get_server_info(time)
394419
if result.get('Sott') is not None:
395420
Sott = result.get('Sott')
396421
for timeKey, val in Sott.items():
397422
if timeKey == 'StartTime':
398423
now = val
399424
if timeKey == 'EndTime':
400425
now_plus_10m = val
401-
else:
402-
now = datetime.utcnow()
403-
now = now - timedelta(minutes=5)
404-
now_plus_10m = now + timedelta(minutes=10)
405-
now = now.strftime("%Y/%m/%d %I:%M:%S")
406-
now_plus_10m = now_plus_10m.strftime("%Y/%m/%d %I:%M:%S")
407-
408-
else:
409-
now = datetime.utcnow()
410-
now = now - timedelta(minutes=5)
411-
now_plus_10m = now + timedelta(minutes=10)
412-
now = now.strftime("%Y/%m/%d %I:%M:%S")
413-
now_plus_10m = now_plus_10m.strftime("%Y/%m/%d %I:%M:%S")
414426

415-
plaintext = now + "#" + self.API_KEY + "#" + now_plus_10m
427+
plaintext = now + "#" + key + "#" + now_plus_10m
416428
padding = 16 - (len(plaintext) % 16)
417429
if sys.version_info[0] == 3:
418430
plaintext += (bytes([padding]) * padding).decode()
419431
else:
420432
plaintext += (chr(padding) * padding).decode()
421433

422434
salt = "\0\0\0\0\0\0\0\0"
423-
cipher_key = PBKDF2(self.API_SECRET,
435+
cipher_key = PBKDF2(secret,
424436
salt, 10000).read(self.CONST_KEYSIZE // 8)
425437

426438
if sys.version_info[0] == 3:

lib/LoginRadius/__init__.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
__copyright__ = "Copyright 2019, LoginRadius"
2121
__email__ = "[email protected]"
2222
__status__ = "Production"
23-
__version__ = "11.2.0"
23+
__version__ = "11.3.0"
2424

2525
import json
2626
import sys
@@ -387,40 +387,49 @@ def is_null_or_whitespace(self, value):
387387
def get_validation_message(self, field):
388388
return "Invalid value for field " + str(field)
389389

390-
def get_sott(self, time='10', getLRserverTime=False):
391-
if getLRserverTime:
392-
result = self.configuration.get_server_info()
390+
#
391+
# Function to generate SOTT manually
392+
#
393+
def get_sott(self, timeDifference='', getLRserverTime=False, apiKey="", apiSecret=""):
394+
395+
time = '10'
396+
secret = self.API_SECRET
397+
key = self.API_KEY
398+
399+
if(not self.is_null_or_whitespace(timeDifference)):
400+
time = timeDifference
401+
402+
if(not self.is_null_or_whitespace(apiSecret)):
403+
secret = apiSecret
404+
405+
if(not self.is_null_or_whitespace(apiKey)):
406+
key = apiKey
393407

408+
now = datetime.utcnow()
409+
now = now - timedelta(minutes=0)
410+
now_plus_10m = now + timedelta(minutes=int(time))
411+
now = now.strftime("%Y/%m/%d %I:%M:%S")
412+
now_plus_10m = now_plus_10m.strftime("%Y/%m/%d %I:%M:%S")
413+
414+
if getLRserverTime:
415+
result = self.configuration.get_server_info(time)
394416
if result.get('Sott') is not None:
395417
Sott = result.get('Sott')
396418
for timeKey, val in Sott.items():
397419
if timeKey == 'StartTime':
398420
now = val
399421
if timeKey == 'EndTime':
400422
now_plus_10m = val
401-
else:
402-
now = datetime.utcnow()
403-
now = now - timedelta(minutes=5)
404-
now_plus_10m = now + timedelta(minutes=10)
405-
now = now.strftime("%Y/%m/%d %I:%M:%S")
406-
now_plus_10m = now_plus_10m.strftime("%Y/%m/%d %I:%M:%S")
407-
408-
else:
409-
now = datetime.utcnow()
410-
now = now - timedelta(minutes=5)
411-
now_plus_10m = now + timedelta(minutes=10)
412-
now = now.strftime("%Y/%m/%d %I:%M:%S")
413-
now_plus_10m = now_plus_10m.strftime("%Y/%m/%d %I:%M:%S")
414423

415-
plaintext = now + "#" + self.API_KEY + "#" + now_plus_10m
424+
plaintext = now + "#" + key + "#" + now_plus_10m
416425
padding = 16 - (len(plaintext) % 16)
417426
if sys.version_info[0] == 3:
418427
plaintext += (bytes([padding]) * padding).decode()
419428
else:
420429
plaintext += (chr(padding) * padding).decode()
421430

422431
salt = "\0\0\0\0\0\0\0\0"
423-
cipher_key = PBKDF2(self.API_SECRET,
432+
cipher_key = PBKDF2(secret,
424433
salt, 10000).read(self.CONST_KEYSIZE // 8)
425434

426435
if sys.version_info[0] == 3:

lib/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,30 @@ From Package
2121
Using pip
2222

2323
```
24-
pip install loginradius-v2==11.2.0
24+
pip install loginradius-v2==11.3.0
2525
```
2626

2727
or with easy_install
2828

2929
```
30-
easy_install loginradius-v2==11.2.0
30+
easy_install loginradius-v2==11.3.0
3131
```
3232

3333
Changelog
3434
======
3535

36+
11.3.0
37+
-----------
38+
Release on **January 31, 2022**
39+
## Enhancements
40+
41+
- Added a feature to add ApiKey and ApiSecret directly in LoginRadius manual SOTT generation method.
42+
- Code optimization for better performance.
43+
- Added Licence and Contribution Guideline files.
44+
45+
## Breaking Changes
46+
47+
For developers migrating from v11.2.0, there will be 1 minor breaking change in terms of SDK implementation. In this version, we have added a feature to add ApiKey & ApiSecret directly into the manual SOTT generation method `get_sott()`.
3648

3749
11.2.0
3850
-----------

lib/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setuptools.setup(
1010
name = 'LoginRadius-v2',
11-
version='11.2.0',
11+
version='11.3.0',
1212
long_description=long_description,
1313
long_description_content_type='text/markdown',
1414
packages=setuptools.find_packages(),

0 commit comments

Comments
 (0)