Skip to content

Commit 02025ee

Browse files
committed
Add support for configuring name ID format
1 parent 62898fd commit 02025ee

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Flags:
1818
-h, --help help for saml-auth-proxy
1919
--idp-ca-path string Optional path to a CA certificate PEM file for the IdP [SAML_PROXY_IDP_CA_PATH]
2020
--idp-metadata-url string URL of the IdP's metadata XML [SAML_PROXY_IDP_METADATA_URL]
21+
--name-id-format string One of unspecified, transient (default), email, or persistent to use a standard format or give a full URN of the name ID format [SAML_PROXY_NAME_ID_FORMAT]
2122
--name-id-mapping string Name of the request header to convey the SAML nameID/subject [SAML_PROXY_NAME_ID_MAPPING]
2223
--new-auth-webhook-url string URL of webhook that will get POST'ed when a new authentication is processed [SAML_PROXY_NEW_AUTH_WEBHOOK_URL]
2324
--sp-cert-path string Path to the X509 public certificate PEM file for this SP [SAML_PROXY_SP_CERT_PATH] (default "saml-auth-proxy.cert")

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func init() {
2828
rootCmd.Flags().StringVar(&serverConfig.IdpMetadataUrl, "idp-metadata-url", "", "URL of the IdP's metadata XML")
2929
rootCmd.Flags().StringVar(&serverConfig.IdpCaFile, "idp-ca-path", "",
3030
"Optional path to a CA certificate PEM file for the IdP")
31+
rootCmd.Flags().StringVar(&serverConfig.NameIdFormat, "name-id-format", "",
32+
"One of unspecified, transient (default), email, or persistent to use a standard format or give a full URN of the name ID format")
3133
rootCmd.Flags().StringVar(&serverConfig.SpKeyPath, "sp-key-path", "saml-auth-proxy.key", "Path to the X509 private key PEM file for this SP")
3234
rootCmd.Flags().StringVar(&serverConfig.SpCertPath, "sp-cert-path", "saml-auth-proxy.cert", "Path to the X509 public certificate PEM file for this SP")
3335
rootCmd.Flags().StringToStringVar(&serverConfig.AttributeHeaderMappings, "attribute-header-mappings", nil,

server/server.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/rsa"
55
"crypto/tls"
66
"crypto/x509"
7+
"github.com/crewjam/saml"
78
"github.com/crewjam/saml/samlsp"
89
"github.com/pkg/errors"
910
"io/ioutil"
@@ -18,6 +19,7 @@ type Config struct {
1819
BackendUrl string
1920
IdpMetadataUrl string
2021
IdpCaFile string
22+
NameIdFormat string
2123
SpKeyPath string
2224
SpCertPath string
2325
NameIdHeaderMapping string
@@ -63,6 +65,19 @@ func Start(cfg *Config) error {
6365
return errors.Wrap(err, "Failed to initialize SP")
6466
}
6567

68+
switch cfg.NameIdFormat {
69+
case "unspecified":
70+
samlSP.ServiceProvider.AuthnNameIDFormat = saml.UnspecifiedNameIDFormat
71+
case "transient":
72+
samlSP.ServiceProvider.AuthnNameIDFormat = saml.TransientNameIDFormat
73+
case "email":
74+
samlSP.ServiceProvider.AuthnNameIDFormat = saml.EmailAddressNameIDFormat
75+
case "persistent":
76+
samlSP.ServiceProvider.AuthnNameIDFormat = saml.PersistentNameIDFormat
77+
default:
78+
samlSP.ServiceProvider.AuthnNameIDFormat = saml.NameIDFormat(cfg.NameIdFormat)
79+
}
80+
6681
proxy, err := NewProxy(cfg)
6782
if err != nil {
6883
return errors.Wrap(err, "Failed to create proxy")

0 commit comments

Comments
 (0)