Last active
August 29, 2015 14:14
-
-
Save almet/b27e18c382156a639c0d to your computer and use it in GitHub Desktop.
whats-hawk-how-to-use-it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
credentials = { | |
'id': keyMaterial[0:32], | |
'key': keyMaterial[32:64], | |
'algorithm': 'sha256' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyramid_hawkauth import HawkAuthenticationPolicy | |
policy = HawkAuthenticationPolicy(decode_hawk_id=get_hawk_id) | |
config.set_authentication_policy(authn_policy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hawk_auth = HawkAuth( | |
hawk_session=resp.headers['hawk-session-token'], | |
server_url=self.server_url | |
) | |
requests.post("/url", auth=hawk_auth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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