-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow IAP auth through idtoken from service account * Refactor ExecAllocatorOption setup into a utility function to fix duplication warning. Also allow self signed certificate for all login methods Co-authored-by: Brian Gann <[email protected]>
- Loading branch information
1 parent
81491b1
commit de05036
Showing
9 changed files
with
146 additions
and
61 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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package kiosk | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"github.com/chromedp/cdproto/cdp" | ||
"github.com/chromedp/cdproto/fetch" | ||
|
||
"github.com/chromedp/chromedp" | ||
|
||
"google.golang.org/api/idtoken" | ||
) | ||
|
||
// GrafanaKioskGenericOauth creates a chrome-based kiosk using a oauth2 authenticated account | ||
func GrafanaKioskIdToken(cfg *Config) { | ||
dir, err := ioutil.TempDir("", "chromedp-example") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer os.RemoveAll(dir) | ||
|
||
opts := generateExecutorOptions(dir, cfg.General.WindowPosition, cfg.Target.IgnoreCertificateErrors) | ||
|
||
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...) | ||
defer cancel() | ||
|
||
// also set up a custom logger | ||
taskCtx, cancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(log.Printf)) | ||
defer cancel() | ||
|
||
listenChromeEvents(taskCtx, targetCrashed) | ||
|
||
// ensure that the browser process is started | ||
if err := chromedp.Run(taskCtx); err != nil { | ||
panic(err) | ||
} | ||
|
||
var generatedURL = GenerateURL(cfg.Target.URL, cfg.General.Mode, cfg.General.AutoFit, cfg.Target.IsPlayList) | ||
log.Println("Navigating to ", generatedURL) | ||
|
||
log.Printf("Token is using audience %s and reading from %s\n",cfg.IDTOKEN.Audience, cfg.IDTOKEN.KeyFile) | ||
ts, err := idtoken.NewTokenSource(context.Background(), cfg.IDTOKEN.Audience, idtoken.WithCredentialsFile(cfg.IDTOKEN.KeyFile)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
chromedp.ListenTarget(taskCtx, func(ev interface{}) { | ||
switch ev := ev.(type) { | ||
case *fetch.EventRequestPaused: | ||
go func() { | ||
fetchReq := fetch.ContinueRequest(ev.RequestID) | ||
for k, v := range ev.Request.Headers { | ||
fetchReq.Headers = append(fetchReq.Headers, &fetch.HeaderEntry{Name: k, Value: fmt.Sprintf("%v", v)}) | ||
} | ||
token, err := ts.Token() | ||
if err != nil { | ||
panic(fmt.Errorf("idtoken.NewClient: %v", err)) | ||
} | ||
fetchReq.Headers = append(fetchReq.Headers, &fetch.HeaderEntry{Name: "Authorization", Value: "Bearer " + token.AccessToken}) | ||
fetchReq.Do(GetExecutor(taskCtx)) | ||
}() | ||
} | ||
}) | ||
|
||
if err := chromedp.Run(taskCtx, enableFetch(generatedURL)); err != nil { | ||
panic(err) | ||
} | ||
log.Println("Sleeping 2 seconds before exit.") | ||
time.Sleep(2 * time.Second) | ||
log.Println("Exit...") | ||
} | ||
|
||
func GetExecutor(ctx context.Context) context.Context { | ||
c := chromedp.FromContext(ctx) | ||
return cdp.WithExecutor(ctx, c.Target) | ||
} | ||
|
||
|
||
func enableFetch(url string) chromedp.Tasks { | ||
return chromedp.Tasks{ | ||
fetch.Enable(), | ||
chromedp.Navigate(url), | ||
chromedp.WaitVisible("notinputPassword", chromedp.ByID), | ||
} | ||
} |
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
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