Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP Metadata generation #51

Open
ekaterinasmarp opened this issue Apr 7, 2019 · 5 comments
Open

SP Metadata generation #51

ekaterinasmarp opened this issue Apr 7, 2019 · 5 comments

Comments

@ekaterinasmarp
Copy link

Hello, Is there any way I can get metadata XML string from the library? It is usually used in order to integrate with IdP and contains information like entity name, public key, assertion consumer endpoint etc.

@takuy
Copy link

takuy commented Apr 21, 2019

Hi @ekaterinasmarp, I was struggling with the same thing. After some tinkering, I think this would do it.

	sp := &saml2.SAMLServiceProvider{
		IdentityProviderSSOURL:      metadata.IDPSSODescriptor.SingleSignOnServices[0].Location,
		IdentityProviderIssuer:      metadata.EntityID,
		ServiceProviderIssuer:       "http://localhost:8080",
		AssertionConsumerServiceURL: "http://localhost:8080/v1/_saml_callback",
		SignAuthnRequests:           true,
		AudienceURI:                 "http://localhost:8080",
		IDPCertificateStore:         &certStore,
		SPKeyStore:                  LoadKeyStore("myservice.cert", "myservice.key"),
	}

	meta, err := sp.Metadata()
	xmlMeta, err := xml.Marshal(meta)

	fmt.Println(string(xmlMeta[:]))

@takuy
Copy link

takuy commented Apr 21, 2019

Though, it seems some of the Metadata generated by this library is found to be invalid by https://samltest.id/ (the replacement for testshib.org). I'll see what can be done about that.

@SeniorCluckers
Copy link

SeniorCluckers commented Apr 22, 2019

@takuy @ekaterinasmarp

I actually have it where you visit the link such as (https://domain.com/saml/metadata) it shows you the metadata xml. I tested on samltest.id and it works fine without any issues. However, I created the XML file manually using a struct. Note that I knew what my metadata file had to have based on the request response.

@takuy
Copy link

takuy commented Apr 24, 2019

@SeniorCluckers would you be able to share some sample code? Interested in how you're doing it.

@shentschel
Copy link

A little old but I had the same error on samltest. My fix:

metadata, err := sp.Service.Metadata()
if err != nil {
  return nil, err
}

// Workaround as the lib is currently marshalling to nanoseconds which cannot be used with samltest
metadata.ValidUntil = time.Now().Add(time.Hour * 24 * 7).Round(time.Millisecond)

return xml.MarshalIndent(metadata, "", "  ")

Maybe this helps somebody else with the same problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants