Exemplo n.º 1
0
def custom_scheme_redirect(url_redirect):
    # urlparse.urlsplit doesn't currently handle custom schemes,
    # which we want our callback URLs to support so mobile apps can register
    # their own callback scheme handlers.
    # See http://bugs.python.org/issue9374
    # and http://stackoverflow.com/questions/1417958/parse-custom-uris-with-urlparse-python

    scheme = urlparse.urlsplit(url_redirect)[0]

    scheme_lists = [
        urlparse.uses_netloc, urlparse.uses_query, urlparse.uses_fragment,
        urlparse.uses_params, urlparse.uses_relative
    ]
    scheme_lists_modified = []

    # Modify urlparse's internal scheme lists so it properly handles
    # custom schemes
    if scheme:
        for scheme_list in scheme_lists:
            if scheme not in scheme_list:
                scheme_list.append(scheme)
                scheme_lists_modified.append(scheme_list)

    # Clear cache before re-parsing url_redirect
    urlparse.clear_cache()

    # Grab flask/werkzeug redirect result
    redirect_result = redirect(url_redirect)

    # Restore previous urlparse scheme list
    for scheme_list in scheme_lists_modified:
        scheme_list.remove(scheme)

    return redirect_result
def facebook_request_token_handler(oauth_map):
    # Start Facebook request token process
    params = {
        "client_id": App.facebook_app_id,
        "redirect_uri": get_facebook_token_callback_url(oauth_map),
        "scope": "email",
    }

    if oauth_map.is_mobile_view():
        # Add FB-specific mobile view identifier
        params["display"] = "touch"

    return redirect("%s?%s" % (FB_URL_OAUTH_DIALOG, urllib.urlencode(params)))
Exemplo n.º 3
0
def facebook_request_token_handler(oauth_map):
    # Start Facebook request token process
    params = {
        "client_id": App.facebook_app_id,
        "redirect_uri": get_facebook_token_callback_url(oauth_map),
        "scope": "email",
    }

    if oauth_map.is_mobile_view():
        # Add FB-specific mobile view identifier
        params["display"] = "touch"

    return redirect("%s?%s" % (FB_URL_OAUTH_DIALOG, urllib.urlencode(params)))
Exemplo n.º 4
0
def authorize_token_redirect(oauth_map, force_http=False):
    if not oauth_map:
        raise OAuthError("Missing oauth_map while returning " "authorize_token_redirect")

    if not oauth_map.callback_url:
        raise OAuthError("Missing callback URL during " "authorize_token_redirect")

    params = {
        "oauth_token": oauth_map.request_token,
        "oauth_token_secret": oauth_map.request_token_secret,
        "oauth_callback": oauth_map.callback_url_with_request_token_params(),
    }
    url = "/api/auth/authorize"
    if force_http:
        url = url_util.insecure_url(url)
    return redirect(append_url_params(url, params))
Exemplo n.º 5
0
def authorize_token_redirect(oauth_map, force_http=False):
    if not oauth_map:
        raise OAuthError("Missing oauth_map while returning "
                         "authorize_token_redirect")

    if not oauth_map.callback_url:
        raise OAuthError("Missing callback URL during "
                         "authorize_token_redirect")

    params = {
        "oauth_token": oauth_map.request_token,
        "oauth_token_secret": oauth_map.request_token_secret,
        "oauth_callback": oauth_map.callback_url_with_request_token_params(),
    }
    url = "/api/auth/authorize"
    if force_http:
        url = url_util.insecure_url(url)
    return redirect(append_url_params(url, params))
Exemplo n.º 6
0
def custom_scheme_redirect(url_redirect):
    # urlparse.urlsplit doesn't currently handle custom schemes,
    # which we want our callback URLs to support so mobile apps can register
    # their own callback scheme handlers.
    # See http://bugs.python.org/issue9374
    # and http://stackoverflow.com/questions/1417958/parse-custom-uris-with-urlparse-python

    scheme = urlparse.urlsplit(url_redirect)[0]

    scheme_lists = [
        urlparse.uses_netloc,
        urlparse.uses_query,
        urlparse.uses_fragment,
        urlparse.uses_params,
        urlparse.uses_relative,
    ]
    scheme_lists_modified = []

    # Modify urlparse's internal scheme lists so it properly handles
    # custom schemes
    if scheme:
        for scheme_list in scheme_lists:
            if scheme not in scheme_list:
                scheme_list.append(scheme)
                scheme_lists_modified.append(scheme_list)

    # Clear cache before re-parsing url_redirect
    urlparse.clear_cache()

    # Grab flask/werkzeug redirect result
    redirect_result = redirect(url_redirect)

    # Restore previous urlparse scheme list
    for scheme_list in scheme_lists_modified:
        scheme_list.remove(scheme)

    return redirect_result
