Skip to content

Commit

Permalink
aep
Browse files Browse the repository at this point in the history
  • Loading branch information
xibin.song authored and JuziAha committed Apr 7, 2023
1 parent 318c5aa commit 7069591
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
15 changes: 15 additions & 0 deletions aep/applicationportal/applicationPortalApp.py
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 aep/applicationportal/authentication/getTokenInformation.py
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)

35 changes: 35 additions & 0 deletions aep/applicationportal/authentication/login.py
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

25 changes: 25 additions & 0 deletions aep/applicationportal/authentication/logout.py
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 aep/applicationportal/authentication/refreshAccessToken.py
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 aep/applicationportal/usersandorganization/chooseOrganization.py
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)


0 comments on commit 7069591

Please sign in to comment.