LaunchKey Flask

LaunchKey-Flask on GitHub.

For using LaunchKey authentication with the Flask Microframework.


LaunchKey-Flask uses Flask-Login for user session management together with LaunchKey's Python SDK to provide authentication for Flask applications.


$ easy_install launchkey-flask


$ pip install launchkey-flask


Initial Configuration

from flask.ext.launchkey import LaunchKeyManager, login_required

app = Flask(__name__)
# Note that you must configure a Flask secret key for secure sessions
app.config['SECRET_KEY'] = "thisismyextasecretkey"
# LaunchKey Configuration keys
app.config['LAUNCHKEY_APP_KEY'] = 1234567890
app.config['LAUNCHKEY_SECRET_KEY'] = "abcdefghijklmnopqrstuvwxyz123456"
app.config['LAUNCHKEY_PRIVATE_KEY_PATH'] = "/path/to/private_key.key"

# LaunchKey Config
launchkey = LaunchKeyManager(app)
# Redirect view for private pages
launchkey.login_view = "/login"

Login Required Views

def user_page():
    return render_template('user.html')

You simply need to use the login_required decorator in front of any private pages.

Using LaunchKey Authentication

A series of callback URLs are required for the different authentication steps.

Initial authorize step to initiate the process.

@app.route('/_authorize', methods=['POST'])
def auth_user():
    # Retrieve form input
    username = request.form['username']
    # Generate an auth request
    auth_response = launchkey.authorize(username)
    # Return results
    return jsonify({'response': auth_response})

Polling to see if the user has responded to an auth request.

@app.route('/_poll', methods=['GET'])
def response_poll():
    # Check for a user response to auth request
    poll_response = launchkey.poll_request()
    # Return results
    return jsonify({'response': poll_response })

Once the user has launched, verify that they are authorized. Then log them in.

@app.route('/_isauthorized', methods=['GET'])
def is_authorized():
    # Check if the user is authorized
    is_authorized = launchkey.is_authorized()
    if is_authorized:
        # User has been authorized, so log them in
    # Return results
    return jsonify({'response': is_authorized })

Logging the user out. This will end the LaunchKey session as well as the Flask-Login session.

@app.route('/_deauth', methods=['GET'])
def deauth_user():
    # Logout user from both LaunchKey as well as Flask-Login
    success = launchkey.logout()
    return jsonify({'response': success})


$ python test

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at ×