Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package login
import (
"context"
"fmt"
"log"
"net/http"
"net/url"

Expand All @@ -14,6 +15,7 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/iostreams"
"github.com/redhat-developer/app-services-cli/pkg/localize"
"github.com/redhat-developer/app-services-cli/pkg/logging"
"github.com/redhat-developer/app-services-cli/static"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -105,6 +107,8 @@ func (a *AuthorizationCodeGrant) loginSSO(ctx context.Context, cfg *SSOConfig) e
http.Redirect(w, r, authCodeURL, http.StatusFound)
})

sm.Handle("/static/", createStaticHTTPHandler())

authURL, err := url.Parse(cfg.AuthURL)
if err != nil {
return err
Expand Down Expand Up @@ -189,6 +193,8 @@ func (a *AuthorizationCodeGrant) loginMAS(ctx context.Context, cfg *SSOConfig) e
http.Redirect(w, r, authCodeURL, http.StatusFound)
})

sm.Handle("/static/", createStaticHTTPHandler())

// HTTP handler for the redirect page
sm.Handle("/"+redirectURL.Path, &masRedirectPageHandler{
CancelContext: cancel,
Expand Down Expand Up @@ -231,9 +237,7 @@ func (a *AuthorizationCodeGrant) openBrowser(authCodeURL string, redirectURL *ur
// starts the local HTTP webserver to handle redirect from the Auth server
func (a *AuthorizationCodeGrant) startServer(ctx context.Context, server *http.Server) {
go func() {
if err := server.ListenAndServe(); err == nil {
a.Logger.Error(a.Localizer.MustLocalize("login.log.error.unableToStartServer", localize.NewEntry("Error", err)))
}
log.Fatal(server.ListenAndServe())
}()
<-ctx.Done()
}
Expand Down Expand Up @@ -270,3 +274,8 @@ func (a *AuthorizationCodeGrant) printAuthURLFallback(authCodeURL string, redire
a.Logger.Debug("Error opening browser:", err, "\nPrinting Auth URL to console instead")
a.openBrowser(authCodeURL, redirectURL)
}

func createStaticHTTPHandler() http.Handler {
staticFs := http.FileServer(http.FS(static.ImagesFS()))
return http.StripPrefix("/static", staticFs)
}
3 changes: 2 additions & 1 deletion pkg/auth/login/static/mas-sso-redirect-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
<head>
<link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly@4.70.2/patternfly.css">
<title>%v</title>
<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico"/>
</head>

<body>
<div class="pf-c-empty-state">
<div class="pf-c-empty-state__content">
<i class="fas fa-key pf-c-empty-state__icon" aria-hidden="true"></i>
<img src="/static/img/logo.png" alt="Logo"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change these to SVG

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Inline will be easier than Embed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? I will still need to embed them.

<h1 class="pf-c-title pf-m-lg">%v</h1>
<div class="pf-c-empty-state__body">%v</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion pkg/auth/login/static/sso-redirect-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
<head>
<link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly@4.70.2/patternfly.css">
<title>%v</title>
<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico"/>
</head>

<body>
<div class="pf-c-empty-state">
<div class="pf-c-empty-state__content">
<i class="fas fa-key pf-c-empty-state__icon" aria-hidden="true"></i>
<img src="/static/img/logo.png" alt="Logo"/>
<h1 class="pf-c-title pf-m-lg">%v</h1>
<div class="pf-c-empty-state__body">%v</div>
</div>
Expand Down
Binary file added static/img/favicon.ico
Binary file not shown.
Binary file added static/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions static/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package static

import (
"embed"
"io/fs"
)

//go:embed img/*
var images embed.FS

// ImagesFS returns the embedded images assets
func ImagesFS() fs.FS {
return images
}