Listing 1

try
{
  if (ConfluenceConfiguration.Instance.UseSso)
  {
    if (
      !this.Page.ClientScript.IsStartupScriptRegistered("Confluence"))
    {
      //Reserve a credential ticket from SSO Service
      string ssoTicket = null;
      Credentials.ReserveCredentialTicket(
          Credentials.SingleSignonTicketType.Default,
          ref ssoTicket);

      this.Page.ClientScript.RegisterClientScriptBlock(
        typeof(System.Web.UI.Page), "Confluence",
      String.Format(SsoClientScriptFormatted,
      HttpUtility.UrlEncode(ssoTicket)), true);
    }
  }
}
catch (SingleSignonException singleSignOnEx)
{
  //Swallow this exception, we will not be generating a
  //ClientScriptBlock for client-side authentication...
}


Listing 2

var xmlHttp;
function createXMLHttpRequest()
{ 
  if (window.ActiveXObject)
  {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if(window.XMLHttpRequest)
  {
    xmlHttp = new XMLHttpRequest();
  }
}

function getCredentials()
{
  url = "_layouts/Atlassian/ConfluenceSettings.aspx?getCredentials=true&id=<ticket>;
  xmlHttp.open('GET',url,true);
  xmlHttp.onreadystatechange=sendAuthRequest;
  xmlHttp.send(null);
  return false;
}

function sendAuthRequest()
{
  if (xmlHttp.readyState==4)
  {
    xmlHttp.open('GET', xmlHttp.responseText, false);
    xmlHttp.send(null);
  }
}

createXMLHttpRequest();
getCredentials();


Listing 3

try
{
  RemotePage page = ConfluenceHelper.GetConfluencePage(this.PageId);
  ...
}
catch (SingleSignonException singleSignOnEx)
{
  int ssoErrorCode = singleSignOnEx.LastErrorCode;

  if (ssoErrorCode == SSOReturnCodes.SSO_E_CREDS_NOT_FOUND)
  {
    try
    {
      ISsoProvider provider = SsoProviderFactory.GetSsoProvider();
      string strSSOLogonFormUrl = provider.GetCredentialManagementURL(
        ConfluenceConfiguration.Instance.SsoApplicationName).
        AbsoluteUri;
      pageContent = "Click <b><a href=" + strSSOLogonFormUrl +
        ">here</a></b> to save your credentials for the Confluence Application.";
    }
    catch
    {
      pageContent = "Credentials not found.";
    }
  }
}


Listing 4

//Check to see if the request is for ticket redemption
//for user credentials
if (Page.Request.QueryString.ToString().ToLower().
    Contains("getcredentials"))
{
  //Make sure the user has been authenticated and pull the SSO
  //credentials for the ticket and verify they match the current user
  ...

  string ssoTicket =
    HttpUtility.UrlDecode(Page.Request.QueryString["id"]);
  //Correct for loss of "+" during encoding/decoding...
  ssoTicket = ssoTicket.Replace(" ", "+");

  SPSecurity.RunWithElevatedPrivileges(
    delegate()
    {
      using (SPSite site = new SPSite(Web.Site.ID))
      {
        using (SPWeb Web = site.OpenWeb())
        {
          //Retrieve the credentials using the ticket
          Sso.Credentials.GetCredentialsUsingTicket(
            0,
            ConfluenceConfiguration.Instance.SsoApplicationName,
            ssoTicket,
            ref rgTicketCreds);
        }
      }
    }
  );

  if (userName != string.Empty && password != string.Empty)
  {
    if (userName == rgTicketCreds[0] && password == rgTicketCreds[1])
    {
      Page.Response.Write(string.Format(
        ConfluenceConfiguration.Instance.ConfluenceSite +
        "/login.action?os_username={0}&os_password={1}&login=Log+In&os_destination=",
        rgTicketCreds[0], rgTicketCreds[1]));
    }
  }

  Page.Response.End();
}