/
flow.go
46 lines (38 loc) · 1.04 KB
/
flow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package flow
import (
"context"
"net/http"
"net/url"
"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
}
type FlowWithRedirect interface {
SecureRedirectToOpts(ctx context.Context, cfg config.Provider) (opts []x.SecureRedirectOption)
}