Skip to content

Commit

Permalink
refactor: dry up login.NewFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 25, 2020
1 parent 8eb2e6f commit f261c44
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
10 changes: 1 addition & 9 deletions selfservice/flow/login/flow.go
Expand Up @@ -88,20 +88,12 @@ type Flow struct {
}

func NewFlow(exp time.Duration, csrf string, r *http.Request, flowType flow.Type) *Flow {
source := urlx.Copy(r.URL)
source.Host = r.Host

source.Scheme = "http"
if r.TLS != nil {
source.Scheme = "https"
}

now := time.Now().UTC()
return &Flow{
ID: x.NewUUID(),
ExpiresAt: now.Add(exp),
IssuedAt: now,
RequestURL: source.String(),
RequestURL: x.RequestURL(r).String(),
Methods: map[identity.CredentialsType]*FlowMethod{},
CSRFToken: csrf,
Type: flowType,
Expand Down
2 changes: 1 addition & 1 deletion selfservice/flow/login/flow_test.go
Expand Up @@ -59,7 +59,7 @@ func TestNewFlow(t *testing.T) {
r := login.NewFlow(0, "csrf", &http.Request{
URL: urlx.ParseOrPanic("https://ory.sh/"),
Host: "ory.sh"}, flow.TypeBrowser)
assert.Equal(t, "http://ory.sh/", r.RequestURL)
assert.Equal(t, "https://ory.sh/", r.RequestURL)
})
}

Expand Down

0 comments on commit f261c44

Please sign in to comment.