SINGLE SIGN-ON

Integrating with your identity management

Civil offers single sign-on (SSO) to allow your users to log in directly to your site and seamlessly use Civil Comments with the same account.

Including SSO on your page

Once you have subscribed to the Civil SSO integration, include the following Javascript call after the embed code.

Civil({
  provider: 'myProvider',
  login: myLoginFunction,
  logout: myLogoutFunction,
  getUser: myGetUserFunction,
});

Parameters

provider string

The authentication provider ID. Currently, Civil supports Gigya and custom authentication using JSON Web Tokens.

gigya Gigya

jwt Custom authentication with JSON Web Tokens


getUser function

A function that returns the current authenticated user. getUser can return the user directly or call a callback for asynchronous methods.

Synchronous Example
function getUser() {
  return {
    id: "thetruthisoutthere",
    handle: "Fox Mulder",
    email: "[email protected]",
  };
}
Asynchronous Example
function getUser(callback) {
  doSomethingAsync()
  .then(function(user){
    callback(null, {
      id: user.id,
      handle: user.name,
      email: user.email,
    });
  });
}

Note: callback expects error as the first parameter and success as the second.

Gigya example
function getUser(callback) {
  gigya.socialize.getUserInfo({
    callback: function(res) {
      callback(null, {
        UID: res.user.UID,
        UIDSignature: res.user.UIDSignature,
        signatureTimestamp: res.user.signatureTimestamp,
      });
    }
  });
}
JWT Example
function getUser() {
  return {
    token: "eyJhbGciOiJIUzI1NiIs..."
  };
}


login function

The function used on your site to open the log in modal and log in or sign up the user. login is passed a callback as the first parameter. callback expects error as the first parameter and success as the second.

Gigya example
function login(callback) {
  var options = {
    buttonsStyle: 'fullLogoColored',
    callback: function(res) {
      callback(null, {
        UID: res.UID,
        UIDSignature: res.UIDSignature,
        signatureTimestamp: res.signatureTimestamp,
      });
    },
    screenSet: 'Default-RegistrationLogin',
    redirectURL: 'http://localhost:5001',
  };
  window.gigya.accounts.showScreenSet(options);
}
JWT example
function login(callback) {
  openMyLoginModal()
  .then(function(user){
    callback(null, {
      token: "eyJhbGciOiJIUzI1NiIs..."
    });
  });
}


logout function

The function used on your site to log the user out. logout is passed a callback as the first parameter. callback expects error as the first parameter if the logout failed.

function logout(callback) {
  myLogOutFunction();
  callback();
}

Full Embed Demo View (Gigya)
<div id="civil-comments"></div>
<script>
  (function(c, o, mm, e, n, t, s){
    c[n] = c[n] || function() {
      var args = [].slice.call(arguments);
      (c[n].q = c[n].q || []).push(args);
      if (c[n].r) return;
      t = o.createElement(mm);
      s = o.getElementsByTagName(mm)[0];
      t.async = 1;
      t.src = [e].concat(args.map(encodeURIComponent)).join("/");
      s.parentNode.insertBefore(t, s);
      c[n].r = 1;
    };
    c["CivilCommentsObject"] = c[n];
  })(window, document, "script", "https://ssr.civilcomments.com/v1", "Civil");

  Civil('1', 'the-demo-times', 'en');
  Civil({
    provider: 'gigya',
    getUser: gigyaCurrentUser,
    login: gigyaLogin,
    logout: gigyaLogout,
  });
</script>

results matching ""

    No results matching ""