-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Victor Getz
committed
Nov 25, 2022
1 parent
0c3fa0e
commit cd6fdd1
Showing
1 changed file
with
40 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
@@ -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" | ||
|
||
|
@@ -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) | ||
|