Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token-based authentication. #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jbuchbinder
Copy link

This patch adds authentication based on a passed token, contained in the X-Token header. It allows a login endpoint to create a token which can be passed as a header to all subsequent API calls.

// The function should return true for a valid token.
func TokenFunc(authfn func(string) bool) martini.Handler {
return func(res http.ResponseWriter, req *http.Request, c martini.Context) {
auth := req.Header.Get("X-Token")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you use the X-Token header? Token-based authentication usually uses the Authorization header as well, together with the Bearer keyword instead of Basic (or sometimes no keyword at all).

Examples:

Authorization: mytoken
Authorization: Bearer mytoken

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of third party APIs have done so to avoid any confusion with Basic auth -- but I'm fine with using Authorization: Bearer instead. Do you want an adjusted patch set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I don't really care that much. Either way is fine with me.

If @codegangsta if fine with this patch, I'd just add a few simple tests before we merge, that's all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants