Exemplo n.º 1
0
def auth_return(request):
    if not xsrfutil.validate_token(settings.SECRET_KEY, request.REQUEST['state'], None):
        return  HttpResponseBadRequest()
    try:
        credentials = get_flow().step2_exchange(request.REQUEST)
        Storage().put(credentials)
        messages.success(request, u'Asociada cuenta de publicación')
    except Error:
        messages.error(request, u'Autorización no concedida')
    return HttpResponseRedirect(reverse("config_plugin"))
Exemplo n.º 2
0
def auth_manage(request, revoke = False):
    credentials = Storage().get()
    if revoke:
        try:
            credentials.revoke(httplib2.Http())
        except Error:
            messages.error(request, u'No pudo ser revocado el permiso en el servidor de Google')
            Storage().delete()
        messages.warning(request, u'Eliminada cuenta de publicación')
    else:
        if credentials is None or credentials.invalid:
            flow = get_flow()
            flow.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY, None)
            authorize_url = flow.step1_get_authorize_url()
            return HttpResponseRedirect(authorize_url)

    return HttpResponseRedirect(reverse("config_plugin"))