diff options
| author | mo khan <mo@mokhan.ca> | 2022-05-16 11:27:26 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2022-05-16 11:27:26 -0600 |
| commit | 6e8d8847041e053a9107e8927078a49763a524d3 (patch) | |
| tree | 94e631fa84dd943ac622af2f2aab286aed1a922d | |
| parent | 59b6a9a68bf585c5baabe57ebc5cdfe45485dcd0 (diff) | |
set audience in initial redirect to /authorize not to /token
| -rw-r--r-- | cmd/ui/main.go | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/cmd/ui/main.go b/cmd/ui/main.go index 6319b58..d125d15 100644 --- a/cmd/ui/main.go +++ b/cmd/ui/main.go @@ -40,7 +40,7 @@ func SessionFor(sessions map[string]*x.Session, r *http.Request, w http.Response func main() { sessions := map[string]*x.Session{} - godotenv.Load() + x.Check(godotenv.Load()) provider := x.Must(oidc.NewProvider(context.Background(), "https://"+os.Getenv("AUTH0_DOMAIN")+"/")) cfg := oauth2.Config{ ClientID: os.Getenv("AUTH0_CLIENT_ID"), @@ -48,9 +48,10 @@ func main() { RedirectURL: os.Getenv("AUTH0_CALLBACK_URL"), Endpoint: provider.Endpoint(), Scopes: []string{ - oidc.ScopeOpenID, - oidc.ScopeOfflineAccess, + "email", "profile", + oidc.ScopeOfflineAccess, + oidc.ScopeOpenID, }, } router := http.NewServeMux() @@ -66,7 +67,8 @@ func main() { router.Handle("/login", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := SessionFor(sessions, r, w) session.OAuthState = uuid.GenerateUUID() - http.Redirect(w, r, cfg.AuthCodeURL(session.OAuthState), http.StatusTemporaryRedirect) + url := cfg.AuthCodeURL(session.OAuthState, oauth2.SetAuthURLParam("audience", os.Getenv("AUTH0_AUDIENCE"))) + http.Redirect(w, r, url, http.StatusTemporaryRedirect) })) router.Handle("/callback", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -78,11 +80,7 @@ func main() { } client := &http.Client{Transport: x.LoggingRoundTripper{http.DefaultTransport}} - token := x.Must(cfg.Exchange( - context.WithValue(r.Context(), oauth2.HTTPClient, client), - r.URL.Query().Get("code"), - oauth2.SetAuthURLParam("audience", os.Getenv("AUTH0_AUDIENCE")), - )) + token := x.Must(cfg.Exchange(context.WithValue(r.Context(), oauth2.HTTPClient, client), r.URL.Query().Get("code"))) rawIDToken, ok := token.Extra("id_token").(string) if !ok { |
