// Copyright © 2023 Ory Corp // SPDX-License-Identifier: Apache-2.0 package flow import ( "context" "encoding/json" "net/http" "net/url" hydraclientgo "github.com/ory/hydra-client-go/v2" "github.com/ory/x/sqlxx" "github.com/ory/kratos/x/redir" "github.com/gofrs/uuid" "github.com/pkg/errors" "github.com/ory/herodot" "github.com/ory/kratos/driver/config" "github.com/ory/kratos/ui/container" "github.com/ory/kratos/x" "github.com/ory/x/urlx" ) func AppendFlowTo(src *url.URL, id uuid.UUID) *url.URL { return urlx.CopyWithQuery(src, url.Values{"flow": {id.String()}}) } func GetFlowID(r *http.Request) (uuid.UUID, error) { rid := x.ParseUUID(r.URL.Query().Get("flow")) if rid == uuid.Nil { return rid, errors.WithStack(herodot.ErrBadRequest().WithReasonf("The flow query parameter is missing or malformed.")) } return rid, nil } type Flow interface { GetID() uuid.UUID GetType() Type GetRequestURL() string AppendTo(*url.URL) *url.URL GetUI() *container.Container GetState() State SetState(State) GetFlowName() FlowName GetTransientPayload() json.RawMessage } type FlowWithRedirect interface { SecureRedirectToOpts(ctx context.Context, cfg config.Provider) (opts []redir.SecureRedirectOption) } type InternalContexter interface { EnsureInternalContext() GetInternalContext() sqlxx.JSONRawMessage SetInternalContext(sqlxx.JSONRawMessage) } type OAuth2ChallengeProvider interface { GetOAuth2LoginChallenge() sqlxx.NullString } // HydraLoginRequestProvider is implemented by flows that can carry the OAuth2 // login request that initiated them. type HydraLoginRequestProvider interface { GetHydraLoginRequest() *hydraclientgo.OAuth2LoginRequest }