Esempio n. 1
0
def captricity_login(request):
    # First check to see if user already granted access
    # If user already granted access, redirect to home page
    profile = request.user.get_profile()
    if profile.captricity_api_token != "":
        return HttpResponseRedirect(reverse("captricity_cloud_io.views.home"))

    # Otherwise start captricity login flow
    login_url = settings.API_TARGET + "accounts/request-access/"
    callback_url = (
        "http://" + Site.objects.get_current().domain + reverse("captricity_cloud_io.views.captricity_callback")
    )
    params = {"return-url": callback_url, "third-party-id": settings.CAPTRICITY_CLIENTID}
    params["signature"] = generate_request_access_signature(params, settings.CAPTRICITY_SECRET_KEY)
    login_url += "?" + urllib.urlencode(params)
    return HttpResponseRedirect(login_url)
Esempio n. 2
0
def captricity_callback(request):
    # First check signature
    signature_params = copy.copy(request.GET)
    del signature_params["signature"]
    if generate_request_access_signature(signature_params, settings.CAPTRICITY_SECRET_KEY) != request.GET["signature"]:
        # signature failed to verify, so do nothing (possible man in the middle attack)
        return render_to_response(
            "captricity_cloud_io/captricity_callback.html",
            {
                "redirect": reverse("captricity_cloud_io.views.home"),
                "alert_msg": "Signature failed to verify from " + settings.API_TARGET,
            },
            context_instance=RequestContext(request),
        )

    # If the request was denied, do nothing
    if "request-denied" in signature_params:
        return render_to_response(
            "captricity_cloud_io/captricity_callback.html",
            {
                "redirect": reverse("captricity_cloud_io.views.home"),
                "alert_msg": "You denied request for access to Captricity. Some features of this page will be unusable.",
            },
            context_instance=RequestContext(request),
        )

    # Otherwise update user profile with captricity api token and redirect user
    profile = request.user.get_profile()
    profile.captricity_api_token = request.GET["token"]
    profile.save()
    return render_to_response(
        "captricity_cloud_io/captricity_callback.html",
        {
            "redirect": reverse("captricity_cloud_io.views.home"),
            "alert_msg": "Request for access to Captricity was granted!",
        },
        context_instance=RequestContext(request),
    )
import urllib

from captools.api.util import generate_request_access_signature

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print 'You must specify a third party app client id and third party app client secret key to authorize the app access to a user\'s account'
        sys.exit(0)

    return_url = 'example.com'
    third_party_id = sys.argv[1]
    third_party_key = sys.argv[2]

    # Use a dictionary to make it easier to work with the query parameters
    params = {
        'return-url': return_url,
        'third-party-id': third_party_id,
    }

    # Generate the login url
    login_url = 'https://shreddr.captricity.com/accounts/request-access/'

    # Use captools.api.utils.generate_request_access_signature to generate the signature to pass on to the login url
    params['signature'] = generate_request_access_signature(
        params, third_party_key)

    # Finally, encode the parameters as a query string
    encoded_params = urllib.urlencode(params)

    print 'Request access url:', login_url + '?' + encoded_params
import sys
import urllib

from captools.api.util import generate_request_access_signature

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print 'You must specify a third party app client id and third party app client secret key to authorize the app access to a user\'s account'
        sys.exit(0)

    return_url = 'example.com'
    third_party_id = sys.argv[1]
    third_party_key = sys.argv[2]

    # Use a dictionary to make it easier to work with the query parameters
    params = {
            'return-url' : return_url,
            'third-party-id' : third_party_id,
    }

    # Generate the login url
    login_url = 'https://shreddr.captricity.com/accounts/request-access/'

    # Use captools.api.utils.generate_request_access_signature to generate the signature to pass on to the login url
    params['signature'] = generate_request_access_signature(params, third_party_key)

    # Finally, encode the parameters as a query string
    encoded_params = urllib.urlencode(params)

    print 'Request access url:', login_url + '?' + encoded_params