def METHOD_NAME(request):
    state = get_random_string(STATE_LENGTH)
    request.session[SESSION_STATE] = state
    quote = {
        "response_type": "code",
        "client_id": request.settings.oauth2_client_id,
        "redirect_uri": get_redirect_uri(request),
        "scope": request.settings.oauth2_scopes,
        "state": state,
    }
    return "%s?%s" % (request.settings.oauth2_login_url, urlencode(quote))