Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="bcls-section">
  <h2 id="app">Get an Access Token</h2>

  <fieldset>
    <legend>Inputs</legend>

    <p>Client ID: <input id="clientId" type="text" size="50" /></p>

    <p>Client Secret: <input id="clientSecret" type="text" size="50" /></p>

    <p><button id="submitButton" class="bcls-button">Get Access Token</button></p>
  </fieldset>

  <fieldset>
    <legend>Output</legend>

    <h3>Access token</h3>
    <textarea name="accessToken" id="accessToken" class="bcls-code">Access token will appear here...</textarea>

    <h3>Full response</h3>

    <pre class="line-numbers">
<code id="apiResponse" class="language-json">Full API response will appear here...</code></pre>
  </fieldset>
</section>
              
            
!

CSS

              
                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #f5f5f5;
  font-family: sans-serif;
  margin: 2em;
}
/*
 * Styles essential to the sample
 * are below
 */
.bcls-code {
  color: #111;
  font-family: monospace;
  padding: 1em;
  width: 90%;
  min-height: 5em;
  background-color: #fff;
  font-size: 1rem;
}
.bcls-button {
  padding: .5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: .5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64AAB2;
  border: 1px #64AAB2 solid;
  border-radius: .5em;
}
code {
  color: #E4B842;
  font-family: monospace;
}
              
            
!

JS

              
                var BCLS = ( function (window, document) {
  var clientId   = document.getElementById('clientId'),
    clientSecret = document.getElementById('clientSecret'),
    submitButton = document.getElementById('submitButton'),
    accessToken  = document.getElementById('accessToken'),
    apiResponse  = document.getElementById('apiResponse'),
    options      = {},
    proxyURL     = 'https://solutions.brightcove.com/bcls/bcls-proxy/access-token-proxy.php',
    access_token;

// event handlers
submitButton.addEventListener('click', function() {
  var responseParsed;
  if (isDefined(clientId.value) && isDefined(clientSecret.value)) {
    options.client_id     = clientId.value;
    options.client_secret = clientSecret.value;
    makeRequest(options, function(response) {
      if (isJson(response)) {
        responseParsed          = JSON.parse(response);
        access_token            = responseParsed.access_token;
        accessToken.textContent = access_token;
        apiResponse.textContent = JSON.stringify(responseParsed, null, '  ');
      } else {
        // didn't get JSON back, just dump responseRaw
        apiResponse.textContent = response;
      }
    });
  } else {
    alert('Client id and secret are required.');
  }
});

accessToken.addEventListener('click', function() {
  this.select();
});

/**
 * tests for all the ways a variable might be undefined or not have a value
 * @param {*} x the variable to test
 * @return {Boolean} true if variable is defined and has a value
 */
function isDefined(x) {
    if ( x === '' || x === null || x === undefined) {
        return false;
    }
    return true;
}

/*
 * tests to see if a string is json
 * @param {String} str string to test
 * @return {Boolean}
 */
function isJson(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}

/**
 * send API request to the proxy
 * @param  {Object} options options for the request
 * @param  {String} requestID the type of request = id of the button
 * @param  {Function} [callback] callback function
 */
function makeRequest(options, callback) {
  var httpRequest = new XMLHttpRequest(),
    responseRaw,
    requestParams,
    // response handler
    getResponse = function() {
      try {
        if (httpRequest.readyState === 4) {
          if (httpRequest.status >= 200 && httpRequest.status < 300) {
            // check for completion
            responseRaw = httpRequest.responseText;
            callback(responseRaw);
          }
        }
      } catch (e) {
        alert('Caught Exception: ' + e);
      }
    };
  // set up request data
  requestParams = 'client_id=' + options.client_id + '&client_secret=' + options.client_secret;

  // set response handler
  httpRequest.onreadystatechange = getResponse;
  // open the request
  httpRequest.open('POST', proxyURL);
  // set headers
  httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  // open and send request
  httpRequest.send(requestParams);
}

})(window, document);

              
            
!
999px

Console