Skip to content

Commit

Permalink
Bugfix Htmlfile not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Getz committed Nov 25, 2022
1 parent 0c3fa0e commit cd6fdd1
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions src/iam/oidc_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"github.com/google/uuid"
"github.com/pkg/browser"
"golang.org/x/oauth2"
"html/template"
"net/http"
"os"
"otc-auth/src/util"
"strings"
)
Expand All @@ -23,6 +21,45 @@ var (
idTokenVerifier *oidc.IDTokenVerifier
)

const htmlFile = `
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<meta name="viewport" content="width=device-width, initial-scale=1" charset="UTF-8">
<title>Success</title>
</head>
<body style="height: 100%">
<div class="d-flex flex-column min-vh-100 justify-content-center align-items-center">
<div class="col"></div>
<div class="col-4">
<h1 class="text-center">Success!</h1><br/>
<div class="text-center" style="background-color: rgba(148, 240, 169, 0.2); padding: 1.25rem 1.25rem .25rem;border: 0.075rem solid #94F0A9;">
<i class="bi bi-check-circle-fill text-success"></i> <strong class="text-success">Signed in via your OIDC
provider</strong>
<p style="margin-top: .75rem">You can now close this window.</p>
</div>
<div class="text-center">
<img src="https://github.com/iits-consulting/otc-auth/blob/main/src/static/images/iits-logo-2021-red-square-xl.png?raw=true" width="250" style="padding: 2rem"/>
</div>
</div>
<div class="col"></div>
</div>
</body>
<footer style="width:100%; bottom: 0px; position: fixed; border-top: solid .1em; border-top-color: #DDE0E3; background-color: #F4F5F6; padding: 2em;">
<div class="row text-center">
<div class="col">
<p>Built with ❤️ by <a href="https://iits-consulting.de" target="_self">iits consulting</a></p>
</div>
<div class="col">
<p><a href="https://github.com/iits-consulting/otc-auth" target="_self"><i class="bi bi-github"></i>Github</a></p>
</div>
</div>
</footer>
</html>
`

const localhost = "localhost:8088"
const redirectURL = "http://localhost:8088/oidc/auth"

Expand Down Expand Up @@ -76,21 +113,7 @@ func startAndListenHttpServer(channel chan OIDCUsernameAndToken) {
return
}

projectDir, err := os.Getwd()
if err != nil {
util.OutputErrorToConsoleAndExit(err)
}
if !strings.HasSuffix(projectDir, "/src") {
projectDir += "/src"
}
page, err := template.ParseFiles(fmt.Sprintf("%s/static/authorized.html", projectDir))
if err != nil {
util.OutputErrorToConsoleAndExit(err)
}

if err := page.ExecuteTemplate(w, "authorized.html", nil); err != nil {
util.OutputErrorToConsoleAndExit(err)
}
w.Write([]byte(htmlFile))

if idToken != "" {
oidcUsernameAndToken.BearerToken = fmt.Sprintf("Bearer %s", idToken)
Expand Down

0 comments on commit cd6fdd1

Please sign in to comment.