-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import aep.applicationportal.authentication.login as login_py | ||
import aep.applicationportal.authentication.logout as logout_py | ||
import aep.applicationportal.authentication.getTokenInformation as getTokenInformation_py | ||
|
||
import aep.applicationportal.usersandorganization.chooseOrganization as chooseOrganization_py | ||
|
||
def applicationPortalGeneral(accessKey, secretKey, orgId, url): | ||
|
||
accessToken = login_py.login(accessKey, secretKey, url) | ||
chooseOrganization_py.chooseOrganization(accessKey, secretKey, orgId, url, accessToken) | ||
# logout_py.logout(accessKey, secretKey, url, accessToken) | ||
|
||
# getTokenInformation_py.getTokenInformation(accessKey, secretKey, url, accessToken) | ||
|
||
|
26 changes: 26 additions & 0 deletions
26
aep/applicationportal/authentication/getTokenInformation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
* Copyright (C), 2015-2021, Envision | ||
* FileName: getTokenInformation | ||
* Author: Dylan Yeo | ||
* Date: 16/03/22 | ||
* Description: Get information about the user who is currently logged-in through the access token. | ||
* <author> <time> <version> <desc> | ||
* | ||
* https://support.envisioniot.com/docs/app-portal-api/en/2.3.0/authentication/get_token_information.html | ||
""" | ||
|
||
import poseidon.poseidon | ||
from requests.models import PreparedRequest | ||
|
||
def getTokenInformation(accessKey, secretKey, url, accessToken): | ||
accessURL = url + "/app-portal-service/v2.1/session/info" | ||
params = {} | ||
req = PreparedRequest() | ||
req.prepare_url(accessURL, params) | ||
print(req.url) | ||
|
||
header = {"Authorization": accessToken} | ||
|
||
response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, headers=header) | ||
print(response) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
* Copyright (C), 2015-2021, Envision | ||
* FileName: login | ||
* Author: Dylan Yeo | ||
* Date: 16/03/22 | ||
* Description: Log in to the account | ||
* <author> <time> <version> <desc> | ||
* | ||
* https://support.envisioniot.com/docs/app-portal-api/en/2.3.0/authentication/login.html | ||
""" | ||
|
||
import poseidon.poseidon | ||
from requests.models import PreparedRequest | ||
|
||
def login(accessKey, secretKey, url): | ||
accessURL = url + "/app-portal-service/v2.2/login" | ||
params = {} | ||
req = PreparedRequest() | ||
req.prepare_url(accessURL, params) | ||
print(req.url) | ||
|
||
body = {"account": "songxibin2013", | ||
"password": "Password1" | ||
} | ||
print(body) | ||
|
||
response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body) | ||
print(response) | ||
|
||
try: | ||
accessToken = response["data"]["accessToken"] | ||
except: | ||
accessToken = None | ||
return accessToken | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
* Copyright (C), 2015-2021, Envision | ||
* FileName: logout | ||
* Author: Dylan Yeo | ||
* Date: 16/03/22 | ||
* Description: Log out of the account | ||
* <author> <time> <version> <desc> | ||
* | ||
* https://support.envisioniot.com/docs/app-portal-api/en/2.3.0/authentication/logout.html | ||
""" | ||
|
||
import poseidon.poseidon | ||
from requests.models import PreparedRequest | ||
|
||
def logout(accessKey, secretKey, url, accessToken): | ||
accessURL = url + "/app-portal-service/v2.0/logout" | ||
params = {} | ||
req = PreparedRequest() | ||
req.prepare_url(accessURL, params) | ||
print(req.url) | ||
|
||
header= {"Authorization": accessToken} | ||
|
||
response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, headers=header) | ||
print(response) |
35 changes: 35 additions & 0 deletions
35
aep/applicationportal/authentication/refreshAccessToken.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
* Copyright (C), 2015-2021, Envision | ||
* FileName: refreshAccessToken | ||
* Author: Dylan Yeo | ||
* Date: 16/03/22 | ||
* Description: Request a new access token using the refresh token | ||
* <author> <time> <version> <desc> | ||
* | ||
* https://support.envisioniot.com/docs/app-portal-api/en/2.3.0/authentication/refresh_access_token.html | ||
""" | ||
|
||
import poseidon.poseidon | ||
from requests.models import PreparedRequest | ||
|
||
def refreshAccessToken(accessKey, secretKey, url): | ||
accessURL = url + "/app-portal-service/v2.0/login" | ||
params = {"refreshToken": ""} | ||
req = PreparedRequest() | ||
req.prepare_url(accessURL, params) | ||
print(req.url) | ||
|
||
body={"account": "songxibin2013", | ||
"password": "Password1" | ||
} | ||
print(body) | ||
|
||
response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body) | ||
print(response) | ||
|
||
try: | ||
accessToken = response["data"]["accessToken"] | ||
except: | ||
accessToken = None | ||
return accessToken | ||
|
31 changes: 31 additions & 0 deletions
31
aep/applicationportal/usersandorganization/chooseOrganization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
* Copyright (C), 2015-2021, Envision | ||
* FileName: chooseOrganization | ||
* Author: Dylan Yeo | ||
* Date: 16/03/22 | ||
* Description: Select the organization that the user needs to use after login | ||
* <author> <time> <version> <desc> | ||
* | ||
* https://support.envisioniot.com/docs/app-portal-api/en/2.3.0/user_and_ou/choose_organization | ||
""" | ||
|
||
import poseidon.poseidon | ||
from requests.models import PreparedRequest | ||
|
||
def chooseOrganization(accessKey, secretKey, orgId, url, accessToken): | ||
accessURL = url + "/app-portal-service/v2.2/session/set" | ||
params = {} | ||
req = PreparedRequest() | ||
req.prepare_url(accessURL, params) | ||
print(req.url) | ||
|
||
headers = {'Authorization': 'Bearer '+ accessToken} | ||
print(headers) | ||
|
||
body = {'orgId': orgId} | ||
print(body) | ||
|
||
response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body, headers=headers, method='POST') | ||
print(response) | ||
|
||
|