FusionAuth/terraform-provider-fusionauth

Bug with creating a new theme using source_theme_id?

lyricnz opened this issue · 5 comments

This might be a Fusion Auth bug - either in the API, or in their website/app.

I created a new theme using

resource "fusionauth_theme" "new_theme_2" {
  name = "clone theme"
  source_theme_id = "75a068fd-e94b-451a-9aeb-3ddb9a3b5987"
}

Where that ID is the FusionAuth theme on my local (not sure if this constant). The new theme contained the following markup for "OAuth two-factor enable" snippet, which appears to be the actual template for "OAuth two-factor enable complete"

Starting as below (42 lines total)

[#ftl/]
[#-- @ftlvariable name="application" type="io.fusionauth.domain.Application" --]
[#-- @ftlvariable name="client_id" type="java.lang.String" --]
[#-- @ftlvariable name="currentUser" type="io.fusionauth.domain.User" --]
[#-- @ftlvariable name="recoveryCodes" type="java.util.List<java.lang.String>" --]
[#-- @ftlvariable name="tenant" type="io.fusionauth.domain.Tenant" --]
[#-- @ftlvariable name="tenantId" type="java.util.UUID" --]
[#-- @ftlvariable name="version" type="java.lang.String" --]
[#import "../_helpers.ftl" as helpers/]

[@helpers.html]
  [@helpers.head]
    [#-- Custom <head> code goes here --]
  [/@helpers.head]
  [@helpers.body]

    [@helpers.header]
      [#-- Custom header code goes here --]
    [/@helpers.header]

    [@helpers.main title=theme.message('two-factor-recovery-codes')]
      [#setting url_escaping_charset='UTF-8']
      <form action="${request.contextPath}/oauth2/two-factor-enable-complete" method="POST" class="full">
        [@helpers.oauthHiddenFields/]
        <p class="mt-0"> ${theme.message("{description}oauth2-recovery-codes-1")} </p>
        <fieldset>
          <div class="code d-flex" style="justify-content: center; flex-wrap: wrap; gap: 5px 15px;">
            [#list recoveryCodes as code]<div>${code}</div>[/#list]
          </div>
          <p> ${theme.message("{description}oauth2-recovery-codes-2")}  </p>
        </fieldset>
        <div class="form-row">
          [@helpers.button text=theme.message('done')/]
        </div>
      </form>
    [/@helpers.main]

    [@helpers.footer]
      [#-- Custom footer code goes here --]
    [/@helpers.footer]
  [/@helpers.body]
[/@helpers.html]

This could be caused/triggered by changing a theme definition from having source_theme_id to not - see #172

I reproduced it thusly:

  • Create theme with
resource "fusionauth_theme" "new_theme_2" {
  name = "clone theme"
  source_theme_id = "75a068fd-e94b-451a-9aeb-3ddb9a3b5987"
}
  • check "OAuth two-factor enable" - it has 125 lines

Screenshot 2023-02-23 at 12 17 21 pm

  • comment out source_theme_id line and terraform apply. only one change
    image

  • reload "OAuth two-factor enable" - it has 42 lines

Screenshot 2023-02-23 at 12 17 49 pm

Confirmed the template issue with preview. The "enable" snippet shows the recovery codes

image

Cannot reproduce in the Fusion Auth admin web interface (but there is no concept of removing the source id)

Running into this issue myself, looking into it I believe its because the underlying API route accepts EITHER the template definitions, or a source_theme_id.

The way the API documentation is written suggests that as soon as the source_theme_id is provided, the templates will be ignored, and instead copied from the source theme