Esempio n. 1
0
    def get(self, request):
        """
        This function initializes the authentication process 
        It builds a challenge which is sent to the client
        """

        # Creates a new nonce associated to this session
        nonce = Nonce()
        nonce.save()

        # Gets the callback uri
        callback_uri = self.get_callback_uri(request)

        # Builds the challenge (bitid uri)
        bitid_uri = bitid.build_uri(callback_uri, nonce.nid)

        # Gets the qrcode uri
        qrcode = bitid.qrcode(bitid_uri)

        context = {
            "callback_uri": callback_uri,
            "bitid_uri": bitid_uri,
            "qrcode": qrcode
        }

        return render(request, self.template_name, context)
Esempio n. 2
0
    def get(self, request):
        """
        This function initializes the authentication process 
        It builds a challenge which is sent to the client
        """

        # Creates a new nonce associated to this session

        sid = request.session._get_or_create_session_key()

        nonce = Nonce(sid=sid)
        nonce.save()

        # Gets the callback uri
        callback_uri = self.get_callback_uri(request)

        # Builds the challenge (bitid uri) 
        bitid_uri = bitid.build_uri(callback_uri, nonce.nid)

        # Gets the qrcode uri
        qrcode = bitid.qrcode(bitid_uri)

        context = {
            "callback_uri": callback_uri,
            "bitid_uri": bitid_uri,
            "qrcode": qrcode
        }

        return render(request, self.template_name, context)
Esempio n. 3
0
def login():
    '''
    This function initializes the authentication process 
    It builds a challenge which is sent to the client
    '''
    # Initializes a new session id and stores it in the session cookie
    # If user was authenticated, it will be similar to a log out
    session["sid"] = str(uuid.uuid4())
    session["uid"] = None
    # Creates a new nonce associated to this session
    nonce = Nonce(session["sid"])
    # Stores the nonce in database
    nonce_db_service.create_nonce(nonce)
    # Gets the callback uri
    callback_uri = get_callback_uri()
    # Builds the challenge (bitid uri)
    bitid_uri = bitid.build_uri(callback_uri, nonce.nid)
    # Gets the qrcode uri
    qrcode = bitid.qrcode(bitid_uri)
    # Renders the login page
    params_tpl = {
        "callback_uri": callback_uri,
        "bitid_uri": bitid_uri,
        "qrcode": qrcode
    }
    return render_template('login.html', params_tpl=params_tpl)
def prepare_bitid_challenge(callback_uri):
    # Creates a new nonce associated to this session
    nonce = Nonce(session["sid"])
    nonce.uid = session.get("uid", None)
    # Stores the nonce in database
    nonce_db_service.create_nonce(nonce)
    # Builds the challenge (bitid uri) 
    bitid_uri = bitid.build_uri(callback_uri, nonce.nid)
    # Gets the qrcode uri
    qrcode = bitid.qrcode(bitid_uri)
    # Returns a dictionary storing data related to the challenge
    return {"callback_uri": callback_uri, "bitid_uri": bitid_uri, "qrcode": qrcode}
Esempio n. 5
0
    def post(self, request):
        """
        This function validates the response sent by the client about the challenge
        This is the route called by the bitcoin wallet when the challenge has been signed
        """

        # Retrieves the callback uri
        callback_uri = self.get_callback_uri(request)

        # Extracts data from the posted request
        try:
            data = json.loads(request.body)
            bitid_uri = data.get("uri")
            signature = data.get("signature")
            address = data.get("address")
        except Exception:
            bitid_uri = request.POST.get("uri")
            signature = request.POST.get("signature")
            address = request.POST.get("address")

        logger.info('bitid_uri=%s' % bitid_uri)
        logger.info('callback_uri=%s' % self.get_callback_uri(request))
        logger.info('signature=%s' % signature)
        logger.info('address=%s' % address)

        errors = []

        user = authenticate(bitid_uri=bitid_uri,
                            callback_uri=callback_uri,
                            signature=signature,
                            address=address,
                            errors=errors)

        if user is not None:
            logger.info('is_auth?=%s' % user.is_authenticated())
            user.save()
            #login(request, user)
            #return render(request, self.template_name, {'user': user })
            return HttpResponseRedirect(reverse('djbitid_challenge'))
        else:
            form = BitIdForm(request.POST)
            form.full_clean()
            for error in errors:
                form._errors[NON_FIELD_ERRORS] = form.error_class([error])
            #return HttpResponseRedirect(reverse('djbitid_challenge'))
            #return HttpResponseRedirect(reverse('login'))
            #return HttpResponseRedirect(reverse('djbitid_challenge'))
            qrcode = bitid.qrcode(bitid_uri)
            return render(request, self.template_name, {
                'form': form,
                'bitid_uri': bitid_uri,
                'qrcode': qrcode
            })
