import os
from identiblok_authid import EnterpriseSSO, SQLiteStore

sso = EnterpriseSSO(
    origin=os.environ.get('AUTHID_ORIGIN', 'https://auth.identiblok.com'),
    application_id=os.environ['AUTHID_APPLICATION_ID'],
    organization_id=os.environ['AUTHID_ORGANIZATION_ID'],
    connection_id=os.environ['AUTHID_CONNECTION_ID'],
    client_id=os.environ['AUTHID_OIDC_CLIENT_ID'],
    client_secret=os.environ['AUTHID_OIDC_CLIENT_SECRET'],
    redirect_uri=os.environ['AUTHID_OIDC_REDIRECT_URI'],
    store=SQLiteStore(os.environ['AUTHID_STATE_DB']),
)

def begin_login(browser_binding):
    return sso.begin(browser_binding)

async def finish_login(callback_url, browser_binding):
    # Only create/rotate your own application session after this returns.
    # Store the scoped ID and all three scope IDs; never link by email.
    return await sso.complete(callback_url, browser_binding)
