•   about 4 years ago

Requests for help on a few API usage topics, especially client side OAuth initiation.

Hello Context.IO,

I'm getting started with the Node.JS client library. I have a few questions:

1) Is there forum where I can post my API usage questions? If so, please leave me the URL here.

2) In the client library code, I see references to "this.callback" in several places. However, I can't seem to find where that element is defined. Where can I get an explanation of what code defines/declares that method and what is the context of the "this" object at this point? (See line 15 of accounts.js).

3) I see the calls for creating a new ContextIO API object with the consumer key and secret defined in keys.json (now updated to reflect my consumer key and secret). However, I'm having some trouble wrapping my head around the "big picture" using OAuth with the API.

My intention is to have a Node.JS server acting as a middleman to my clients that reside on the user's local device. What I can't figure out are the steps I would follow to initiate the OAuth session from the client, with my server code then forwarding the request to OAuth provider (GMail in this case) in order to have the user be logged in by Gmail, resulting in the authenticated token ending up back in my hands for use with subsequent API calls when the OAuth provider accesses a URL I provide for that purpose.

Is there a document or sample that shows generally what I would do to make this happen? I'm used to OAuth session where I provide a callback URL to the provider with the code behind that URL receiving the token that is now authenticated.

  • 2 comments

  • Manager   •   about 4 years ago

    Hello (again) Robert!
    Lemme reply inline:

    1) Is there forum where I can post my API usage questions? If so, please leave me the URL here.

    Feel free to drop them in here, or if they're more support questions email us at support [at] context [dot] io. We're happy to help!

    2) In the client library code, I see references to "this.callback" in several places. However, I can't seem to find where that element is defined. Where can I get an explanation of what code defines/declares that method and what is the context of the "this" object at this point? (See line 15 of accounts.js).

    In Javascript, the `this` keyword refers to the owner of the function that's being executed. Is accounts.js a file that you wrote? I don't see it in our client lib. Perhaps you could tell me what you're trying to do and I can help you with some sample code that might clear things up? Lemme know!

    3) I see the calls for creating a new ContextIO API object with the consumer key and secret defined in keys.json (now updated to reflect my consumer key and secret). However, I'm having some trouble wrapping my head around the "big picture" using OAuth with the API.

    Sure - You use your Context.IO key and secret and sign API requests via Oauth1. Our client libraries do this, you can take a peek at the code and see how to form and sign those requests in various languages. If you need some help finding those code blocks, let me know which lib you're looking at and I'll get you some line numbers. So, that's how you make authenticated requests to Context.IO. Depending on your user's email provider, you may be able to get their permission to access their email via Oauth. This only works if the email provider is Gmail or Outlook.com. Context.IO does work on other email providers, we just have to use credentials rather than Oauth. Our connect tokens remove all that complexity of you needing to decide if you will get your user's permission via Oauth or credentials, and I recommend you use them to get your user's permission. Hope this makes sense! If it doesn't or you have more questions, let me know! Happy to help in here, via email, or can jump on a call and chat through some stuff.

    Cheers,
    Tony

  •   •   about 4 years ago

    Hi Robert!

    'this.callback' is referring to the 'ctxio' variable which represents the Context.IO connection object created on line 9 of the accounts.js file.

    As far as your OAuth efforts:
    You’ll have your server making all the API calls to Context.IO, issue a unique token that would be saved on the client's device, that the client would pass to your server securely via SSL. Your server would then look at that unique token and find out the Context.IO account id for that user, so the server component can make calls and pass the relevant data back to the client.

Comments are closed.