Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init_saml_auth(self):
r = RequestFactory()
request = r.get('/sso/saml/?provider=MyProvider', **dict(HTTP_HOST='example.com'))
req = prepare_django_request(request)
auth_obj = init_saml_auth(req)
self.assertTrue(type(auth_obj) is onelogin.saml2.auth.OneLogin_Saml2_Auth)
def _saml_login(self):
req = prepare_request_for_saml_toolkit(self.request)
auth = authenticate_saml(req, custom_base_path=Settings['saml_config_folder'])
return self.redirect(auth.login())
def _create_auth_object(self, db, idp_entity_id):
"""Creates and initializes an OneLogin_Saml2_Auth object
:param db: Database session
:type db: sqlalchemy.orm.session.Session
:param idp_entity_id: IdP's entityID
:type idp_entity_id: string
:return: OneLogin_Saml2_Auth object
:rtype: OneLogin_Saml2_Auth
"""
request_data = self._get_request_data()
settings = self._configuration.get_settings(db, idp_entity_id)
auth = OneLogin_Saml2_Auth(request_data, old_settings=settings)
return auth
def _create_saml_auth(self, idp):
"""Get an instance of OneLogin_Saml2_Auth"""
config = self.generate_saml_config(idp)
request_info = {
'https': 'on' if self.strategy.request_is_secure() else 'off',
'http_host': self.strategy.request_host(),
'script_name': self.strategy.request_path(),
'server_port': self.strategy.request_port(),
'get_data': self.strategy.request_get(),
'post_data': self.strategy.request_post(),
}
return OneLogin_Saml2_Auth(request_info, config)
def post(self):
if "onelogin" not in current_app.config.get("ACTIVE_PROVIDERS"):
return "Onelogin is not enabled in the config. See the ACTIVE_PROVIDERS section.", 404
auth = OneLogin_Saml2_Auth(self.req, current_app.config.get("ONELOGIN_SETTINGS"))
self.reqparse.add_argument('return_to', required=False, default=current_app.config.get('WEB_PATH'))
self.reqparse.add_argument('acs', required=False)
self.reqparse.add_argument('sls', required=False)
args = self.reqparse.parse_args()
return_to = args['return_to']
if args['acs'] != None:
# valids the SAML response and checks if successfully authenticated
if self._consumer(auth):
email = auth.get_attribute(current_app.config.get("ONELOGIN_EMAIL_FIELD"))[0]
user = User.query.filter(User.email == email).first()
# if we get an sso user create them an account
def _get_auth(request):
req = prepare_from_request(request)
auth = OneLogin_Saml2_Auth(req, _get_saml_settings())
return auth
def __init__(self):
if current_app.config['SAML_ENABLED']:
from onelogin.saml2.auth import OneLogin_Saml2_Auth
from onelogin.saml2.idp_metadata_parser import OneLogin_Saml2_IdPMetadataParser
self.idp_timestamp = datetime.now()
self.OneLogin_Saml2_Auth = OneLogin_Saml2_Auth
self.OneLogin_Saml2_IdPMetadataParser = OneLogin_Saml2_IdPMetadataParser
self.idp_data = None
if 'SAML_IDP_ENTITY_ID' in current_app.config:
self.idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(
current_app.config['SAML_METADATA_URL'],
entity_id=current_app.config.get('SAML_IDP_ENTITY_ID',
None),
required_sso_binding=current_app.
config['SAML_IDP_SSO_BINDING'])
else:
self.idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(
current_app.config['SAML_METADATA_URL'],
entity_id=current_app.config.get('SAML_IDP_ENTITY_ID',
None))
if self.idp_data is None:
def init_saml_auth():
parsed_url = urlparse(request.url)
request_data = {
"https": "on" if request.scheme == "https" else "off",
"http_host": request.host,
"server_port": parsed_url.port,
"script_name": request.path,
"get_data": request.args.copy(),
"post_data": request.form.copy(),
"query_string": request.query_string
}
auth = OneLogin_Saml2_Auth(request_data, custom_base_path=get_env("INFRABOX_ACCOUNT_SAML_SETTINGS_PATH"))
return auth
def init_saml_auth(req):
saml_auth = OneLogin_Saml2_Auth(
req,
custom_base_path=os.path.join(
os.path.dirname(os.path.dirname(__file__)), 'saml/config'))
return saml_auth