Skip to content

Commit 2e015a9

Browse files
Sherif FanousUnix4ever
authored andcommitted
chore: support Auth0 client playing nicely with other OAuth2/OIDC providers
Omni doesn't use a generic OAuth2/OIDC client/SDK instead it uses the Auth0 SDK for Vue and it's using a pretty old version, v1.0.2 as can be seen by inspecting the Omni package.json [here](https://github.com/siderolabs/omni/blob/7fb5d2b20a9372e1a0906b9384696daf93a45c51/frontend/package.json#L13). This SDK in turn uses [auth0-spa-js](https://github.com/auth0/auth0-spa-js) v1.22.1 which can be seen by inspecting its package.json [here](https://github.com/auth0/auth0-vue/blob/bb3bc817d18b8b6d68f3292fe6fadb31f28320db/package.json#L80). **This has significant implications as the v1 of the SDK is not compliant with OAuth2 in 1 critical area.** OAuth2 mandates the use of the `application/x-www-form-urlencoded` content type for grant messages sent to the token endpoint and that sending JSON request bodies will result in a 400 error. Unfortunately the v1 of the SDK sends the request payload as JSON which means that IdPs such as Authentik rightfully returns a 400 error and this results in an infinite loop of requests from Omni to Authentik. The behavior can be confirmed by looking at the comment in the Auth0 SDK code [here](https://github.com/auth0/auth0-spa-js/blob/371e5a82a6da3be24a2f89b7a3a4473f01156c02/src/global.ts#L251). Interestingly the default for the `useFormData` was changed to `true` in v1.22.6 of the SDK. This PR introduces a new Omni flag called `--auth-auth0-use-form-data`. By default the flag is set to `false` to maintain backwards compatibility. If the flag is set to `true` then the Auth0 client is created with the `useFormData` set to `true` Signed-off-by: Sherif Fanous <[email protected]> Signed-off-by: Artem Chernyshev <[email protected]>
1 parent de4c096 commit 2e015a9

File tree

8 files changed

+232
-178
lines changed

8 files changed

+232
-178
lines changed

client/api/omni/specs/auth.pb.go

Lines changed: 178 additions & 168 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/api/omni/specs/auth.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ message AuthConfigSpec {
1212
bool enabled = 1;
1313
string domain = 2;
1414
string client_id = 3;
15+
bool useFormData = 4;
1516
}
1617

1718
message Webauthn {

client/api/omni/specs/auth_vtproto.pb.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/omni/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ func init() {
307307
"enable Auth0 authentication. Once set to true, it cannot be set back to false.")
308308
rootCmd.Flags().StringVar(&config.Config.Auth.Auth0.ClientID, "auth-auth0-client-id", config.Config.Auth.Auth0.ClientID, "Auth0 application client ID.")
309309
rootCmd.Flags().StringVar(&config.Config.Auth.Auth0.Domain, "auth-auth0-domain", config.Config.Auth.Auth0.Domain, "Auth0 application domain.")
310+
rootCmd.Flags().BoolVar(&config.Config.Auth.Auth0.UseFormData, "auth-auth0-use-form-data", config.Config.Auth.Auth0.UseFormData,
311+
"When true, data to the token endpoint is transmitted as x-www-form-urlencoded data instead of JSON. The default is false")
310312

311313
rootCmd.Flags().BoolVar(&config.Config.Auth.WebAuthn.Enabled, "auth-webauthn-enabled", config.Config.Auth.WebAuthn.Enabled,
312314
"enable WebAuthn authentication. Once set to true, it cannot be set back to false.")

frontend/src/api/omni/specs/auth.pb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type AuthConfigSpecAuth0 = {
99
enabled?: boolean
1010
domain?: string
1111
client_id?: string
12+
useFormData?: boolean
1213
}
1314

1415
export type AuthConfigSpecWebauthn = {

frontend/src/main.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ const setupApp = async () => {
5353
appendToBody: true,
5454
})
5555

56-
if (authType.value === AuthType.Auth0) {
57-
app = app.use(createAuth0({
58-
domain: authConfigSpec!.auth0?.domain!,
59-
client_id: authConfigSpec!.auth0?.client_id!,
60-
redirect_uri: window.location.origin,
61-
}))
62-
}
56+
if (authType.value === AuthType.Auth0) {
57+
app = app.use(createAuth0({
58+
domain: authConfigSpec!.auth0?.domain!,
59+
client_id: authConfigSpec!.auth0?.client_id!,
60+
redirect_uri: window.location.origin,
61+
useFormData: !!authConfigSpec!.auth0?.useFormData,
62+
}))
63+
}
6364

6465
app.use(vClickOutside);
6566
app.mount('#app');

internal/pkg/auth/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func EnsureAuthConfigResource(ctx context.Context, st state.State, logger *zap.L
4444
res.TypedSpec().Value.Auth0.Enabled = authParams.Auth0.Enabled
4545
res.TypedSpec().Value.Auth0.Domain = authParams.Auth0.Domain
4646
res.TypedSpec().Value.Auth0.ClientId = authParams.Auth0.ClientID
47+
res.TypedSpec().Value.Auth0.UseFormData = authParams.Auth0.UseFormData
4748
res.TypedSpec().Value.Saml.Enabled = authParams.SAML.Enabled
4849
res.TypedSpec().Value.Saml.Url = authParams.SAML.URL
4950
res.TypedSpec().Value.Saml.Metadata = authParams.SAML.Metadata

internal/pkg/config/auth.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ type AuthParams struct {
2020

2121
// Auth0Params holds configuration parameters for Auth0.
2222
type Auth0Params struct {
23-
Domain string `yaml:"domain"`
24-
ClientID string `yaml:"clientID"`
25-
Enabled bool `yaml:"enabled"`
23+
Domain string `yaml:"domain"`
24+
ClientID string `yaml:"clientID"`
25+
UseFormData bool `yaml:"useFormData"`
26+
Enabled bool `yaml:"enabled"`
2627
}
2728

2829
// WebAuthnParams holds configuration parameters for WebAuthn.

0 commit comments

Comments
 (0)