Skip to content

Commit

Permalink
feat: introduce fallbacks for required configs (#376)
Browse files Browse the repository at this point in the history
Closes #369
Closes #352
  • Loading branch information
aeneasr authored May 4, 2020
1 parent aa74935 commit b3bcb25
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 27 deletions.
39 changes: 15 additions & 24 deletions .schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@
"selfservice": {
"type": "object",
"additionalProperties": false,
"required": [
"logout"
],
"properties": {
"strategies": {
"type": "object",
Expand Down Expand Up @@ -351,10 +348,7 @@
]
}
},
"additionalProperties": false,
"required": [
"redirect_to"
]
"additionalProperties": false
},
"settings": {
"type": "object",
Expand Down Expand Up @@ -591,7 +585,8 @@
"format": "uri",
"examples": [
"https://my-app.com/login/mfa"
]
],
"default": "https://www.ory.sh/kratos/docs/fallback/mfa"
},
"login_ui": {
"title": "Login UI URL",
Expand All @@ -600,7 +595,8 @@
"format": "uri",
"examples": [
"https://my-app.com/login"
]
],
"default": "https://www.ory.sh/kratos/docs/fallback/login"
},
"settings_ui": {
"title": "Settings UI URL",
Expand All @@ -609,7 +605,8 @@
"format": "uri",
"examples": [
"https://my-app.com/user/settings"
]
],
"default": "https://www.ory.sh/kratos/docs/fallback/settings"
},
"default_return_to": {
"$ref": "#/definitions/defaultReturnTo"
Expand All @@ -621,7 +618,8 @@
"format": "uri",
"examples": [
"https://my-app.com/signup"
]
],
"default": "https://www.ory.sh/kratos/docs/fallback/registration"
},
"error_ui": {
"title": "ORY Kratos Error UI URL",
Expand All @@ -630,7 +628,8 @@
"format": "uri",
"examples": [
"https://my-app.com/kratos-error"
]
],
"default": "https://www.ory.sh/kratos/docs/fallback/error"
},
"verify_ui": {
"title": "Verify UI URL",
Expand All @@ -639,7 +638,8 @@
"format": "uri",
"examples": [
"https://my-app.com/verify"
]
],
"default": "https://www.ory.sh/kratos/docs/fallback/verify"
},
"whitelisted_return_to_urls": {
"title": "Whitelisted Return To URLs",
Expand All @@ -656,14 +656,7 @@
"uniqueItems": true
}
},
"required": [
"settings_ui",
"login_ui",
"registration_ui",
"error_ui",
"verify_ui",
"default_return_to"
],
"required": [],
"additionalProperties": false
},
"log": {
Expand Down Expand Up @@ -840,9 +833,7 @@
},
"required": [
"dsn",
"identity",
"selfservice",
"courier"
"identity"
],
"additionalProperties": false
}
6 changes: 6 additions & 0 deletions courier/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/gofrs/uuid"
"github.com/pkg/errors"

"github.com/ory/herodot"

gomail "github.com/ory/mail/v3"

