Skip to content

ma314smith/go-wsfed

Repository files navigation

go-wsfed

GoDoc

The wsfed package provides functionality for:

  • Generating a redirect url to an IDP
  • Parsing Tokens generated by an IDP (currently only SAML v1.1 Tokens are supported since that was my specific use case, but it wouldn't take much work to add other Tokens)

Install

go get github.com/ma314smith/go-wsfed

Examples

Configuration

  config = wsfed.Config{}
  // set the metatdata url for the IDP (alternatively set the IDPEndpoint)
	config.MetadataURL = "https://idp.example.com/wsfederation/metadata"
  // trust the certs in the metadata (alternatively set the TrustedCerts)
	config.MetadataCertsAreTrusted = true
  // poll the metadata once a week to check for any new certificates.
  // the default is 0 seconds, which never refreshes after the initial poll
	config.MetadataRefreshIntervalSeconds = 604800
  // set your realm
	config.Realm = "http://realm.example.com"
  // use your config to create a new WSFed object
	sso = wsfed.New(&config)

Get the Request URL for the IDP

// get the default request parameters (wa, wtrealm, wct) or create your own
rp := sso.GetDefaultRequestParameters()
// pass the RequestParameters to GetRequestURL
url, err := sso.GetRequestURL(rp)

Parse Claims asserted by the IDP

// get the wresult parameter from the IDP POST
wresult := r.PostFormValue("wresult")
// pass the wresult to ParseResponse
claims, err := sso.ParseResponse(wresult)

Contributions

Contributions are welcome. Just fork the repo and send a pull request.

About

Go (golang) library for generating WS-Fed requests and parsing tokens

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages