Setting up a login page for account linking

This topic describes what is required on the account linked login page.

Note: For background information, see Account linking.

Required functions

You need to implement the following functions to:

  • Extract a given parameter from the current URL. The browser will use this to obtain the URL of the back-end instance. The instance URL is passed in the instance query parameter.
  • Perform an HTTP redirect to the Converse authorize endpoint that will close the tab or pop-up after successful authentication, using the encoded redirect URL and the authorization code or token given by the back-end system.
  • Get the credentials entered by the user, and request authentication from the instance configured in the Account Link button.

Example

This example outlines how you might implement these functions. In this example <bot URL> is the URL of the server hosting the bot, such as https://designer.converse.pitneybowes.com

<script >
function getParameterByName(name) {
	var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
	return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

function doRedirect(authCode) {
	var uri = decodeURIComponent(getParameterByName("redirect_uri"));
	window.location.replace("<bot URL>/authorize?redirect_uri=" 
                                + encodeURI(uri + "&authorization_code=" + authCode));
}

function getAuthentication(){
        var body = {
            //get user credentials from login page
        }
        var url = getParameterByName("instance")

        //set up request etc
}
</script>