def register():

    okta_util = OktaUtil(request.headers)

    first_name = request.form["firstName"]
    last_name = request.form["lastName"]
    email = request.form["email"]
    mobile = request.form["mobile"]
    password = request.form["password"]

    user_info = okta_util.create_user(first_name=first_name,
                                      last_name=last_name,
                                      email=email,
                                      phone=mobile,
                                      password=password)
    print user_info
    user_id = user_info["id"]

    # Authenticate
    auth_response = okta_util.authenticate(username=email, password=password)
    session[okta_util.OKTA_SESSION_TOKEN_KEY] = auth_response["sessionToken"]

    factor_response = okta_util.create_sms_factor(user_id=user_id, phone_number=mobile)
    activate_url = factor_response["_links"]["activate"]["href"]

    # Activate
    activate_response = okta_util.activate_sms_factor(url=activate_url)

    return json.dumps(activate_response)
def login():
    print "login()"

    okta_util = OktaUtil(request.headers)

    user = request.form["user"]
    pwd = request.form["password"]

    auth = okta_util.authenticate(username=user, password=pwd)

    try:
        session[okta_util.OKTA_SESSION_TOKEN_KEY] = auth["sessionToken"]
        user_id = auth["_embedded"]["user"]["id"]
        session_response = okta_util.create_session(session[okta_util.OKTA_SESSION_TOKEN_KEY])
        session[okta_util.OKTA_SESSION_ID_KEY] = session_response["id"]
    except:
        session[okta_util.OKTA_SESSION_TOKEN_KEY] = None
        user_id = None
        session_response = {"status":"FAILED", "message":"Authentication Failed"}

    return json.dumps(session_response)
def loginMFA():
    print "loginMFA()"

    okta_util = OktaUtil(request.headers)

    user = request.form["user"]
    pwd = request.form["password"]

    auth = okta_util.authenticate(username=user, password=pwd)
    try:
        session[okta_util.OKTA_SESSION_TOKEN_KEY] = auth["sessionToken"]
        user_id = auth["_embedded"]["user"]["id"]
        factors = okta_util.list_factors(user_id=user_id)
        factor_id = factors[0]["id"]
        push_factor_response = okta_util.push_factor_verification(user_id=user_id, factor_id=factor_id)
    except:
        session[okta_util.OKTA_SESSION_TOKEN_KEY] = None
        user_id = None
        push_factor_response = {"status":"FAILED", "message":"Authentication Failed"}

    return json.dumps(push_factor_response)