Software Archive
Read-only legacy content

Reference to exports. and helpers.

Andrew_S_1
Beginner
670 Views

Hello,

Can someone please tell me where 'exports.' and 'helpers.' used in the sample code in the article "Using OAuth2 Authentication" are defined?

Thanks in advance.

0 Kudos
4 Replies
Rakshith_K_Intel
Employee
670 Views

Once you create a data binding in the xdk UI, there will be code scripts added to the project, you can find these definitions in this path in your project:

.../www/xdk/service/service-method.js

0 Kudos
Andrew_S_1
Beginner
670 Views

Thank you Rakshith, however I am not quite able to complete the binding.  I am running XDK#2893 on a MacBook Pro from early 2015 using OS X Yosemite 10.10.5.  I am trying to setup a connection with my app’s setup on Dropbox, using the authorize method on the XDK’s list of services.

Using the localhost as the redirect_uri, and response_type set to "code" I get a Dropbox screen asking for access permission, and after confirming on that, the XDK receives what looks like a correct bearer token (in the Response Body field however), the Call field is empty, Response Code reads n/a, and Response Headers just has empty brackets.  But when I click on Create Data Binding (which has ‘db_coreauthorize’ in the edit box to its left)  I get:

Error saving service binding

No paths chosen in response body.

(Hint: click some of those checkboxes below)

But there are no checkboxes in the response body or anywhere else.  And no service modules have been deposited in the tray on the left (though there is now a services folder).

Is this enough to go on?

Yours,

Andrew Scott

0 Kudos
Anjali_G_Intel
Employee
670 Views

Hi Andrew,

1. What type of values are you seeing in the response body section? Is it not a json object? 

2. Do you see the data binding you created in the web services's "Saved DAta binding" section?

3. The "helpers" object has the helpers function. Depending on where you want to access it and what you want to do with it, try any of these ways  :

a) Use the "Create a new web service" button and enter any value and generate the files. The .js file is automatically passed the helpers object. You can see what it has and the function implementation.

b) If you use the "Debug It" option in the web services explorer, you will be able to step through the code and see exactly what the helpers object contains and how the functions are implemented. 

c) Create any random data binding. Maybe use the "API explorer sandbox" in the web services list, enter "http://jsonplaceholder.typicode.com/posts" in the GET api's parameter field and just create a data binding. Look for www/js/xdk/services/service-methods.js file. The "helpers" object is defined here. Note that these files are auto-generated and editing them here would not be of any use. You can use the implementation to guide you to write your own helper functions.You can include another script that will over-ride or extend the existing helpers.

Thanks,

Anjali 

0 Kudos
Anjali_G_Intel
Employee
670 Views

Oh, one more thing to note. 

When one uses any of the authorize methods that are implemented in the xdk services. The returned string result i.e. the token is stored in local storage. So one would not need to create a data binding for the authorize APIs. If you make a call of any of the other APIs from the explorer, they would automatically use the returned token from localstorage. If you want to access the returned token in your own code, use this :

    var db = window.localStorage;
    return db.getItem(<name of token>);

We store the tokens with this convention : {servicename}_access_token. So for dropbox, it would be :

 window.localStorage.getItem('dropbox_access_token');

Hope this helps!

Anjali 

0 Kudos
Reply