Skip to content

Instantly share code, notes, and snippets.

@almet
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almet/b27e18c382156a639c0d to your computer and use it in GitHub Desktop.
Save almet/b27e18c382156a639c0d to your computer and use it in GitHub Desktop.
whats-hawk-how-to-use-it
credentials = {
'id': keyMaterial[0:32],
'key': keyMaterial[32:64],
'algorithm': 'sha256'
}
var express = require("express");
var hawk = require("express-hawkauth");
app = express();
var hawkMiddleware = hawk.getMiddleware({
hawkOptions: {},
getSession: function(tokenId, cb) {
// A function which pass to the cb the key and algorithm for the
// given token id. First argument of the callback is a potential
// error.
cb(null, {key: "key", algorithm: "sha256"});
},
createSession: function(id, key, cb) {
// A function which stores a session for the given id and key.
// Argument returned is a potential error.
cb(null);
},
setUser: function(req, res, tokenId, cb) {
// A function that uses req and res, the hawkId when they're known so
// that it can tweak it. For instance, you can store the tokenId as the
// user.
req.user = tokenId;
}
});
app.get("/hawk-enabled-endpoint", hawkMiddleware);
from pyramid_hawkauth import HawkAuthenticationPolicy
policy = HawkAuthenticationPolicy(decode_hawk_id=get_hawk_id)
config.set_authentication_policy(authn_policy)
hawk_auth = HawkAuth(
hawk_session=resp.headers['hawk-session-token'],
server_url=self.server_url
)
requests.post("/url", auth=hawk_auth)
import requests
from requests_hawk import HawkAuth
hawk_auth = HawkAuth(
credentials={'id': id, 'key': key, 'algorithm': 'sha256'})
requests.post("/url", auth=hawk_auth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment