2021-04-07 23:12:13 +00:00
|
|
|
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
|
2020-11-04 00:17:38 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
// Package auth provides a handler for the OIDC authorization endpoint.
|
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2020-11-06 22:44:58 +00:00
|
|
|
"time"
|
2020-11-04 20:19:07 +00:00
|
|
|
|
2021-01-20 17:54:44 +00:00
|
|
|
coreosoidc "github.com/coreos/go-oidc/v3/oidc"
|
2020-11-04 23:04:50 +00:00
|
|
|
"github.com/ory/fosite"
|
2020-11-06 22:44:58 +00:00
|
|
|
"github.com/ory/fosite/handler/openid"
|
|
|
|
"github.com/ory/fosite/token/jwt"
|
2021-04-09 00:28:01 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-11-11 01:58:00 +00:00
|
|
|
"golang.org/x/oauth2"
|
2021-05-27 00:04:20 +00:00
|
|
|
"k8s.io/apiserver/pkg/authentication/authenticator"
|
2020-11-11 01:58:00 +00:00
|
|
|
|
2020-11-04 00:17:38 +00:00
|
|
|
"go.pinniped.dev/internal/httputil/httperr"
|
2020-12-14 23:28:32 +00:00
|
|
|
"go.pinniped.dev/internal/httputil/securityheader"
|
2020-11-13 23:59:51 +00:00
|
|
|
"go.pinniped.dev/internal/oidc"
|
2020-11-11 01:58:00 +00:00
|
|
|
"go.pinniped.dev/internal/oidc/csrftoken"
|
2021-06-30 22:02:14 +00:00
|
|
|
"go.pinniped.dev/internal/oidc/downstreamsession"
|
2020-11-04 00:17:38 +00:00
|
|
|
"go.pinniped.dev/internal/oidc/provider"
|
2020-11-11 01:58:00 +00:00
|
|
|
"go.pinniped.dev/internal/plog"
|
2020-11-17 18:46:54 +00:00
|
|
|
"go.pinniped.dev/pkg/oidcclient/nonce"
|
|
|
|
"go.pinniped.dev/pkg/oidcclient/pkce"
|
2020-11-11 01:58:00 +00:00
|
|
|
)
|
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
const (
|
2021-05-12 20:06:08 +00:00
|
|
|
CustomUsernameHeaderName = "Pinniped-Username"
|
|
|
|
CustomPasswordHeaderName = "Pinniped-Password" //nolint:gosec // this is not a credential
|
2021-04-09 00:28:01 +00:00
|
|
|
)
|
|
|
|
|
2020-11-04 00:17:38 +00:00
|
|
|
func NewHandler(
|
2020-11-19 16:35:23 +00:00
|
|
|
downstreamIssuer string,
|
2021-04-07 23:12:13 +00:00
|
|
|
idpLister oidc.UpstreamIdentityProvidersLister,
|
2021-04-09 00:28:01 +00:00
|
|
|
oauthHelperWithoutStorage fosite.OAuth2Provider,
|
|
|
|
oauthHelperWithStorage fosite.OAuth2Provider,
|
2020-11-11 01:58:00 +00:00
|
|
|
generateCSRF func() (csrftoken.CSRFToken, error),
|
2020-11-04 00:17:38 +00:00
|
|
|
generatePKCE func() (pkce.Code, error),
|
|
|
|
generateNonce func() (nonce.Nonce, error),
|
2020-11-16 19:41:00 +00:00
|
|
|
upstreamStateEncoder oidc.Encoder,
|
|
|
|
cookieCodec oidc.Codec,
|
2020-11-04 00:17:38 +00:00
|
|
|
) http.Handler {
|
2020-12-14 23:28:32 +00:00
|
|
|
return securityheader.Wrap(httperr.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
|
2020-11-04 00:17:38 +00:00
|
|
|
if r.Method != http.MethodPost && r.Method != http.MethodGet {
|
|
|
|
// https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
|
|
|
|
// Authorization Servers MUST support the use of the HTTP GET and POST methods defined in
|
|
|
|
// RFC 2616 [RFC2616] at the Authorization Endpoint.
|
|
|
|
return httperr.Newf(http.StatusMethodNotAllowed, "%s (try GET or POST)", r.Method)
|
|
|
|
}
|
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
oidcUpstream, ldapUpstream, err := chooseUpstreamIDP(idpLister)
|
2020-11-04 20:19:07 +00:00
|
|
|
if err != nil {
|
2020-11-11 20:29:14 +00:00
|
|
|
plog.WarningErr("authorize upstream config", err)
|
2020-11-04 23:04:50 +00:00
|
|
|
return err
|
2020-11-04 20:19:07 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
if oidcUpstream != nil {
|
|
|
|
return handleAuthRequestForOIDCUpstream(r, w,
|
|
|
|
oauthHelperWithoutStorage,
|
|
|
|
generateCSRF, generateNonce, generatePKCE,
|
|
|
|
oidcUpstream,
|
|
|
|
downstreamIssuer,
|
|
|
|
upstreamStateEncoder,
|
|
|
|
cookieCodec,
|
|
|
|
)
|
2020-11-04 00:17:38 +00:00
|
|
|
}
|
2021-04-09 00:28:01 +00:00
|
|
|
return handleAuthRequestForLDAPUpstream(r, w,
|
|
|
|
oauthHelperWithStorage,
|
|
|
|
ldapUpstream,
|
|
|
|
)
|
|
|
|
}))
|
|
|
|
}
|
2020-11-04 00:17:38 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
func handleAuthRequestForLDAPUpstream(
|
|
|
|
r *http.Request,
|
|
|
|
w http.ResponseWriter,
|
|
|
|
oauthHelper fosite.OAuth2Provider,
|
|
|
|
ldapUpstream provider.UpstreamLDAPIdentityProviderI,
|
|
|
|
) error {
|
|
|
|
authorizeRequester, created := newAuthorizeRequest(r, w, oauthHelper)
|
|
|
|
if !created {
|
|
|
|
return nil
|
|
|
|
}
|
2020-11-04 00:17:38 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
username := r.Header.Get(CustomUsernameHeaderName)
|
|
|
|
password := r.Header.Get(CustomPasswordHeaderName)
|
|
|
|
if username == "" || password == "" {
|
|
|
|
// Return an error according to OIDC spec 3.1.2.6 (second paragraph).
|
|
|
|
err := errors.WithStack(fosite.ErrAccessDenied.WithHintf("Missing or blank username or password."))
|
2021-04-20 00:59:46 +00:00
|
|
|
plog.Info("authorize response error", oidc.FositeErrorForLog(err)...)
|
2021-04-09 00:28:01 +00:00
|
|
|
oauthHelper.WriteAuthorizeError(w, authorizeRequester, err)
|
|
|
|
return nil
|
|
|
|
}
|
2020-11-04 00:17:38 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
authenticateResponse, authenticated, err := ldapUpstream.AuthenticateUser(r.Context(), username, password)
|
|
|
|
if err != nil {
|
2021-04-13 23:22:13 +00:00
|
|
|
plog.WarningErr("unexpected error during upstream LDAP authentication", err, "upstreamName", ldapUpstream.GetName())
|
2021-04-09 00:28:01 +00:00
|
|
|
return httperr.New(http.StatusBadGateway, "unexpected error during upstream authentication")
|
|
|
|
}
|
|
|
|
if !authenticated {
|
2021-04-13 23:22:13 +00:00
|
|
|
plog.Debug("failed upstream LDAP authentication", "upstreamName", ldapUpstream.GetName())
|
2021-04-09 00:28:01 +00:00
|
|
|
// Return an error according to OIDC spec 3.1.2.6 (second paragraph).
|
|
|
|
err = errors.WithStack(fosite.ErrAccessDenied.WithHintf("Username/password not accepted by LDAP provider."))
|
2021-04-20 00:59:46 +00:00
|
|
|
plog.Info("authorize response error", oidc.FositeErrorForLog(err)...)
|
2021-04-09 00:28:01 +00:00
|
|
|
oauthHelper.WriteAuthorizeError(w, authorizeRequester, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-30 22:02:14 +00:00
|
|
|
openIDSession := downstreamsession.MakeDownstreamSession(
|
|
|
|
downstreamSubjectFromUpstreamLDAP(ldapUpstream, authenticateResponse),
|
|
|
|
authenticateResponse.User.GetName(),
|
|
|
|
authenticateResponse.User.GetGroups(),
|
|
|
|
)
|
2021-04-09 00:28:01 +00:00
|
|
|
|
|
|
|
authorizeResponder, err := oauthHelper.NewAuthorizeResponse(r.Context(), authorizeRequester, openIDSession)
|
|
|
|
if err != nil {
|
|
|
|
plog.Info("authorize response error", oidc.FositeErrorForLog(err)...)
|
|
|
|
oauthHelper.WriteAuthorizeError(w, authorizeRequester, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
oauthHelper.WriteAuthorizeResponse(w, authorizeRequester, authorizeResponder)
|
2021-06-30 22:02:14 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleAuthRequestForOIDCUpstream(
|
|
|
|
r *http.Request,
|
|
|
|
w http.ResponseWriter,
|
|
|
|
oauthHelper fosite.OAuth2Provider,
|
|
|
|
generateCSRF func() (csrftoken.CSRFToken, error),
|
|
|
|
generateNonce func() (nonce.Nonce, error),
|
|
|
|
generatePKCE func() (pkce.Code, error),
|
|
|
|
oidcUpstream provider.UpstreamOIDCIdentityProviderI,
|
|
|
|
downstreamIssuer string,
|
|
|
|
upstreamStateEncoder oidc.Encoder,
|
|
|
|
cookieCodec oidc.Codec,
|
|
|
|
) error {
|
|
|
|
authorizeRequester, created := newAuthorizeRequest(r, w, oauthHelper)
|
|
|
|
if !created {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
_, err := oauthHelper.NewAuthorizeResponse(r.Context(), authorizeRequester, &openid.DefaultSession{
|
|
|
|
Claims: &jwt.IDTokenClaims{
|
|
|
|
// Temporary claim values to allow `NewAuthorizeResponse` to perform other OIDC validations.
|
|
|
|
Subject: "none",
|
|
|
|
AuthTime: now,
|
|
|
|
RequestedAt: now,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
plog.Info("authorize response error", oidc.FositeErrorForLog(err)...)
|
|
|
|
oauthHelper.WriteAuthorizeError(w, authorizeRequester, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
csrfValue, nonceValue, pkceValue, err := generateValues(generateCSRF, generateNonce, generatePKCE)
|
|
|
|
if err != nil {
|
|
|
|
plog.Error("authorize generate error", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
csrfFromCookie := readCSRFCookie(r, cookieCodec)
|
|
|
|
if csrfFromCookie != "" {
|
|
|
|
csrfValue = csrfFromCookie
|
|
|
|
}
|
|
|
|
|
|
|
|
upstreamOAuthConfig := oauth2.Config{
|
|
|
|
ClientID: oidcUpstream.GetClientID(),
|
|
|
|
Endpoint: oauth2.Endpoint{
|
|
|
|
AuthURL: oidcUpstream.GetAuthorizationURL().String(),
|
|
|
|
},
|
|
|
|
RedirectURL: fmt.Sprintf("%s/callback", downstreamIssuer),
|
|
|
|
Scopes: oidcUpstream.GetScopes(),
|
|
|
|
}
|
|
|
|
|
|
|
|
encodedStateParamValue, err := upstreamStateParam(
|
|
|
|
authorizeRequester,
|
|
|
|
oidcUpstream.GetName(),
|
|
|
|
nonceValue,
|
|
|
|
csrfValue,
|
|
|
|
pkceValue,
|
|
|
|
upstreamStateEncoder,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
plog.Error("authorize upstream state param error", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if csrfFromCookie == "" {
|
|
|
|
// We did not receive an incoming CSRF cookie, so write a new one.
|
|
|
|
err := addCSRFSetCookieHeader(w, csrfValue, cookieCodec)
|
2020-11-11 20:29:14 +00:00
|
|
|
if err != nil {
|
2021-04-09 00:28:01 +00:00
|
|
|
plog.Error("error setting CSRF cookie", err)
|
2020-11-11 20:29:14 +00:00
|
|
|
return err
|
2020-11-11 01:58:00 +00:00
|
|
|
}
|
2021-04-09 00:28:01 +00:00
|
|
|
}
|
2020-11-11 20:29:14 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
authCodeOptions := []oauth2.AuthCodeOption{
|
|
|
|
oauth2.AccessTypeOffline,
|
|
|
|
nonceValue.Param(),
|
|
|
|
pkceValue.Challenge(),
|
|
|
|
pkceValue.Method(),
|
|
|
|
}
|
2020-11-11 01:58:00 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
promptParam := r.Form.Get("prompt")
|
|
|
|
if promptParam != "" && oidc.ScopeWasRequested(authorizeRequester, coreosoidc.ScopeOpenID) {
|
|
|
|
authCodeOptions = append(authCodeOptions, oauth2.SetAuthURLParam("prompt", promptParam))
|
|
|
|
}
|
2020-12-12 01:13:27 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
http.Redirect(w, r,
|
|
|
|
upstreamOAuthConfig.AuthCodeURL(
|
|
|
|
encodedStateParamValue,
|
|
|
|
authCodeOptions...,
|
|
|
|
),
|
|
|
|
302,
|
|
|
|
)
|
2020-12-12 01:13:27 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-11-04 00:17:38 +00:00
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
func newAuthorizeRequest(r *http.Request, w http.ResponseWriter, oauthHelper fosite.OAuth2Provider) (fosite.AuthorizeRequester, bool) {
|
|
|
|
authorizeRequester, err := oauthHelper.NewAuthorizeRequest(r.Context(), r)
|
|
|
|
if err != nil {
|
|
|
|
plog.Info("authorize request error", oidc.FositeErrorForLog(err)...)
|
|
|
|
oauthHelper.WriteAuthorizeError(w, authorizeRequester, err)
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
2021-06-30 22:02:14 +00:00
|
|
|
// Automatically grant the openid, offline_access, and pinniped:request-audience scopes, but only if they were requested.
|
2021-04-09 00:28:01 +00:00
|
|
|
// Grant the openid scope (for now) if they asked for it so that `NewAuthorizeResponse` will perform its OIDC validations.
|
|
|
|
// There don't seem to be any validations inside `NewAuthorizeResponse` related to the offline_access scope
|
|
|
|
// at this time, however we will temporarily grant the scope just in case that changes in a future release of fosite.
|
2021-06-30 22:02:14 +00:00
|
|
|
downstreamsession.GrantScopesIfRequested(authorizeRequester)
|
|
|
|
|
|
|
|
return authorizeRequester, true
|
2020-11-04 00:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 01:20:57 +00:00
|
|
|
func readCSRFCookie(r *http.Request, codec oidc.Decoder) csrftoken.CSRFToken {
|
2020-11-16 16:47:49 +00:00
|
|
|
receivedCSRFCookie, err := r.Cookie(oidc.CSRFCookieName)
|
2020-11-12 23:36:59 +00:00
|
|
|
if err != nil {
|
|
|
|
// Error means that the cookie was not found
|
2020-11-20 21:56:35 +00:00
|
|
|
return ""
|
2020-11-12 23:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var csrfFromCookie csrftoken.CSRFToken
|
2020-11-16 16:47:49 +00:00
|
|
|
err = codec.Decode(oidc.CSRFCookieEncodingName, receivedCSRFCookie.Value, &csrfFromCookie)
|
2020-11-12 23:36:59 +00:00
|
|
|
if err != nil {
|
2020-11-20 21:56:35 +00:00
|
|
|
// We can ignore any errors and just make a new cookie. Hopefully this will
|
|
|
|
// make the user experience better if, for example, the server rotated
|
|
|
|
// cookie signing keys and then a user submitted a very old cookie.
|
|
|
|
return ""
|
2020-11-12 23:36:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 21:56:35 +00:00
|
|
|
return csrfFromCookie
|
2020-11-12 23:36:59 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 00:28:01 +00:00
|
|
|
// Select either an OIDC or an LDAP IDP, or return an error.
|
|
|
|
func chooseUpstreamIDP(idpLister oidc.UpstreamIdentityProvidersLister) (provider.UpstreamOIDCIdentityProviderI, provider.UpstreamLDAPIdentityProviderI, error) {
|
|
|
|
oidcUpstreams := idpLister.GetOIDCIdentityProviders()
|
|
|
|
ldapUpstreams := idpLister.GetLDAPIdentityProviders()
|
|
|
|
switch {
|
|
|
|
case len(oidcUpstreams)+len(ldapUpstreams) == 0:
|
|
|
|
return nil, nil, httperr.New(
|
2020-11-04 00:17:38 +00:00
|
|
|
http.StatusUnprocessableEntity,
|
|
|
|
"No upstream providers are configured",
|
|
|
|
)
|
2021-04-09 00:28:01 +00:00
|
|
|
case len(oidcUpstreams)+len(ldapUpstreams) > 1:
|
2020-12-15 18:49:13 +00:00
|
|
|
var upstreamIDPNames []string
|
2021-04-09 00:28:01 +00:00
|
|
|
for _, idp := range oidcUpstreams {
|
|
|
|
upstreamIDPNames = append(upstreamIDPNames, idp.GetName())
|
|
|
|
}
|
|
|
|
for _, idp := range ldapUpstreams {
|
2020-12-15 18:49:13 +00:00
|
|
|
upstreamIDPNames = append(upstreamIDPNames, idp.GetName())
|
|
|
|
}
|
|
|
|
plog.Warning("Too many upstream providers are configured (found: %s)", upstreamIDPNames)
|
2021-04-09 00:28:01 +00:00
|
|
|
return nil, nil, httperr.New(
|
2020-11-04 00:17:38 +00:00
|
|
|
http.StatusUnprocessableEntity,
|
|
|
|
"Too many upstream providers are configured (support for multiple upstreams is not yet implemented)",
|
|
|
|
)
|
2021-04-09 00:28:01 +00:00
|
|
|
case len(oidcUpstreams) == 1:
|
|
|
|
return oidcUpstreams[0], nil, nil
|
|
|
|
default:
|
|
|
|
return nil, ldapUpstreams[0], nil
|
2020-11-04 00:17:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-11 01:58:00 +00:00
|
|
|
func generateValues(
|
|
|
|
generateCSRF func() (csrftoken.CSRFToken, error),
|
2020-11-04 00:17:38 +00:00
|
|
|
generateNonce func() (nonce.Nonce, error),
|
|
|
|
generatePKCE func() (pkce.Code, error),
|
2020-11-11 01:58:00 +00:00
|
|
|
) (csrftoken.CSRFToken, nonce.Nonce, pkce.Code, error) {
|
|
|
|
csrfValue, err := generateCSRF()
|
2020-11-04 00:17:38 +00:00
|
|
|
if err != nil {
|
2020-11-11 01:58:00 +00:00
|
|
|
return "", "", "", httperr.Wrap(http.StatusInternalServerError, "error generating CSRF token", err)
|
2020-11-04 00:17:38 +00:00
|
|
|
}
|
|
|
|
nonceValue, err := generateNonce()
|
|
|
|
if err != nil {
|
|
|
|
return "", "", "", httperr.Wrap(http.StatusInternalServerError, "error generating nonce param", err)
|
|
|
|
}
|
|
|
|
pkceValue, err := generatePKCE()
|
|
|
|
if err != nil {
|
|
|
|
return "", "", "", httperr.Wrap(http.StatusInternalServerError, "error generating PKCE param", err)
|
|
|
|
}
|
2020-11-11 01:58:00 +00:00
|
|
|
return csrfValue, nonceValue, pkceValue, nil
|
2020-11-04 00:17:38 +00:00
|
|
|
}
|
2020-11-10 18:33:52 +00:00
|
|
|
|
2020-11-11 20:29:14 +00:00
|
|
|
func upstreamStateParam(
|
|
|
|
authorizeRequester fosite.AuthorizeRequester,
|
2020-11-20 21:14:45 +00:00
|
|
|
upstreamName string,
|
2020-11-11 20:29:14 +00:00
|
|
|
nonceValue nonce.Nonce,
|
|
|
|
csrfValue csrftoken.CSRFToken,
|
|
|
|
pkceValue pkce.Code,
|
2020-11-16 19:41:00 +00:00
|
|
|
encoder oidc.Encoder,
|
2020-11-11 20:29:14 +00:00
|
|
|
) (string, error) {
|
2020-11-16 19:41:00 +00:00
|
|
|
stateParamData := oidc.UpstreamStateParamData{
|
|
|
|
AuthParams: authorizeRequester.GetRequestForm().Encode(),
|
2020-11-20 21:14:45 +00:00
|
|
|
UpstreamName: upstreamName,
|
2020-11-16 19:41:00 +00:00
|
|
|
Nonce: nonceValue,
|
|
|
|
CSRFToken: csrfValue,
|
|
|
|
PKCECode: pkceValue,
|
|
|
|
FormatVersion: oidc.UpstreamStateParamFormatVersion,
|
2020-11-11 20:29:14 +00:00
|
|
|
}
|
2020-11-16 19:41:00 +00:00
|
|
|
encodedStateParamValue, err := encoder.Encode(oidc.UpstreamStateParamEncodingName, stateParamData)
|
2020-11-11 20:29:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", httperr.Wrap(http.StatusInternalServerError, "error encoding upstream state param", err)
|
|
|
|
}
|
|
|
|
return encodedStateParamValue, nil
|
|
|
|
}
|
|
|
|
|
2020-12-10 01:20:57 +00:00
|
|
|
func addCSRFSetCookieHeader(w http.ResponseWriter, csrfValue csrftoken.CSRFToken, codec oidc.Encoder) error {
|
2020-11-16 16:47:49 +00:00
|
|
|
encodedCSRFValue, err := codec.Encode(oidc.CSRFCookieEncodingName, csrfValue)
|
2020-11-12 23:36:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return httperr.Wrap(http.StatusInternalServerError, "error encoding CSRF cookie", err)
|
|
|
|
}
|
|
|
|
|
2020-11-11 20:29:14 +00:00
|
|
|
http.SetCookie(w, &http.Cookie{
|
2020-11-16 16:47:49 +00:00
|
|
|
Name: oidc.CSRFCookieName,
|
2020-11-12 23:36:59 +00:00
|
|
|
Value: encodedCSRFValue,
|
2020-11-11 20:29:14 +00:00
|
|
|
HttpOnly: true,
|
2020-12-04 03:23:58 +00:00
|
|
|
SameSite: http.SameSiteLaxMode,
|
2020-11-11 20:29:14 +00:00
|
|
|
Secure: true,
|
2020-12-01 23:01:22 +00:00
|
|
|
Path: "/",
|
2020-11-11 20:29:14 +00:00
|
|
|
})
|
2020-11-12 23:36:59 +00:00
|
|
|
|
|
|
|
return nil
|
2020-11-11 20:29:14 +00:00
|
|
|
}
|
2021-05-27 00:04:20 +00:00
|
|
|
|
|
|
|
func downstreamSubjectFromUpstreamLDAP(ldapUpstream provider.UpstreamLDAPIdentityProviderI, authenticateResponse *authenticator.Response) string {
|
|
|
|
ldapURL := *ldapUpstream.GetURL()
|
|
|
|
q := ldapURL.Query()
|
|
|
|
q.Set(oidc.IDTokenSubjectClaim, authenticateResponse.User.GetUID())
|
|
|
|
ldapURL.RawQuery = q.Encode()
|
|
|
|
return ldapURL.String()
|
|
|
|
}
|