def prepare_bitid_challenge(callback_uri):
    # Creates a new nonce associated to this session
    nonce = Nonce(session["sid"])
    nonce.uid = session.get("uid", None)
    # Stores the nonce in database
    nonce_db_service.create_nonce(nonce)
    # Builds the challenge (bitid uri)
    bitid_uri = bitid.build_uri(callback_uri, nonce.nid)
    # Gets the qrcode uri
    qrcode = bitid.qrcode(bitid_uri)
    # Returns a dictionary storing data related to the challenge
    return {
        "callback_uri": callback_uri,
        "bitid_uri": bitid_uri,
        "qrcode": qrcode
    }
Esempio n. 7
0
    def post(self, request):
        """
        This function validates the response sent by the client about the challenge
        This is the route called by the bitcoin wallet when the challenge has been signed
        """

        # Retrieves the callback uri
        callback_uri = self.get_callback_uri(request)
        
        # Extracts data from the posted request
        try:
            data = json.loads(request.body)                                         
            bitid_uri = data.get("uri")
            signature = data.get("signature")                                       
            address   = data.get("address")                                         
        except Exception:
            bitid_uri = request.POST.get("uri")
            signature = request.POST.get("signature")                               
            address   = request.POST.get("address")    

        logger.info('bitid_uri=%s' % bitid_uri)
        logger.info('callback_uri=%s' % self.get_callback_uri(request))
        logger.info('signature=%s' % signature)
        logger.info('address=%s' % address)

        errors = []

        user = authenticate(bitid_uri=bitid_uri, callback_uri=callback_uri,
                            signature=signature, address=address, errors=errors)

        if user is not None:
            logger.info('is_auth?=%s' % user.is_authenticated())
            user.save()
            #login(request, user)
            #return render(request, self.template_name, {'user': user })
            return HttpResponseRedirect(reverse('djbitid_challenge'))
        else:
            form = BitIdForm(request.POST)
            form.full_clean()
            for error in errors:
                form._errors[NON_FIELD_ERRORS] = form.error_class([error])
            #return HttpResponseRedirect(reverse('djbitid_challenge'))
            #return HttpResponseRedirect(reverse('login'))
            #return HttpResponseRedirect(reverse('djbitid_challenge'))
            qrcode = bitid.qrcode(bitid_uri)
            return render(request, self.template_name, {'form': form, 'bitid_uri': bitid_uri, 'qrcode': qrcode })
Esempio n. 8
0
def login():
    '''
    This function initializes the authentication process 
    It builds a challenge which is sent to the client
    '''
    # Initializes a new session id and stores it in the session cookie
    # If user was authenticated, it will be similar to a log out
    session["sid"]  = str(uuid.uuid4())
    session["uid"] = None
    # Creates a new nonce associated to this session
    nonce = Nonce(session["sid"])
    # Stores the nonce in database
    nonce_db_service.create_nonce(nonce)
    # Gets the callback uri
    callback_uri = get_callback_uri()
    # Builds the challenge (bitid uri) 
    bitid_uri = bitid.build_uri(callback_uri, nonce.nid)
    # Gets the qrcode uri
    qrcode = bitid.qrcode(bitid_uri)
    # Renders the login page
    params_tpl = {"callback_uri": callback_uri, "bitid_uri": bitid_uri, "qrcode": qrcode}
    return render_template('login.html', params_tpl=params_tpl)
Esempio n. 9
0
 def test_build_qrcode(self):
     qrcode = bitid.qrcode(BITID_URI)
     check_qrcode = QRCODE_BASE_URI + quote(BITID_URI)
     self.assertEqual(check_qrcode, qrcode)
Esempio n. 10
0
 def test_build_qrcode(self):
     qrcode = bitid.qrcode(BITID_URI)
     check_qrcode = QRCODE_BASE_URI + quote(BITID_URI)
     self.assertEqual(check_qrcode, qrcode)