-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from nathan-v/Feature_additional_factor_support
Support more MFA
- Loading branch information
Showing
7 changed files
with
571 additions
and
108 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
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
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
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
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,65 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Credits: Portions of this code were copied/modified from | ||
# https://github.com/ThoughtWorksInc/oktaauth | ||
# | ||
# Copyright (c) 2015, Peter Gillard-Moss | ||
# All rights reserved. | ||
|
||
# Permission to use, copy, modify, and/or distribute this software for any | ||
# purpose with or without fee is hereby granted, provided that the above | ||
# copyright notice and this permission notice appear in all copies. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
"""This contains all of the Okta SML specific code.""" | ||
from __future__ import unicode_literals | ||
import base64 | ||
import logging | ||
|
||
import bs4 | ||
import requests | ||
|
||
from aws_okta_keyman import okta | ||
|
||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class OktaSaml(okta.Okta): | ||
"""Handle the SAML part of talking to Okta.""" | ||
|
||
def assertion(self, saml): | ||
"""Parse the assertion from the SAML response.""" | ||
assertion = '' | ||
soup = bs4.BeautifulSoup(saml, 'html.parser') | ||
for inputtag in soup.find_all('input'): | ||
if inputtag.get('name') == 'SAMLResponse': | ||
assertion = inputtag.get('value') | ||
return base64.b64decode(assertion) | ||
|
||
def get_assertion(self, appid, apptype): | ||
"""Call Okta and get the assertion.""" | ||
path = '{url}/home/{apptype}/{appid}'.format( | ||
url=self.base_url, apptype=apptype, appid=appid) | ||
resp = self.session.get(path, | ||
params={'onetimetoken': self.session_token}) | ||
LOG.debug(resp.__dict__) | ||
|
||
try: | ||
resp.raise_for_status() | ||
except (requests.exceptions.HTTPError, | ||
requests.exceptions.ConnectionError) as err: | ||
if err.response.status_code == 404: | ||
LOG.fatal("Provided App ID {} not found".format(appid)) | ||
else: | ||
LOG.error('Unknown error: {msg}'.format( | ||
msg=str(err.response.__dict__))) | ||
raise okta.UnknownError() | ||
|
||
return self.assertion(resp.text) |
Oops, something went wrong.