Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGNIN_V2 #68

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws_okta_processor/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.9.1'
__version__ = '1.10.0'
47 changes: 45 additions & 2 deletions aws_okta_processor/core/saml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import sys
from fnmatch import fnmatch

Expand Down Expand Up @@ -95,15 +96,24 @@ def get_aws_roles(saml_assertion=None, accounts_filter=None, sign_in_url=None):


def get_account_roles(saml_assertion=None, sign_in_url=None):
role_accounts = []

data = {
"SAMLResponse": saml_assertion,
"RelayState": ""
}

response = requests.post(sign_in_url or AWS_SIGN_IN_URL, data=data)
soup = BeautifulSoup(response.text, "html.parser")

field_set = soup.find('fieldset')

if field_set:
return get_account_roles_v1(soup=soup)
else:
return get_account_roles_v2(soup=soup)


def get_account_roles_v1(soup: BeautifulSoup):
role_accounts = []
accounts = soup.find('fieldset').find_all(
"div",
attrs={"class": "saml-account"},
Expand Down Expand Up @@ -135,6 +145,39 @@ def get_account_roles(saml_assertion=None, sign_in_url=None):
return role_accounts


def get_account_roles_v2(soup: BeautifulSoup):
role_accounts = []

accounts = (
soup.find(name="ul", attrs={"class": re.compile(r'saml-form_custom_list__.*')})
.find_all(name="li", attrs={"class": re.compile(r'saml-form_custom_list_item__.*')}, recursive=False)
)

for account in accounts:
account_name = account.find(
name="div",
attrs={"class": re.compile(r'saml-form_account_name_div__.*')}
).string

roles = account.find(
name="div",
attrs={"class": re.compile(r'saml-form_account_role_div__.*')}).find_all(
name="div",
attrs={"class": re.compile(r'saml-form_role_div__.*')}
)

for role in roles:
role_arn = role.a['id']
role_description = role.a.string
role_accounts.append(AWSRole(
account_name=f"Account: {account_name}",
role_description=role_description,
role_arn=role_arn
))

return role_accounts


class AWSRole:
def __init__(
self,
Expand Down
File renamed without changes.
Loading