python - Properly creating OAuth2Service with Rauth and Django -
i using rauth authentication against stripe connect. in doing needing instantiate oauth2service use in multiple views. right views file looks lot (and works), feels wrong:
from rauth.service import oauth2service service = oauth2service( name = 'stripe', client_id = 'my_client_id', client_secret = 'my_secret', authorize_url = 'auth_url', access_token_url = 'stripe_access_token_url', base_url = 'stripe_api_url', ) def stripe_auth(request): params = {'response_type': 'code'} url = service.get_authorize_url(**params) return httpresponseredirect(url) def stripe_callback(request): code = request.get['code'] data = { 'grant_type': 'authorization_code', 'code': code } resp = service.get_raw_access_token(method='post', data=data) ... rest of view code ...
my problem feel placing "service" variable outside of views somehow wrong, not sure way should handle this. should split out separate module, place in settings file, create decorator? not real sure.
any advice appreciated.
i add attribute flask application object this:
app = flask(....) app.stripe = oauth2service( name = 'stripe', client_id = 'my_client_id', client_secret = 'my_secret', authorize_url = 'auth_url', access_token_url = 'stripe_access_token_url', base_url = 'stripe_api_url', )
that makes accessible.
Comments
Post a Comment