feat(controller): Add authtoken public id to request context

This allows for http middleware handler functions that run later in the
handler function stack to have access to the extracted auth token public
id.

(cherry picked from commit e337cf8f69)
pull/4099/head
Timothy Messier 3 years ago
parent 90c848c1e0
commit da6ff69f53
No known key found for this signature in database
GPG Key ID: EFD2F184F7600572

@ -17,6 +17,7 @@ const (
type (
ContextMaxRequestSizeType struct{}
ContextOriginalRequestPathType struct{}
ContextAuthTokenPublicIdType struct{}
)
var (
@ -30,6 +31,10 @@ var (
// about clashing string identifiers
ContextMaxRequestSizeTypeKey ContextMaxRequestSizeType
// ContextAuthTokenPublicIdKey is a value to keep linters from complaining
// about clashing string identifiers
ContextAuthTokenPublicIdKey ContextAuthTokenPublicIdType
// ContextOriginalRequestPathTypeKey is a value to keep linters from complaining
// about clashing string identifiers
ContextOriginalRequestPathTypeKey ContextOriginalRequestPathType

@ -411,6 +411,7 @@ func wrapHandlerWithCommonFuncs(h http.Handler, c *Controller, props HandlerProp
}
requestInfo.PublicId, requestInfo.EncryptedToken, requestInfo.TokenFormat = auth.GetTokenFromRequest(ctx, c.kms, r)
ctx = context.WithValue(ctx, globals.ContextAuthTokenPublicIdKey, requestInfo.PublicId)
if info, ok := event.RequestInfoFromContext(ctx); ok {
// piggyback some eventing fields with the auth info proto message

Loading…
Cancel
Save