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 missing func #4

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion auth/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (

echo "github.com/theopenlane/echox"

"github.com/theopenlane/core/pkg/middleware/echocontext"
"github.com/theopenlane/utils/ulids"

"github.com/theopenlane/core/pkg/middleware/echocontext"
)

type AuthenticationType string
Expand Down Expand Up @@ -274,6 +275,27 @@ func GetAuthzSubjectType(ctx context.Context) string {
return subjectType
}

// SetOrganizationIDInAuthContext sets the organization ID in the auth context
// this should only be used when creating a new organization and subsequent updates
// need to happen in the context of the new organization
func SetOrganizationIDInAuthContext(ctx context.Context, orgID string) error {
au, err := GetAuthenticatedUserContext(ctx)
if err != nil {
return err
}

au.OrganizationID = orgID

ec, err := echocontext.EchoContextFromContext(ctx)
if err != nil {
return err
}

SetAuthenticatedUserContext(ec, au)

return nil
}

// AddOrganizationIDToContext appends an authorized organization ID to the context.
// This generally should not be used, as the authorized organization should be
// determined by the claims or the token. This is only used in cases where the
Expand Down
Loading