1- # openapi-client
2- HelloAsso auto-generated SDK
1+ # helloasso-python
32
4- This Python package is automatically generated by the [ OpenAPI Generator] ( https://openapi-generator.tech ) project:
5-
6- - API version: public
7- - Package version: 1.0.0
8- - Generator version: 7.10.0
9- - Build package: org.openapitools.codegen.languages.PythonClientCodegen
3+ The HelloAsso Python library offers a straightforward way to interact with the HelloAsso API in Python applications. It features a collection of pre-built classes for API resources that automatically adapt to API responses, ensuring flexibility across different versions of the HelloAsso API.
104
115## Requirements.
126
@@ -18,9 +12,9 @@ Python 3.8+
1812If the python package is hosted on a repository, you can install directly using:
1913
2014``` sh
21- pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
15+ pip install helloasso-python
2216```
23- (you may need to run ` pip ` with root permission: ` sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git ` )
17+ (you may need to run ` pip ` with root permission: ` sudo pip install helloasso-python ` )
2418
2519Then import the package:
2620``` python
@@ -235,23 +229,116 @@ Class | Method | HTTP request | Description
235229 - [ ResultsWithPaginationModelSynchronizableFormModel] ( docs/ResultsWithPaginationModelSynchronizableFormModel.md )
236230 - [ ResultsWithPaginationModelSynchronizableOrganizationModel] ( docs/ResultsWithPaginationModelSynchronizableOrganizationModel.md )
237231
232+ ## Authorization
238233
239- <a id =" documentation-for-authorization " ></a >
240- ## Documentation For Authorization
241-
234+ We use OAuth2 for authentication, so to avoid reinventing the wheel, we recommend using the [ Authlib] ( https://pypi.org/project/Authlib ) package
242235
243- Authentication schemes defined for the API:
244- <a id =" OAuth2 " ></a >
245- ### OAuth2
236+ ### Prerequisite
237+ Install the Authlib package:
246238
247- - ** Type ** : OAuth
248- - ** Flow ** : application
249- - ** Authorization URL ** :
250- - ** Scopes ** : N/A
239+ ``` bash
240+ pip install requests
241+ pip install Authlib
242+ ```
251243
244+ ### Client Credentials Flow
245+ ``` python
246+ from authlib.integrations.requests_client import OAuth2Session
247+
248+ # Configuration
249+ client_id = ' your_client_id'
250+ client_secret = ' your_client_secret'
251+ token_url = ' https://api.helloasso.com/oauth2/token'
252+
253+ # Create an OAuth2 session
254+ client = OAuth2Session(client_id, client_secret)
255+
256+ # Get an access token
257+ def get_access_token ():
258+ token = client.fetch_token(token_url, grant_type = ' client_credentials' )
259+ print (" Access Token:" , token[' access_token' ])
260+ print (" Expires In:" , token[' expires_in' ])
261+ print (" Refresh Token:" , token[' refresh_token' ])
262+ return token
263+
264+ # Usage
265+ get_access_token()
266+ ```
252267
253- ## Author
268+ ### Refresh Token Flow
269+ ``` python
270+ from authlib.integrations.requests_client import OAuth2Session
271+
272+ # Configuration
273+ client_id = ' your_client_id'
274+ client_secret = ' your_client_secret'
275+ token_url = ' https://api.helloasso.com/oauth2/token'
276+
277+ # Refresh the token
278+ def refresh_access_token (refresh_token ):
279+ client = OAuth2Session(client_id, client_secret)
280+ token = client.refresh_token(token_url, refresh_token = refresh_token)
281+ print (" New Access Token:" , token[' access_token' ])
282+ print (" Expires In:" , token[' expires_in' ])
283+ print (" New Refresh Token:" , token[' refresh_token' ])
284+ return token
285+
286+ # Usage
287+ refresh_access_token(' your_refresh_token' )
288+ ```
254289
290+ ### Authorization Code Flow
291+ ``` python
292+ import base64
293+ import hashlib
294+ import os
295+ from authlib.integrations.requests_client import OAuth2Session
296+
297+ # Configuration
298+ client_id = ' your_client_id'
299+ client_secret = ' your_client_secret'
300+ authorize_url = ' https://auth.helloasso.com/authorize'
301+ token_url = ' https://api.helloasso.com/oauth2/token'
302+ redirect_uri = ' https://your-app.com/callback'
303+
304+ # PKCE Helper Functions
305+ def generate_code_verifier ():
306+ """ Generate a high-entropy code_verifier."""
307+ return base64.urlsafe_b64encode(os.urandom(32 )).rstrip(b ' =' ).decode(' utf-8' )
308+
309+ def generate_code_challenge (code_verifier ):
310+ """ Generate a code_challenge based on the code_verifier."""
311+ code_challenge = hashlib.sha256(code_verifier.encode(' utf-8' )).digest()
312+ return base64.urlsafe_b64encode(code_challenge).rstrip(b ' =' ).decode(' utf-8' )
313+
314+ # Step 1: Generate the Authorization URL
315+ def get_authorization_url ():
316+ # Generate PKCE parameters
317+ code_verifier = generate_code_verifier()
318+ code_challenge = generate_code_challenge(code_verifier)
319+
320+ client = OAuth2Session(client_id, client_secret, redirect_uri = redirect_uri)
321+ authorization_url, state = client.create_authorization_url(authorize_url, code_challenge = code_challenge, code_challenge_method = ' S256' )
322+ print (" Authorization URL: " , authorization_url)
323+ print (" Code verifier: " , code_verifier)
324+
325+ # Step 2: Exchange the authorization code for an access token
326+ def get_access_token_from_code (authorization_response , code_verifier ):
327+ client = OAuth2Session(client_id, client_secret, redirect_uri = redirect_uri)
328+ token = client.fetch_token(token_url, authorization_response = authorization_response, code_verifier = code_verifier)
329+ print (" Access Token: " , token[' access_token' ])
330+ print (" Expires In: " , token[' expires_in' ])
331+ print (" Refresh Token: " , token[' refresh_token' ])
332+
333+ # Usage
334+ get_authorization_url()
335+ # After user authorizes, exchange the code (passed in the redirect URL callback)
336+ # get_access_token_from_code('your_authorization_code', 'your_code_verifier')
337+ ```
255338
339+ ## About this package
256340
341+ This SDK is automatically generated by the [ OpenAPI Generator] ( https://openapi-generator.tech ) project:
257342
343+ - Generator version: 7.10.0
344+ - Build package: org.openapitools.codegen.languages.PythonClientCodegen
0 commit comments