Exemplo n.º 7
0
def token_to_session():
    set_current_oauth_map_in_session()
    return redirect(request.request_continue_url())
Exemplo n.º 8
0
    oauth_map.request_token = token.key_
    oauth_map.callback_url = requested_oauth_callback()

    if request.values.get("view") == "mobile":
        oauth_map.view = "mobile"

    oauth_map.put()

    chooser_url = ("/login/mobileoauth?oauth_map_id=%s&view=%s" %
                   (oauth_map.key().id(), oauth_map.view))

    oauth_consumer = oauth_server._get_consumer(oauth_request)
    if oauth_consumer and oauth_consumer.anointed:
        chooser_url += "&an=1"

    return redirect(chooser_url)


@route("/api/auth/request_token_callback/<provider>/<oauth_map_id>",
       methods=["GET"])
@decorators.manual_access_checking
def request_token_callback(provider, oauth_map_id):

    oauth_map = OAuthMap.get_by_id_safe(oauth_map_id)
    if not oauth_map:
        return oauth_error_response(
            OAuthError("Unable to find OAuthMap by id during request token "
                       "callback."))

    if provider == "google":
        return google_request_token_handler(oauth_map)
Exemplo n.º 9
0
def token_to_session():
    set_current_oauth_map_in_session()
    return redirect(request.request_continue_url())
Exemplo n.º 10
0
    oauth_map.request_token = token.key_
    oauth_map.callback_url = requested_oauth_callback()

    if request.values.get("view") == "mobile":
        oauth_map.view = "mobile"

    oauth_map.put()

    chooser_url = ("/login/mobileoauth?oauth_map_id=%s&view=%s" %
                   (oauth_map.key().id(), oauth_map.view))

    oauth_consumer = oauth_server._get_consumer(oauth_request)
    if oauth_consumer and oauth_consumer.anointed:
        chooser_url += "&an=1"

    return redirect(chooser_url)


@route("/api/auth/request_token_callback/<provider>/<oauth_map_id>",
       methods=["GET"])
@decorators.manual_access_checking
def request_token_callback(provider, oauth_map_id):

    oauth_map = OAuthMap.get_by_id_safe(oauth_map_id)
    if not oauth_map:
        return oauth_error_response(
            OAuthError("Unable to find OAuthMap by id during request token "
                       "callback."))

    if provider == "google":
        return google_request_token_handler(oauth_map)
Exemplo n.º 11
0
    try:
        google_client = GoogleOAuthClient()
        google_token = google_client.fetch_request_token(oauth_map)
    except Exception, e:
        return oauth_error_response(OAuthError(e.message))

    oauth_map.google_request_token = google_token.key
    oauth_map.google_request_token_secret = google_token.secret
    oauth_map.put()

    params = {"oauth_token": oauth_map.google_request_token}
    if oauth_map.is_mobile_view():
        # Add google-specific mobile view identifier
        params["btmpl"] = "mobile"

    return redirect("http://www.iktel.nl/_ah/OAuthAuthorizeToken?%s" %
                    urllib.urlencode(params))


def retrieve_google_access_token(oauth_map):
    # Start Google access token process
    import logging
    logging.error("import access token")
    google_client = GoogleOAuthClient()
    logging.error("import access token")
    google_token = google_client.fetch_access_token(oauth_map)

    logging.error("1")
    oauth_map.google_access_token = google_token.key
    logging.error(google_token.key)
    logging.error("2")
    oauth_map.google_access_token_secret = google_token.secret
Exemplo n.º 12
0
    try:
        google_client = GoogleOAuthClient()
        google_token = google_client.fetch_request_token(oauth_map)
    except Exception, e:
        return oauth_error_response(OAuthError(e.message))

    oauth_map.google_request_token = google_token.key
    oauth_map.google_request_token_secret = google_token.secret
    oauth_map.put()

    params = {"oauth_token": oauth_map.google_request_token}
    if oauth_map.is_mobile_view():
        # Add google-specific mobile view identifier
        params["btmpl"] = "mobile"

    return redirect("http://www.khanacademy.org/_ah/OAuthAuthorizeToken?%s" %
                    urllib.urlencode(params))


def retrieve_google_access_token(oauth_map):
    # Start Google access token process
    google_client = GoogleOAuthClient()
    google_token = google_client.fetch_access_token(oauth_map)

    oauth_map.google_access_token = google_token.key
    oauth_map.google_access_token_secret = google_token.secret

    return oauth_map


@route("/api/auth/google_token_callback", methods=["GET"])
@decorators.manual_access_checking