Last active
October 26, 2023 13:30
-
-
Save lordzuko/9f3df89ecc0200e66f1e28c1366192ac to your computer and use it in GitHub Desktop.
Automating login using BeautifulSoup & Requests module in python over SSO Raw
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
{ | |
"ssousername":"example@oracle.com", | |
"password":"put your password here" | |
} |
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
import sys | |
import requests | |
import json | |
from bs4 import BeautifulSoup | |
def mprint(x): | |
sys.stdout.write(x) | |
return | |
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'} | |
mprint('[-] Initialization...') | |
s = requests.session() | |
s.headers.update(headers) | |
print 'done' | |
mprint('[-] Gathering JSESSIONID..') | |
# This should redirect us to the login page | |
# On looking at the page source we can find that | |
# in the submit form 6 values are submitted (at least at the time of this script) | |
# try to take those values out using beautiful soup | |
# and then do a post request. On doing post https://login.oracle.com/mysso/signon.jsp | |
# we will be given message we have the data which is more than necessary | |
# then it will take us to the form where we have to submit data here | |
# https://login.oracle.com/oam/server/sso/auth_cred_submit | |
# once done we are signed in and doing and requests.get(url) will get you the page you want. | |
r = s.get("company's local url- a link which requires authentication") | |
if r.status_code != requests.codes.ok: | |
print 'error' | |
exit(1) | |
print 'done' | |
c = r.content | |
soup = BeautifulSoup(c,'lxml') | |
svars = {} | |
for var in soup.findAll('input',type="hidden"): | |
svars[var['name']] = var['value'] | |
s = requests.session() | |
r = s.post('https://login.oracle.com/mysso/signon.jsp', data=svars) | |
mprint('[-] Trying to submit credentials...') | |
inputRaw = open('credentials.json','r') | |
login = json.load(inputRaw) | |
data = { | |
'v': svars['v'], | |
'OAM_REQ': svars['OAM_REQ'], | |
'site2pstoretoken': svars['site2pstoretoken'], | |
'locale': svars['locale'], | |
'ssousername': login['ssousername'], | |
'password': login['password'], | |
} | |
r = s.post('https://login.oracle.com/oam/server/sso/auth_cred_submit', data=data) | |
r = s.get("company's local url- a link which requires authentication") | |
# dumping the html page to html file | |
with open('test.html','w') as f: | |
f.write(r.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i was able to fix it finally using the ADF Faces param
org.apache.myfaces.trinidad.agent.email=true
which enables you to output your page in a simplified mode either for printing or for emailing which is more convenient when scraping the site. anyone having the same issue, checkout https://docs.oracle.com/middleware/1213/adf/develop-faces/adf-faces-outputmodes.htm