Skip to content

Commit

Permalink
DXCDT-555: Include universal-login customize assets (#891)
Browse files Browse the repository at this point in the history
* Add make command to generate universal-login preview assets

* Add universal-login preview assets

* Add route to serve universal-login customize assets

* Update assets

* Minor tweaks to web server url path

* Update assets

* Add npm install to make assets

* Remove ws_port query param

* Update assets

* Tiny improvements
  • Loading branch information
sergiught committed Nov 1, 2023
1 parent 1a6f20a commit 4a570db
Show file tree
Hide file tree
Showing 20 changed files with 9,802 additions and 13 deletions.
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ GO_PKG := github.com/auth0/$(NAME)
GO_BIN ?= $(shell go env GOPATH)/bin
GO_PACKAGES := $(shell go list ./... | grep -vE "vendor|tools|mock")

UNIVERSAL_LOGIN_ASSETS_EXTERNAL_DIR ?= ./../ulp-branding-app
UNIVERSAL_LOGIN_ASSETS_INTERNAL_DIR = ./internal/cli/data/universal-login

## Configuration for build-info
BUILD_DIR ?= $(CURDIR)/out
BUILD_INFO_PKG := $(GO_PKG)/internal/buildinfo
Expand Down Expand Up @@ -68,6 +71,22 @@ $(GO_BIN)/commander:
$(GO_BIN)/auth0:
@$(MAKE) install

#-----------------------------------------------------------------------------------------------------------------------
# Assets
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: assets

assets: ## Generate Universal Login embeddable assets
${call print, "Generating Universal Login embeddable assets"}
@if [ ! -d "${UNIVERSAL_LOGIN_ASSETS_EXTERNAL_DIR}" ]; \
then \
${call print_warning, "No such file or directory: ${UNIVERSAL_LOGIN_ASSETS_EXTERNAL_DIR}"}; \
exit 1; \
fi
@rm -rf "${UNIVERSAL_LOGIN_ASSETS_INTERNAL_DIR}"
@cd "${UNIVERSAL_LOGIN_ASSETS_EXTERNAL_DIR}" && npm install && npm run build
@cp -r "${UNIVERSAL_LOGIN_ASSETS_EXTERNAL_DIR}/dist" "${UNIVERSAL_LOGIN_ASSETS_INTERNAL_DIR}"

#-----------------------------------------------------------------------------------------------------------------------
# Documentation
#-----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -167,5 +186,5 @@ define print
endef

define print_warning
@printf "${TEXT_INVERSE}${COLOR_WHITE} ! ${COLOR_YELLOW} %-75s ${COLOR_WHITE} ${RESET}\n" $(1)
printf "${TEXT_INVERSE}${COLOR_WHITE} !! ${COLOR_YELLOW} %-75s ${COLOR_WHITE} ${RESET}\n" $(1)
endef
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9,672 changes: 9,672 additions & 0 deletions internal/cli/data/universal-login/assets/index-e3ebde5d.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions internal/cli/data/universal-login/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="https://cdn.auth0.com/quantum-assets/dist/1.0.3/favicons/auth0-favicon-onlight.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Auth0 | Branding Customization</title>
<script type="module" crossorigin src="/assets/index-e3ebde5d.js"></script>
<link rel="stylesheet" href="/assets/index-ba9d88e4.css">
</head>
<body>
<div id="root"></div>

</body>
</html>
34 changes: 34 additions & 0 deletions internal/cli/data/universal-login/static/img/app-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions internal/cli/data/universal-login/static/img/avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions internal/cli/data/universal-login/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 26 additions & 11 deletions internal/cli/universal_login_customize.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cli

import (
"context"
"embed"
"encoding/json"
"fmt"
"io/fs"
"net"
"net/http"
"net/url"
Expand All @@ -20,14 +22,21 @@ import (
)

const (
webAppURL = "http://localhost:5173"
webServerPort = "52649"
webServerHost = "localhost:" + webServerPort
webServerURL = "http://localhost:" + webServerPort
fetchBrandingMessageType = "FETCH_BRANDING"
fetchPromptMessageType = "FETCH_PROMPT"
saveBrandingMessageType = "SAVE_BRANDING"
errorMessageType = "ERROR"
successMessageType = "SUCCESS"
)

var (
//go:embed data/universal-login/*
universalLoginPreviewAssets embed.FS
)

type (
universalLoginBrandingData struct {
Applications []*applicationData `json:"applications"`
Expand Down Expand Up @@ -397,7 +406,7 @@ func startWebSocketServer(
ctx, cancel := context.WithCancel(ctx)
defer cancel()

listener, err := net.Listen("tcp", "127.0.0.1:0")
listener, err := net.Listen("tcp", webServerHost)
if err != nil {
return err
}
Expand All @@ -410,8 +419,17 @@ func startWebSocketServer(
tenant: tenantDomain,
}

assetsWithoutPrefix, err := fs.Sub(universalLoginPreviewAssets, "data/universal-login")
if err != nil {
return err
}

router := http.NewServeMux()
router.Handle("/", http.FileServer(http.FS(assetsWithoutPrefix)))
router.Handle("/ws", handler)

server := &http.Server{
Handler: handler,
Handler: router,
ReadTimeout: time.Minute * 10,
WriteTimeout: time.Minute * 10,
}
Expand All @@ -421,7 +439,7 @@ func startWebSocketServer(
errChan <- server.Serve(listener)
}()

openWebAppInBrowser(display, listener.Addr())
openWebAppInBrowser(display)

select {
case err := <-errChan:
Expand All @@ -431,13 +449,10 @@ func startWebSocketServer(
}
}

func openWebAppInBrowser(display *display.Renderer, addr net.Addr) {
port := addr.(*net.TCPAddr).Port
webAppURLWithPort := fmt.Sprintf("%s?ws_port=%d", webAppURL, port)

display.Infof("Perform your changes within the editor: %q", webAppURLWithPort)
func openWebAppInBrowser(display *display.Renderer) {
display.Infof("Perform your changes within the editor: %q", webServerURL)

if err := browser.OpenURL(webAppURLWithPort); err != nil {
if err := browser.OpenURL(webServerURL); err != nil {
display.Warnf("Failed to open the browser. Visit the URL manually.")
}
}
Expand Down Expand Up @@ -582,7 +597,7 @@ func checkOriginFunc(r *http.Request) bool {
return false
}

return originURL.String() == webAppURL
return originURL.String() == webServerURL
}

func saveUniversalLoginBrandingData(ctx context.Context, api *auth0.API, data *universalLoginBrandingData) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/universal_login_customize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ func TestCheckOriginFunc(t *testing.T) {
testName: "Valid Origin",
request: &http.Request{
Header: http.Header{
"Origin": []string{webAppURL},
"Origin": []string{webServerURL},
},
},
expected: true,
Expand Down

0 comments on commit 4a570db

Please sign in to comment.