Documentation ¶
Index ¶
- func TokenFromRequest(w http.ResponseWriter, r *http.Request) (string, error)
- type SharedJwtAuth
- func (auth *SharedJwtAuth) AuthFromID(viewerID string) (*entjwt.AuthedIdentity, error)
- func (auth *SharedJwtAuth) AuthViewer(w http.ResponseWriter, r *http.Request) viewer.ViewerContext
- func (auth *SharedJwtAuth) ExtendTokenExpiration(tokenStr string) (string, error)
- func (auth *SharedJwtAuth) GetBaseClaims() jwt.Claims
- func (auth *SharedJwtAuth) ViewerFromToken(tokenStr string) (viewer.ViewerContext, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TokenFromRequest ¶
Types ¶
type SharedJwtAuth ¶
type SharedJwtAuth struct { // to be used for the current request VCFromID func(string) (viewer.ViewerContext, error) SigningKey interface{} Duration time.Duration SigningMethod jwt.SigningMethod // when generating token. It's passed to jwt.NewWithClaims ClaimFunc func(string) entjwt.Claims BaseClaimFunc func() entjwt.Claims // (with a valid existing token and without a refresh token) // If not set (default), token can be extended whenever e.g. sliding window every 10 minutes, every request, etc. // If set, token can only be extended within that window e.g. if set to 5 minutes, will be 5 minutes // before token expires // By default, auth handler doesn't do anything and since DefaultDuration is currently 1 hour, // developer needs to pick *something* to do to extend tokens or provide a // longer duration ExtendTokenDuration time.Duration }
SharedJwtAuth is shared code for authenticating the viewer from the given ID using JWT This is hidden in an internal package for now because AuthFromID() shouldn't be a public API since it exists to share code between similar implementations using jwt
func (*SharedJwtAuth) AuthFromID ¶
func (auth *SharedJwtAuth) AuthFromID(viewerID string) (*entjwt.AuthedIdentity, error)
AuthFromID returns an AuthedIdentity that's shared across different implementation details of auth
func (*SharedJwtAuth) AuthViewer ¶
func (auth *SharedJwtAuth) AuthViewer(w http.ResponseWriter, r *http.Request) viewer.ViewerContext
AuthViewer takes the authorization token from the request and verifies if valid and then returns a ViewerContext which maps to user encoded in the token
func (*SharedJwtAuth) ExtendTokenExpiration ¶
func (auth *SharedJwtAuth) ExtendTokenExpiration(tokenStr string) (string, error)
ExtendTokenExpiration takes the current token and gets a new auth token for the user See ExtendTokenDuration for more information
func (*SharedJwtAuth) GetBaseClaims ¶
func (auth *SharedJwtAuth) GetBaseClaims() jwt.Claims
func (*SharedJwtAuth) ViewerFromToken ¶
func (auth *SharedJwtAuth) ViewerFromToken(tokenStr string) (viewer.ViewerContext, error)
ViewerFromToken takes the token string and verifies if valid and then returns a ViewerContext which maps to user encoded in the token