nylas/nylas-python

Expose full response dict when calling POST `/oauth/token`

Closed this issue · 3 comments

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I don't ask for a user email on my end, so I need to get it from that response.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Just another method that simply returns the response instead of the token.

def trade_code(self, code):
        args = {
            "client_id": self.client_id,
            "client_secret": self.client_secret,
            "grant_type": "authorization_code",
            "code": code,
        }

        headers = {
            "Content-type": "application/x-www-form-urlencoded",
            "Accept": "text/plain",
        }

        resp = requests.post(
            self.access_token_url, data=urlencode(args), headers=headers
        ).json()

        self.access_token = resp[u"access_token"]
        return resp

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

I'm making the call myself right now.

Additional context
Add any other context or screenshots about the feature request here.

@yi-fan-song thank you for opening this issue! We will investigate adding this to the SDK and let you know once it's been complete & released!

@yi-fan-song The fix has been merged into main and can be accessed via send_authorization(code). It will be included in the next release coming very soon!

@yi-fan-song Nylas Python SDK v5.5.0 has been released containing this new function! Below is how you can access the full payload:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

ACCESS_TOKEN = nylas.send_authorization('{code_from_nylas}')