 
     # -- Optional
     # Returns a redirect URL, at which a user is logged out.
-    create_logout_url: (identity_provider, name_id, session_index, cb) =>
+    create_logout_url: (identity_provider, name_id, session_index, relay_state..., cb) =>
+      relay_state = relay_state[0]
       xml = create_logout_request @issuer, name_id, session_index, identity_provider.sso_logout_url
       zlib.deflateRaw xml, (err, deflated) =>
         return cb err if err?
         uri = url.parse identity_provider.sso_logout_url
-        uri.query = sign_get_request deflated.toString('base64'), @private_key
+        uri.query = sign_get_request deflated.toString('base64'), @private_key, relay_state
         cb null, url.format(uri)
+
+    create_logout_response_url: (in_response_to, logout_url, cb) ->
+      xml = create_logout_response @issuer, "success", in_response_to, logout_url
+      zlib.deflateRaw xml, (err, deflated) =>
+        return cb err if err?
+        uri = url.parse logout_url
+        uri.query = sign_get_response deflated.toString('base64'), @private_key
+        cb null, url.format(uri)
+      # create_logout_response
 
     # Returns XML metadata, used during initial SAML configuration
     create_metadata: (assert_endpoint) =>

      'samlp:SessionIndex': session_index
  .end()

# Takes a base64 encoded @key and returns it formatted with newlines and a PEM header according to @type. If it already
# has a PEM header, it will just return the original key.
format_pem = (key, type) ->

            when saml_response.getElementsByTagNameNS(XMLNS.SAMLP, 'LogoutResponse').length is 1
              response.type = 'logout_response'
              setImmediate cb_wf, null, {}
            when saml_response.getElementsByTagNameNS(XMLNS.SAMLP, 'LogoutRequest').length is 1
              response.type = 'logout_request'
              setImmediate cb_wf, null, parse_logout_request saml_response
        (result, cb_wf) ->
          _.extend response, result
          cb_wf null, response
