<commit_before>{% extends "base.html" %}


{% block main %}
<div class="content">
   <div class="content-developer">
    <h1>Hey Developers!</h1>
    <p>
    <a href="/developers/apps">Your Apps</a>
    </p>
    <h2>Steps To Creating A MLTSHP Application</h2>
    <p>
      To get started first <a href="/developers/new-api-application">register an application</a>. You'll need to
      enter a title, description, and also a redirect URL.
      This URL will be where users of your app will be sent after approving your app to access their account.
    </p>
      Once that is done you will be given an API key and a secret. We are using draft 12 of the new <b>OAuth2</b> specification.
      If you want to read the gory details they are all here: <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-12">http://tools.ietf.org/html/draft-ietf-oauth-v2-12</a>.
    </p>
    <p>
      The steps are:
    </p>
    <ul>
      <li>Provide a MLTSHP authentication URL for your user to approve your application's access. (http://mysite.com/return)</li>
      <li>Capture the authorization code when they are bounced back to your site. (http://mysite.com/return?code=######)</li>
      <li>Use that authorization code to request an access token. The access token will contain a key and a secret.</li>
      <li>Use the key to make requests on behalf of your user and sign each request with the secret. </li>
      <li>If the request is properly signed you can request resources and make updates to those resources on behalf of the user.</li>
    </ul>
    <p>
      Here are two example scripts. Both require you to input your access key and secret you get
      from <a href="/developers/apps">creating an application here</a>.
    </p>
    <ul>
      <li><a href="/static/developers/example.py.txt">Python Script</a></li>
      <li><a href="/static/developers/example.php.txt">PHP Script</a></li>
    </ul>
    <a name='desktop'></a>
    <h2>Desktop or Mobile Device App</h2>
    <p>
       Here is how to authenticate in one step when using a desktop or iOS application. Instead of sending the user
       to a web page to approve, and then have them return to your application with an auth code, you can get
       an access token with one step. <strong>DO NOT</strong> use this method if you are not making a desktop application.
    </p>
    <p>
        After acquiring <a href="/developers/new-api-application">app credentials here</a>, POST
        the following data here:
    </p>
    <pre>
/api/token?grant_type=<strong>password</strong>&amp;client_id=<strong>your app key</strong>
    &amp;client_secret=<strong>your app secret</strong>&amp;username=<strong>the user's name</strong>&amp;password=<strong><PASSWORD></strong>
    </pre>
    <p>
        Then if everything matches you'll receive an access token as a JSON response:
    </p>
    <pre>
{
    "access_token": "########",<commit_msg>Add JS Example, Document API Signatures (#566)<commit_after>{% extends "base.html" %}


{% block main %}
<div class="content">
   <div class="content-developer">
    <h1>Hey Developers!</h1>
    <p>
    <a href="/developers/apps">Your Apps</a>
    </p>
    <h2>Steps To Creating A MLTSHP Application</h2>
    <p>
      To get started first <a href="/developers/new-api-application">register an application</a>. You'll need to
      enter a title, description, and also a redirect URL.
      This URL will be where users of your app will be sent after approving your app to access their account.
    </p>
      Once that is done you will be given an API key and a secret. We are using draft 12 of the new <b>OAuth2</b> specification.
      If you want to read the gory details they are all here: <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-12">http://tools.ietf.org/html/draft-ietf-oauth-v2-12</a>.
    </p>
    <p>
      The steps are:
    </p>
    <ul>
      <li>Provide a MLTSHP authentication URL for your user to approve your application's access. (http://mysite.com/return)</li>
      <li>Capture the authorization code when they are bounced back to your site. (http://mysite.com/return?code=######)</li>
      <li>Use that authorization code to request an access token. The access token will contain a key and a secret.</li>
      <li>Use the key to make requests on behalf of your user and sign each request with the secret. </li>
      <li>If the request is properly signed you can request resources and make updates to those resources on behalf of the user.</li>
    </ul>
    <h3>Signing API Requests</h3>
    <p>
        To sign a request to the API, you'll need to add an <code>Authorization</code> header to your request.
        The value of that header is the authorization string. Start by constructing the signature string:
    </p>
    <pre><code>${TIMESTAMP}
${NONCE}
${METHOD}
mltshp.com
${PORT}
${PATH}
${QUERY}</code></pre>
    <ul>
        <li><strong>timestamp</strong> is a UTC timestamp in seconds.</li>
        <li><strong>nonce</strong> is a random string between 10 and 35 characters long.</li>
        <li><strong>method</strong> either <code>GET</code> or <code>POST</code>.</li>
        <li><strong>host</strong> is <code>mltshp.com</code>.</li>
        <li><strong>port</strong> should be <code>443</code> for SSL, but there's a bug in the API right now, and you'll have to use <code>80</code>.</li>
        <li><strong>path</strong> is the API endpoint you're fetching, such as <code>/api/sharedfile/GA4</code>.</li>
        <li><strong>query</strong> any parameters for a <code>POST</code> request. Leave blank for <code>GET</code> requests.</li>
    </ul>
    <p>
        Once you've constructed that signature string, you'll need to encode it into an HMAC-SHA1 hash using the <code>secret</code> value from the <code>token</code> object. Then Base64 encode the hash.
    </p>
    <p>Now you can construct the authorization string:</p>
    <pre><code>MAC token=${TOKEN}, timestamp=${TIMESTAMP}, nonce=${NONCE}, signature=${SIGNATURE}</code></pre>
    <ul>
        <li><strong>token</strong> is the <code>access_token</code> value of the <code>token</code> object.</li>
        <li><strong>timestamp</strong> needs to match the <code>timestamp</code> in the signature.</li>
        <li><strong>nonce</strong> needs to match the <code>nonce</code> in the signature.</li>
        <li><strong>signature</strong> is the encoded signature string you just built.</li>
    </ul>
    <p>Set this authorization string as the value of the <code>Authorization</code> header in your API request.</p>
    <h2>Example Scripts</h2>
    <p>
      Here are some example scripts. They require you to input your access key and secret you get
      from <a href="/developers/apps">creating an application here</a>.
    </p>
    <ul>
      <li><a href="/static/developers/example.py.txt">Python Script</a></li>
      <li><a href="/static/developers/example.php.txt">PHP Script</a></li>
      <li><a href="https://github.com/spaceninja/mltshp-api-test-js">JavaScript</a></li>
    </ul>
    <a name='desktop'></a>
    <h2>Desktop or Mobile Device App</h2>
    <p>
       Here is how to authenticate in one step when using a desktop or iOS application. Instead of sending the user
       to a web page to approve, and then have them return to your application with an auth code, you can get
       an access token with one step. <strong>DO NOT</strong> use this method if you are not making a desktop application.
    </p>
    <p>
        After acquiring <a href="/developers/new-api-application">app credentials here</a>, POST
        the following data here:
    </p>
    <pre>
/api/token?grant_type=<strong>password</strong>&amp;client_id=<strong>your app key</strong>
    &amp;client_secret=<strong>your app secret</strong>&amp;username=<strong>the user's name</strong>&amp;password=<strong><PASSWORD></strong>
    </pre>
    <p>
        Then if everything matches you'll receive an access token as a JSON response:
    </p>
    <pre>
{
    "access_token": "########",
{'fraction_non_alphanumeric': 0.13342503438789546, 'fraction_numerical': 0.006252344629235964, 'mean_word_length': 3.2362288135593222, 'pattern_counts': {'":': 2, '<': 257, '<?xml version=': 0, '>': 257, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3080643', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2409, 'n_words': 896}