Skip to content

Instantly share code, notes, and snippets.

@tobz
Created November 25, 2013 16:43
Show Gist options
  • Save tobz/7644327 to your computer and use it in GitHub Desktop.
Save tobz/7644327 to your computer and use it in GitHub Desktop.
// Make sure the caller actually has the authority to call these methods.
handler.MapBefore([]string{"GET", "DELETE"}, "token", func(c context.Context) (error) {
// TODO: Figure out if this is the right way to preempt processing of a request.
// Check to see if this token is a supertoken.
if token, ok := c.Data()["Token"].(*ManagedToken); !ok {
goweb.API.RespondWithError(c, 500, "Internal authorization failure")
return fmt.Errorf("Failed to extract authorization token from request - this is bad/not right.")
} else {
if !token.Super {
goweb.API.RespondWithError(c, 401, "You are not authorized to call these methods.")
return fmt.Errorf("Request tried to execute supertoken-level methods without supertoken")
}
return nil
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment