Search code examples
c#web-servicesapirestrestkit

Moxtra Integration Using REST API


I need SAML SSO based authentication for my web based application. Moxtra provide SAML SSO Based authentication like:

 <script type="text/javascript"src="https://www.moxtra.com/api/js/moxtra-latest.js" id="moxtrajs"
 data-client-id="CLIENT-ID" data-app-key="IDP-ENTITY-ID" data-org-id="ORG-ID"></script>

I can generate tokens as following

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha256.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script type="text/javascript">// <![CDATA[
    var client_id = "xxxxxxxxxx";
    var client_secret = "yyyyyyyyyy";
    var timestamp = new Date().getTime();
    var uniqueid = "user-unique-identity";

    var hash = CryptoJS.HmacSHA256(client_id + uniqueid + timestamp, client_secret);
    var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
    var signature = hashInBase64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
// ]]></script>

function get_token() {
    var in_options = {
        uniqueid: uniqueid,
        timestamp: timestamp,
        signature: signature,
        get_accesstoken: function(result) {
            alert("access_token: " + result.access_token + " expires in: " + result.expires_in);
        },
        error: function(result) {
            alert("error code: " + result.error_code + " message: " + result.error_message);
        }
    };
    Moxtra.setup(in_options);
}

Now i need all binders,chat option, timeline option, meet option through REST API. on moxtra they provide here

so in similar way i tried in c# code after generating acess token to get all binders but it says 401 Unauthorized.

My code is as following :

  string url = "https://api.moxtra.com/me/binders?" + Token + "HTTP/1.1";
            HttpWebRequest GETRequest = (HttpWebRequest)WebRequest.Create(url);
            GETRequest.Method = "GET";
            HttpWebResponse GETResponse = (HttpWebResponse)GETRequest.GetResponse();
            Stream GETResponseStream = GETResponse.GetResponseStream();
            StreamReader sr = new StreamReader(GETResponseStream);

can some one provide help on this?

P.S. (Need Everything through REST API's )


Solution

  • From the above code it looks like you are trying to do SSO using Unique ID + Signature method and not SAML SSO. You can find more details on the authentication methods supported by Moxtra at https://developer.moxtra.com/moxo/docs-authentication/

    Since you are using unique id + signature based method for authentication you don't need to pass data-app-key and data-org-id

    <script type="text/javascript"src="https://www.moxtra.com/api/js/moxtra-latest.js" id="moxtrajs" data-client-id="CLIENT-ID"></script>
    

    And regarding your question on error 401 it looks like the access token parameter is not passed correctly in the GET request

    You need to pass the access token as a parameter in the request as "access_token=[access token value]".