"github.com/ory/kratos/driver/configuration"
Expand Down Expand Up @@ -123,6 +125,10 @@ func (m *Courier) Shutdown(ctx context.Context) error {
func (m *Courier) watchMessages(ctx context.Context, errChan chan error) {
for {
if err := backoff.Retry(func() error {
if len(m.Dialer.Host) == 0 {
return errors.WithStack(herodot.ErrInternalServerError.WithReasonf("Courier tried to deliver an email but courier.smtp_url is not set!"))
}

messages, err := m.d.CourierPersister().NextMessages(ctx, 10)
if err != nil {
if errors.Is(err, ErrQueueEmpty) {
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/concepts/security.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ it best suited for any risk assessment.

:::warn

Please be aware that this chapter is still work in progress. Not all
mitigation strategies have been implemented yet in ORY Kratos!
Please be aware that this chapter is still work in progress. Not all mitigation
strategies have been implemented yet in ORY Kratos!

:::

Expand Down
17 changes: 17 additions & 0 deletions docs/docs/fallback/default_return_to.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: error
title: This should be the Error UI
---

You ended up here because you did not set the following configuration value:

```yaml title="path/to/kratos/config.yml
urls:
default_return_to: http://my-app.com/dashboard
```
You can set this configuration value using environment variable
`URLS_DEFAULT_RETURN_TO` as well!

If you don't know what that means, head over to
[Self-Service Flow Completion](../concepts/selfservice-flow-completion.md)!
17 changes: 17 additions & 0 deletions docs/docs/fallback/error.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: error
title: This should be the Error UI
---

You ended up here because you did not set the following configuration value:

```yaml title="path/to/kratos/config.yml
urls:
error_ui: http://my-app.com/error
```
You can set this configuration value using environment variable `URLS_ERROR_UI`
as well!

If you don't know what that means, head over to
[User-Facing Error](../self-service/flows/user-facing-errors.md)!
17 changes: 17 additions & 0 deletions docs/docs/fallback/login.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: login
title: This should be the Login UI
---

You ended up here because you did not set the following configuration value:

```yaml title="path/to/kratos/config.yml
urls:
login_ui: http://my-app.com/login
```
You can set this configuration value using environment variable `URLS_LOGIN_UI`
as well!

If you don't know what that means, head over to
[User Login and Registration](../self-service/flows/user-login-user-registration.mdx)!
17 changes: 17 additions & 0 deletions docs/docs/fallback/mfa.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: mfa
title: This should be the Mfa UI
---

You ended up here because you did not set the following configuration value:

```yaml title="path/to/kratos/config.yml
urls:
mfa_ui: http://my-app.com/mfa
```
You can set this configuration value using environment variable `URLS_MFA_UI` as
well!

If you don't know what that means, head over to our
[MFA Documentation](../self-service/flows/2fa-mfa-multi-factor-authentication.md)!
17 changes: 17 additions & 0 deletions docs/docs/fallback/registration.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: registration
title: This should be the Registration UI
---

You ended up here because you did not set the following configuration value:

```yaml title="path/to/kratos/config.yml
urls:
registration_ui: http://my-app.com/registration
```
You can set this configuration value using environment variable
`URLS_REGISTRATION_UI` as well!

If you don't know what that means, head over to
[User Login and Registration](../self-service/flows/user-login-user-registration.mdx)!
17 changes: 17 additions & 0 deletions docs/docs/fallback/settings.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: settings
title: This should be the Settings UI
---

You ended up here because you did not set the following configuration value:

```yaml title="path/to/kratos/config.yml
urls:
settings_ui: http://my-app.com/settings
```
You can set this configuration value using environment variable
`URLS_SETTINGS_UI` as well!

If you don't know what that means, head over to
[User Settings](../self-service/flows/user-settings-profile-management.mdx)!
17 changes: 17 additions & 0 deletions docs/docs/fallback/verify.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: verify
title: This should be the Verify UI
---

You ended up here because you did not set the following configuration value:

```yaml title="path/to/kratos/config.yml
urls:
verify_ui: http://my-app.com/verify
```
You can set this configuration value using environment variable `URLS_VERIFY_UI`
as well!

If you don't know what that means, head over to our
[User Verification](../self-service/flows/verify-email-account-activation.mdx)!
8 changes: 8 additions & 0 deletions docs/docs/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ You can find all configuration files for this quickstart guide in
individual configuration files are doing, you must consult the other chapters of
this documentation.

:::note

To get a minimal version of ORY Kratos running, you need to set configuration items
`identity.traits.default_schema_url` and `dsn`. You should also configure `urls.*_ui`
because your users will end up at fallbacks otherwise.

:::

In the future, this guide will support more use cases such as:

- Use GitHub to login in and sign up
Expand Down
6 changes: 5 additions & 1 deletion driver/configuration/provider_viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ func (p *ViperProvider) SelfAdminURL() *url.URL {
}

func (p *ViperProvider) CourierSMTPURL() *url.URL {
return mustParseURLFromViper(p.l, ViperKeyCourierSMTPURL)
u, err := url.ParseRequestURI(viper.GetString(ViperKeyCourierSMTPURL))
if err != nil {
return new(url.URL)
}
return u
}

func (p *ViperProvider) LoginURL() *url.URL {
Expand Down

0 comments on commit b3bcb25

Please sign in to comment.