Convert SSO to Enhanced SSO

This guide will show how to convert a standard SSO extension to an Enhanced SSO.

Let’s say you named your extension to MyExtension.

Here is the package you should import on top of your extension.py file:

from q2_sdk.core.http_handlers.tecton_server_handler import Q2TectonServerRequestHandler

And extends from Q2TectonServerRequestHandler

class MyExtension(Q2TectonServerRequestHandler):

And add below lines before __init__ constructor.

CONFIG_FILE_NAME = "MyExtension"
TECTON_URL = "https://cdn1.onlineaccess1.com/cdn/base/tecton/v1.62.0/q2-tecton-sdk.js"

Check the latest Tecton version here: https://tecton.q2developer.com/releases

Add router method:

@property
def router(self):
    router = super().router
    router.update(
        {
            "default": self.default,
            "submit": self.submit,
        }
    )
    return router

Replace default method with this (Note: that 4 commented lines if you use SAML payload)

Look at the commented lines carefully as well if you use SAML payload:

async def default(self):
    # replace destination_url with your actual site url
    destination_url = 'https://MY-OWN-DESTINATION-URL'
    template = self.get_template(
        "index.html.jinja2", {"destination_url": destination_url}
    )

    # If your web application requires a SAML payload to login. Please read through our SSO Guide to understand how you can construct a SAML payload.
    # You can then use the get_saml_payload method to construct your SAML payload and pass it to the template. https://docs.q2developer.com/guides/ssos/sso.html
    # saml_payload = await self.get_saml_payload()
    # template = self.get_template('saml_post.html.jinja2', {'saml_response': saml_payload.response, 'url': saml_payload.url})

    html = self.get_tecton_form(
        "MyExtension",
        custom_template=template,
        routing_key="submit",
        hide_submit_button=True,
    )
    return html

Add submit method:

async def submit(self):
    template = self.get_template(
        "submit.html.jinja2",
        {
            "header": "MyExtension",
            "message": 'Hello World POST: From "MyExtension".<br>',
            "data": self.form_fields,
        },
    )

    html = self.get_tecton_form(
        "MyExtension",
        custom_template=template,
        hide_submit_button=True,
    )

    return html

Add get_saml_payload method if you use SAML payload:

async def get_saml_payload(self):
    """
    This method is used to build the SAML payload and URL for the SSO.
    """
    return {
        'response': None,
        'url': None
    }

Add this saml_post.html.jinja2 file if you use SAML payload:

<form method="post" action="{{url}}">
    <input type="hidden"
        name="SAMLResponse"
        value="{{saml_response}}" />

    <input type="hidden"
        name="RelayState"
        id="RelayState"
        value="{{relay_state}}" />
</form>

<script>
    const win = window.opener || window.parent;
    if (win) {
        const queryString = win.location.search;
        const params = new URLSearchParams(queryString);
        const q = params.get("RelayState");
        if (q) {
            document.querySelector('#RelayState').value = q;
        }
    }
    window.onload = function () { document.forms[0].submit(); }
</script>

Otherwise include this in your index.html.jinja2 file if you just want to redirect:

<script>
    window.location = "{{destination_url}}";
</script>