yarbshk / pybitrix24

The simplest zero dependency polyversion Python library for Bitrix24 REST API.
MIT License
43 stars 23 forks source link

{'error': 'invalid_grant'} #17

Closed macdev14 closed 2 years ago

macdev14 commented 2 years ago

Getting {'error': 'invalid_grant', 'domain': 'xxxx.bitrix24.com.br'}

redirects to the following URL when authorization URL is opened

http://localhost:8000/?code=_xxxxx_&state=&domain=xxxx.bitrix24.com.br&member_id=0_example_0&scope=crm&server_domain=oauth.bitrix.info

yarbshk commented 2 years ago

hey @macdev14 thanks for your message! could you provide more details about the issue in order to reproduce it (e.g. code snippets)?

macdev14 commented 2 years ago

bx24 = Bitrix24('xxxx.bitrix24.com.br', 'client_id', 'secret_key' ) print(bx24.build_authorization_url()) print(bx24.obtain_tokens('AnAuthorizationCode')) returns {'error': 'invalid_grant', 'domain': 'xxxx.bitrix24.com.br'}

As I've seen it should get the code from the url code=xxxxx then send a GET request like this to get the access token: https://xxxx.bitrix24.com.br/oauth/token/?grant_type=authorization_code&client_id=EXAMPLE&client_secret=SECRET_EXAMPLE&code=CODE_FROM_AUTHORIZATION_URL

source: https://dev.1c-bitrix.ru/community/blogs/b24_marketplace/marketplace-bitriks24-how-to-make-oauth-authentication-for-desktop-app.php

returns the following:

{ "access_token": "XXXXXXXX", "expires": 1649707401, "expires_in": 3600, "scope": "app", "domain": "xxxx.bitrix24.com.br", "server_endpoint": "https:\/\/oauth.bitrix.info\/rest\/", "status": "L", "client_endpoint": "https:\/\/xxxx.bitrix24.com.br\/rest\/", "member_id": "xxxxx", "user_id": 000, "refresh_token": "xxxxxxxxx" }

macdev14 commented 2 years ago

I didn't set the code=00000 value in bx24.obtain_tokens('AnAuthorizationCode')) , that's why, thank you!