Allow native authentication to return the full response like the exchange_code_for_token #411
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a
return_full_response
argument to theApi#authenticate
method, along with it an implementation inNativeAuthentication
which mirrors the code in theexchange_code_for_token
method.This let's us perform NativeAuthentication, and get back the full token response vs just the access token. On the implementers end, this lets us share some of our account creation code between the two different types of authentication by being able to rely on the full_response.
Why is this needed? Nylas webhooks come in as "skinny payloads", just enough information to make a request to get the objects data with a request back to Nylas's servers (see: https://developer.nylas.com/docs/developer-guide/webhooks/available-webhooks/#event-webhooks). A calendar event's may look something like:
To look up this object you'll need the access_token for the related account, plus the event id.
Now when using Hosted Authentication, you exchange your oauth code for an access token (https://developer.nylas.com/docs/api/#post/oauth/token). The Ruby API lets you include
return_full_response
in the call toexchange_code_for_token
which gives back not just the access_token, but the full response from the/oauth/token
call:However if you're using Native Authentication, you don't have this option, the call just returns the
access_token
, so now we have to made a follow up call to/account
to get theaccount_id
for theaccess_token
in question. Not the end of the world, but ideally we could treat these two the same, and not make extra requests if we don't have to.License
I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.