mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
For #27287 Video explaining the PR: https://www.youtube.com/watch?v=ZHgFUAvrPEI This PR adds SCIM Users support for Okta. The goal is to first add Users/Groups support so that the remaining backend SCIM work can be done in parallel. This PR does not include the following, which will be added in later PRs - Changes file - Groups support for Okta - Full support for Entra ID - Integration tests # Checklist for submitter - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [x] Added/updated automated tests - [x] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/contexts/logging"
|
|
"github.com/fleetdm/fleet/v4/server/contexts/token"
|
|
"github.com/fleetdm/fleet/v4/server/contexts/viewer"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
kithttp "github.com/go-kit/kit/transport/http"
|
|
)
|
|
|
|
// SetRequestsContexts updates the request with necessary context values for a request
|
|
func SetRequestsContexts(svc fleet.Service) kithttp.RequestFunc {
|
|
return func(ctx context.Context, r *http.Request) context.Context {
|
|
bearer := token.FromHTTPRequest(r)
|
|
ctx = token.NewContext(ctx, bearer)
|
|
if bearer != "" {
|
|
v, err := AuthViewer(ctx, string(bearer), svc)
|
|
if err == nil {
|
|
ctx = viewer.NewContext(ctx, *v)
|
|
}
|
|
}
|
|
|
|
ctx = logging.NewContext(ctx, &logging.LoggingContext{})
|
|
ctx = logging.WithStartTime(ctx)
|
|
return ctx
|
|
}
|
|
}
|
|
|
|
func SetRequestsContextMiddleware(svc fleet.Service, next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := kithttp.PopulateRequestContext(r.Context(), r)
|
|
ctx = SetRequestsContexts(svc)(ctx, r)
|
|
next.ServeHTTP(w, r.WithContext(ctx))
|
|
})
|
|
}
|