Created
September 15, 2016 05:55
-
-
Save zamzterz/da7605a82c7392912c0b175185684342 to your computer and use it in GitHub Desktop.
Second factor authentication as a micro service for SATOSA
This file contains hidden or 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
from satosa.exception import SATOSAAuthenticationError | |
from satosa.internal_data import InternalResponse | |
from satosa.micro_services.base import ResponseMicroService | |
from satosa.response import Response | |
STATE_KEY = "2fa" | |
class SecondFactorAuth(ResponseMicroService): | |
def process(self, context, internal_response): | |
context.state[STATE_KEY] = internal_response.to_dict() | |
return Response(""" | |
<html><body><form action="/2fa/confirm"> | |
<input type="text" name="code"> | |
<button type="submit">Submit</button> | |
</form> | |
</body></html>""") | |
def confirm(self, context): | |
if context.request["code"] != "1234": | |
raise SATOSAAuthenticationError(context.state, "Second factor auth failed") | |
saved_state = context.state[STATE_KEY] | |
internal_response = InternalResponse.from_dict(saved_state) | |
return super().process(context, internal_response) | |
def register_endpoints(self): | |
return [("^2fa/confirm$", self.confirm)] |
This file contains hidden or 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
module: 2fa.SecondFactorAuth | |
name: SecondFactor |
This file contains hidden or 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
BASE: https://localhost:10000 | |
INTERNAL_ATTRIBUTES: "internal_attributes.yaml" | |
COOKIE_STATE_NAME: "SATOSA_STATE" | |
STATE_ENCRYPTION_KEY: "asdASD123" | |
USER_ID_HASH_SALT: "61a89d2db0b9e1e27d490d050b478fe71f352fddd3528a44157f43e339c6c62f2362fb413179937d96172bf84233317" | |
BACKEND_MODULES: | |
- "plugins/saml2_backend.yaml" | |
FRONTEND_MODULES: | |
- "plugins/saml2_frontend.yaml" | |
CUSTOM_PLUGIN_MODULE_PATHS: | |
- "<path to directory containing 2fa.py>" | |
MICRO_SERVICES: | |
- "plugins/2fa.yaml" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment