Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Member
    Join Date
    May 2007
    Posts
    10

    Question API Authentication with Sencha Ext JS or Sencha Touch

    I'm sure it's probably simple that I'm overlooking (usually is), but I'm banging my head against the wall with this simple authentication issue. While I don't expect many here to be expert in Ext JS, I think it's more about how I'm constructing my AJAX calls than anything else.

    Code:
    Ext.define('MyApp.store.base.MyJsonStore', {
        extend: 'Ext.data.Store',
    
        config: {
            storeId: 'MyJsonStore',
            proxy: {
                type: 'ajax',
                url: 'http://mywebsite.com:2086/json-api/listaccts',
                method: 'GET',
                username: 'cpanelusergoeshere',
                password: 'h2liku3h4lkquyweilkruyahwukey',
                reader: {
                    type: 'json'
                }
            }
        }
    });
    The error message I keep seeing from the console I'm using is:

    Unable to load data using the supplied configuration.
    Open in Browser http://mywebsite.com:2086/json-api/listaccts
    I've removed any real information in the above code sample, but it gets the general idea across with what I'm trying to do. More or less, build a better cPanel/WHM manager than other mobile options that are currently available to me while mobile and out in the field.

    If I can get this working, I'll be able to do some slick stuff with this library for mobile devices. I'll admit REST calls aren't my favorite thing, and I'm not the best out there...but I'm willing to learn.

    Also, unless I've misunderstood something, the hash is only required if using root, and even then I've seen other iPhone apps that don't require the hash (curious about that). I don't expect people to be typing the full hash into an iPhone or Android application to be honest.

  2. #2
    cPanel Staff
    Join Date
    Mar 2004
    Posts
    704

    Default Re: API Authentication with Sencha Ext JS or Sencha Touch


  3. #3
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: API Authentication with Sencha Ext JS or Sencha Touch

    yeah...not knowing the details of the Ext framework, more specifically their "proxy" base class implementation, I'd have to agree with Dan's answer...that URL security tokens, issues after basic authentication, is altering the needed target URL. However, if the username and password credential were to be embedded in the HTTP Headers, then tokens wouldn't be an issue since such a request will auth and perform the function "listaccts" and return the data, all in one request. It really comes down to how Ext is forming the HTTP request.

    Regards,
    -DavidN

    PS. I highly recommend that you use port 2087 if possible; it is the SSL port for WHM. Otherwise your entire HTTP request (headers included) will be transmitted in plain text, exposing the credentials to anyone sniffing packets.
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  4. #4
    cPanel Staff
    Join Date
    Mar 2004
    Posts
    704

    Default Re: API Authentication with Sencha Ext JS or Sencha Touch

    Quote Originally Posted by cPanelDavidN View Post
    PS. I highly recommend that you use port 2087 if possible; it is the SSL port for WHM. Otherwise your entire HTTP request (headers included) will be transmitted in plain text, exposing the credentials to anyone sniffing packets.
    Also, use POST instead of GET: Otherwise your query string (which would include the credential parameters) will be easily seen.

  5. #5
    Member
    Join Date
    May 2007
    Posts
    10

    Default Re: API Authentication with Sencha Ext JS or Sencha Touch

    Extremely helpful guys. Thank you! I'll test with this today and see if I can't get this working a little better.

    I did originally try SSL on 2087, however, the application I'm building wasn't liking that. I wanted to at least get it working first, then tackle the SSL issues. It may have something to do with the fact the cPanel server I'm connecting to doesn't have a valid cert for the hostname, so the application is perceiving the "no valid cert" popup, but I'm not 100% on that.

    The servers the app will be connecting to don't necessarily need to have valid certs installed on the server hostname, do they? If so, that may be a deal breaker. Then again...the couple of other apps in the iOS app store don't currently have an issue and I've connected to one of my machines just fine, so maybe I'm imagining things.

  6. #6
    cPanel Staff
    Join Date
    Mar 2004
    Posts
    704

    Default Re: API Authentication with Sencha Ext JS or Sencha Touch

    Quote Originally Posted by ashworth102680 View Post
    The servers the app will be connecting to don't necessarily need to have valid certs installed on the server hostname, do they?
    Not necessarily, how that is handled is 100% up to the browser/ajax code. At times you still get the “untrusted cert” dialog w/ AJAX calls the same as you would if you went to the URL its fetching directly in your browser.

    That is true of a request to any URL and not limited to cPanel API URLs.

    HTH!

  7. #7
    Member
    Join Date
    Jul 2011
    Location
    Palmerston North, New Zealand
    Posts
    27
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: API Authentication with Sencha Ext JS or Sencha Touch

    When calling the JSON API you do not require a cPanel Session Token.
    Also if you can, try to catch the outgoing HTTP packet using something like Wire Shark.
    Inspect the packet and make sure that it is formed correctly.

    Here is an extract from the API class for PHP

    if ( $this->auth_type == 'hash' ) {
    $authstr = 'Authorization: WHM ' . $this->user . ':' . $this->auth . "\r\n";
    } elseif ($this->auth_type == 'pass' ) {
    $authstr = 'Authorization: Basic ' . base64_encode($this->user .':'. $this->auth) . "\r\n";
    } else {
    throw new Exception('invalid auth_type set');
    }

    As you can see, when you are using the raw password, it must conform to Basic Authentication standards, but when you use the hash key, you must conform to WHM standards which is cPanels own custom standard for accessing its API.

  8. #8
    Member This forum account has been confirmed by cPanel staff to represent a vendor. KostonConsulting's Avatar
    Join Date
    Jun 2010
    Location
    Austin, TX
    Posts
    97
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: API Authentication with Sencha Ext JS or Sencha Touch

    Code:
    Ext.define('MyApp.store.base.MyJsonStore', {
        extend: 'Ext.data.Store',
    
        config: {
            storeId: 'MyJsonStore',
            proxy: {
                type: 'ajax',
                url: 'http://mywebsite.com:2086/json-api/listaccts',
                method: 'GET',
                username: 'cpanelusergoeshere',
                password: 'h2liku3h4lkquyweilkruyahwukey',
                reader: {
                    type: 'json'
                }
            }
        }
    });
    I don't see anywhere in the proxy docs that username and password are methods or configuration parameters for ajax proxy. There appears to be a headers config object which should be set to the value of mime base64 encoded
    Code:
    'user:password'
    .

    Sencha Docs - Ext JS 4.0
    Dave Koston
    Koston Consulting
    http://www.kostonconsulting.com

Similar Threads & Tags
Similar threads

  1. Planned for 11.36 WHM - PAM / LDAP / RADIUS Authentication (Pluggable Authentication) [case 39461]
    By NathanS in forum Feature Requests for cPanel/WHM
    Replies: 30
    Last Post: 04-10-2012, 03:37 AM
  2. Cannot use WHM authentication for remote access to API 2
    By netshine in forum cPanel Developers
    Replies: 4
    Last Post: 11-17-2011, 04:10 AM
  3. API authentication with JavaScript and XHR
    By simonpearce in forum cPanel Developers
    Replies: 3
    Last Post: 01-25-2010, 11:30 AM
  4. API Pass/has authentication?
    By jhyland87 in forum cPanel Developers
    Replies: 3
    Last Post: 06-29-2009, 01:12 PM
  5. WHM XML API authentication
    By JamieD in forum cPanel Developers
    Replies: 2
    Last Post: 02-15-2008, 03:27 AM
Tags for this Thread
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube