-
-
Notifications
You must be signed in to change notification settings - Fork 963
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
feat: login & registration via code #3378
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b822073
feat: login with code
Benehiko b6196ff
feat: login and registration with code
Benehiko 6eb0ab0
fix: flow states
Benehiko 343365a
fix: golangci-lint
Benehiko e61c748
chore: move verification hook to before persist
Benehiko 5ebe91a
chore: refactor code state manager to use generics
Benehiko 2107a7e
test: registration with spa and browser
Benehiko 2f45939
test: registration with code on browser and spa
Benehiko 361b316
test: login with code on spa and browser clients
Benehiko 11183d5
test(e2e): login and registration with code errors
Benehiko ca77a83
style: format
Benehiko 26690c3
test(e2e): login success with code
Benehiko 6e8a964
test(e2e): recovery on identity with code
Benehiko aeee834
fix: sdk login and registrion should contain code method
Benehiko 4bdfc79
test(e2e): spa flows on login and registration code
Benehiko 2d48898
chore: rename config keys and return status 400 on first flow submit
Benehiko a0c8e75
fix: verification handler test sql error
Benehiko 558bfe5
chore: restore e2e test script
Benehiko 35769fc
fix(test): verification fake strategy
Benehiko 4da4887
feat: login and registration email template config keys
Benehiko 42ac455
chore: code review for `code` strategy (magic code login) (#3456)
aeneasr d4a2583
chore: synchronize workspaces
aeneasr cdccbef
chore: synchronize workspaces
aeneasr 99922c1
chore: synchronize workspaces
aeneasr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
courier/template/courier/builtin/templates/login_code/valid/email.body.gotmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Hi, | ||
|
||
please login to your account by entering the following code: | ||
|
||
{{ .LoginCode }} |
5 changes: 5 additions & 0 deletions
5
courier/template/courier/builtin/templates/login_code/valid/email.body.plaintext.gotmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Hi, | ||
|
||
please login to your account by entering the following code: | ||
|
||
{{ .LoginCode }} |
1 change: 1 addition & 0 deletions
1
courier/template/courier/builtin/templates/login_code/valid/email.subject.gotmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Login to your account |
5 changes: 5 additions & 0 deletions
5
courier/template/courier/builtin/templates/registration_code/valid/email.body.gotmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Hi, | ||
|
||
please complete your account registration by entering the following code: | ||
|
||
{{ .RegistrationCode }} |
5 changes: 5 additions & 0 deletions
5
...er/template/courier/builtin/templates/registration_code/valid/email.body.plaintext.gotmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Hi, | ||
|
||
please complete your account registration by entering the following code: | ||
|
||
{{ .RegistrationCode }} |
1 change: 1 addition & 0 deletions
1
courier/template/courier/builtin/templates/registration_code/valid/email.subject.gotmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Complete your account registration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package email | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ory/kratos/courier/template" | ||
) | ||
|
||
type ( | ||
LoginCodeValid struct { | ||
deps template.Dependencies | ||
model *LoginCodeValidModel | ||
} | ||
LoginCodeValidModel struct { | ||
To string | ||
LoginCode string | ||
Identity map[string]interface{} | ||
} | ||
) | ||
|
||
func NewLoginCodeValid(d template.Dependencies, m *LoginCodeValidModel) *LoginCodeValid { | ||
return &LoginCodeValid{deps: d, model: m} | ||
} | ||
|
||
func (t *LoginCodeValid) EmailRecipient() (string, error) { | ||
return t.model.To, nil | ||
} | ||
|
||
func (t *LoginCodeValid) EmailSubject(ctx context.Context) (string, error) { | ||
subject, err := template.LoadText(ctx, t.deps, os.DirFS(t.deps.CourierConfig().CourierTemplatesRoot(ctx)), "login_code/valid/email.subject.gotmpl", "login_code/valid/email.subject*", t.model, t.deps.CourierConfig().CourierTemplatesLoginCodeValid(ctx).Subject) | ||
|
||
return strings.TrimSpace(subject), err | ||
} | ||
|
||
func (t *LoginCodeValid) EmailBody(ctx context.Context) (string, error) { | ||
return template.LoadHTML(ctx, t.deps, os.DirFS(t.deps.CourierConfig().CourierTemplatesRoot(ctx)), "login_code/valid/email.body.gotmpl", "login_code/valid/email.body*", t.model, t.deps.CourierConfig().CourierTemplatesLoginCodeValid(ctx).Body.HTML) | ||
} | ||
|
||
func (t *LoginCodeValid) EmailBodyPlaintext(ctx context.Context) (string, error) { | ||
return template.LoadText(ctx, t.deps, os.DirFS(t.deps.CourierConfig().CourierTemplatesRoot(ctx)), "login_code/valid/email.body.plaintext.gotmpl", "login_code/valid/email.body.plaintext*", t.model, t.deps.CourierConfig().CourierTemplatesLoginCodeValid(ctx).Body.PlainText) | ||
} | ||
|
||
func (t *LoginCodeValid) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(t.model) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package email_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ory/kratos/courier" | ||
"github.com/ory/kratos/courier/template/email" | ||
"github.com/ory/kratos/courier/template/testhelpers" | ||
"github.com/ory/kratos/internal" | ||
) | ||
|
||
func TestLoginCodeValid(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
|
||
t.Run("test=with courier templates directory", func(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
tpl := email.NewLoginCodeValid(reg, &email.LoginCodeValidModel{}) | ||
|
||
testhelpers.TestRendered(t, ctx, tpl) | ||
}) | ||
|
||
t.Run("test=with remote resources", func(t *testing.T) { | ||
testhelpers.TestRemoteTemplates(t, "../courier/builtin/templates/login_code/valid", courier.TypeLoginCodeValid) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package email | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ory/kratos/courier/template" | ||
) | ||
|
||
type ( | ||
RegistrationCodeValid struct { | ||
deps template.Dependencies | ||
model *RegistrationCodeValidModel | ||
} | ||
RegistrationCodeValidModel struct { | ||
To string | ||
Traits map[string]interface{} | ||
RegistrationCode string | ||
} | ||
) | ||
|
||
func NewRegistrationCodeValid(d template.Dependencies, m *RegistrationCodeValidModel) *RegistrationCodeValid { | ||
return &RegistrationCodeValid{deps: d, model: m} | ||
} | ||
|
||
func (t *RegistrationCodeValid) EmailRecipient() (string, error) { | ||
return t.model.To, nil | ||
} | ||
|
||
func (t *RegistrationCodeValid) EmailSubject(ctx context.Context) (string, error) { | ||
subject, err := template.LoadText(ctx, t.deps, os.DirFS(t.deps.CourierConfig().CourierTemplatesRoot(ctx)), "registration_code/valid/email.subject.gotmpl", "registration_code/valid/email.subject*", t.model, t.deps.CourierConfig().CourierTemplatesRegistrationCodeValid(ctx).Subject) | ||
|
||
return strings.TrimSpace(subject), err | ||
} | ||
|
||
func (t *RegistrationCodeValid) EmailBody(ctx context.Context) (string, error) { | ||
return template.LoadHTML(ctx, t.deps, os.DirFS(t.deps.CourierConfig().CourierTemplatesRoot(ctx)), "registration_code/valid/email.body.gotmpl", "registration_code/valid/email.body*", t.model, t.deps.CourierConfig().CourierTemplatesRegistrationCodeValid(ctx).Body.HTML) | ||
} | ||
|
||
func (t *RegistrationCodeValid) EmailBodyPlaintext(ctx context.Context) (string, error) { | ||
return template.LoadText(ctx, t.deps, os.DirFS(t.deps.CourierConfig().CourierTemplatesRoot(ctx)), "registration_code/valid/email.body.plaintext.gotmpl", "registration_code/valid/email.body.plaintext*", t.model, t.deps.CourierConfig().CourierTemplatesRegistrationCodeValid(ctx).Body.PlainText) | ||
} | ||
|
||
func (t *RegistrationCodeValid) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(t.model) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package email_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ory/kratos/courier" | ||
"github.com/ory/kratos/courier/template/email" | ||
"github.com/ory/kratos/courier/template/testhelpers" | ||
"github.com/ory/kratos/internal" | ||
) | ||
|
||
func TestRegistrationCodeValid(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
|
||
t.Run("test=with courier templates directory", func(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
tpl := email.NewRegistrationCodeValid(reg, &email.RegistrationCodeValidModel{}) | ||
|
||
testhelpers.TestRendered(t, ctx, tpl) | ||
}) | ||
|
||
t.Run("test=with remote resources", func(t *testing.T) { | ||
testhelpers.TestRemoteTemplates(t, "../courier/builtin/templates/registration_code/valid", courier.TypeRegistrationCodeValid) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this interface being used or implemented?