Coder Social home page Coder Social logo

flask-hmacauth's People

Contributors

fitblip avatar singulared avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flask-hmacauth's Issues

Client code should specify hashlib.sha1

Hi,

Thanks for the library. I think this line

signature=hmac.new(api_key, msg=query).hexdigest()

in the client example should be instead

signature=hmac.new(api_key, msg=query,digestmod=hashlib.sha1).hexdigest()

since by default the digestmod of hmac is not sha1.

Thanks!
Marco

Use or operator in hmac_auth()

Hello,
How can i use or operator in condition hmac_auth(['role1','role2']) or something like that?
I want to have an ability to check if user included in one of this roles.
is it possible?
Thank you.

Client demo code can't pass digest check

The client code should be like this (because the default digestmod of hmac.new is hashlib.md5):

import requests
import time
import hashlib

path_and_query = "/api/v1/create?TIMESTAMP="+str(int(time.time()))+"&ACCOUNT_ID=admin&foo=bar"
host = "https://example.com"
sig=hmac.new(";hi^897t7utf", digestmod=hashlib.sha1, msg=path_and_query).hexdigest()
req = requests.get(host+path_and_query, headers={'X-Auth-Signature': sig})

fix GET parameters encoding & POST parameters reading

Under my testing, 'request' object do not have 'body' attribute in Flask 0.10, so, please consider the following patch, thanks~

--- a/flask_hmacauth.py
+++ b/flask_hmacauth.py
@@ -92,11 +92,16 @@ class HmacManager(object):

         #hash the request URL and Body
         hasher = hmac.new(secret, digestmod=self._digest)
-        #TODO: do we need encode() here?
-        url = urlparse.urlparse(request.url.encode())
+        charset = request.charset or 'utf-8'
+        url = urlparse.urlparse(request.url.encode(charset)) # For URL Query parameter
         hasher.update(url.path + "?" + url.query)
         if request.method == "POST":
-            hasher.update(request.body)
+            body = ''
+            if request.form: # For Form input
+                body = '&'.join(('='.join((key, value.encode(charset))) for key, value in request.form.items()))
+            if request.data: # For data type application/json
+                body = request.data
+            hasher.update(body)
         calculated_hash = hasher.hexdigest()

         try:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.