Ejemplo n.º 1
0
def set_client_credentials():
    session.clear()

    # Set the client credentials in the session
    # If this is a GET, the credentials in the form
    # will both be None, so we default to the credentials
    # set as environment variables
    set_client_credentials_in_session(
        request.form.get('client_id'),
        request.form.get('client_secret')
    )

    if request.form.get('base_url'):
        base_url = 'https://{}.inside-box.net/api/oauth2'.format(
            request.form.get('base_url')
        )
    else:
        base_url = None

    # Set the base_url in the session, if there was no base_url
    # in the form, we're ok because we only access the session
    # through dict.get()
    session['base_url'] = base_url

    redirect_uri = request.url_root + 'box_auth'

    # If we are on a local machine, we can't do https
    if '0.0.0.0:5000' not in redirect_uri:
        redirect_uri = redirect_uri.replace('http://', 'https://')

    box = BoxAuth(*get_client_credentials(), base_url=base_url)
    return redirect(box.get_authorization_url(
        redirect_uri=urllib.quote_plus(redirect_uri))
    )