not working, initial attempts
This commit is contained in:
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -741,6 +741,8 @@ urlpatterns = [
|
||||
views.rower_prefs_view, name='rower_prefs_view'),
|
||||
re_path(r'^me/prefs/user/(?P<userid>\d+)/$',
|
||||
views.rower_simpleprefs_view, name='rower_simpleprefs_view'),
|
||||
re_path(r'^me/fakturoidauthorize/$', views.rower_fakturoid_auth,
|
||||
name='rower_fakturoid_auth'),
|
||||
re_path(r'^me/rojaboauthorize/$', views.rower_rojabo_authorize,
|
||||
name='rower_rojabo_authorize'),
|
||||
re_path(r'^me/polarauthorize/$', views.rower_polar_authorize,
|
||||
|
||||
@@ -4,10 +4,68 @@ from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
||||
from django.contrib.auth.backends import ModelBackend
|
||||
from rowers.views.statements import *
|
||||
from rowsandall_app.settings import FAKTUROID_CLIENT_ID, FAKTUROID_CLIENT_SECRET, FAKTUROID_REDIRECT_URI, FAKTUROID_EMAIL, FAKTUROID_APP_NAME
|
||||
from django.core.mail import EmailMessage
|
||||
import base64
|
||||
from oauthlib.oauth2 import BackendApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
from rowers import credits
|
||||
|
||||
@login_required()
|
||||
def rower_fakturoid_auth(request):
|
||||
state=str(uuid4())
|
||||
|
||||
params = {
|
||||
"client_id":FAKTUROID_CLIENT_ID,
|
||||
"response_type": "code",
|
||||
"redirect_uri": FAKTUROID_REDIRECT_URI,
|
||||
"state": state,
|
||||
}
|
||||
|
||||
url = "https://app.fakturoid.cz/api/v3/oauth/?"+urllib.parse.urlencode(params)
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
@login_required()
|
||||
def rower_process_fakturoidcallback(request):
|
||||
code = request.GET['code']
|
||||
post_data = {
|
||||
'code': code,
|
||||
'grant_type': 'authorization_code',
|
||||
'redirect_uri': FAKTUROID_REDIRECT_URI,
|
||||
"client_id": FAKTUROID_CLIENT_ID,
|
||||
}
|
||||
|
||||
auth_string = f"{FAKTUROID_CLIENT_ID}:{FAKTUROID_CLIENT_SECRET}"
|
||||
base64_bytes = base64.b64encode(auth_string.encode('utf-8'))
|
||||
base64_string = base64_bytes.decode('utf-8')
|
||||
|
||||
authorizationstring = f"Basic {base64_string}"
|
||||
|
||||
headers = {
|
||||
'User-Agent': f"{FAKTUROID_APP_NAME} ({FAKTUROID_EMAIL})",
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': authorizationstring,
|
||||
}
|
||||
|
||||
base_url = 'https://app.fakturoid.cz/api/v3/oauth/token'
|
||||
|
||||
auth = HTTPBasicAuth(FAKTUROID_CLIENT_ID, FAKTUROID_CLIENT_SECRET)
|
||||
client = BackendApplicationClient(client_id=FAKTUROID_CLIENT_ID)
|
||||
|
||||
oauth = OAuth2Session(client=client)
|
||||
token = oauth.fetch_token(token_url=base_url, auth=auth)
|
||||
|
||||
print(headers)
|
||||
print(post_data)
|
||||
print(base_url)
|
||||
|
||||
print(response)
|
||||
print(response.text)
|
||||
return HttpResponse('succes')
|
||||
|
||||
@csrf_exempt
|
||||
def braintree_webhook_view(request):
|
||||
|
||||
@@ -38,6 +38,7 @@ DEBUG = False
|
||||
TESTING = False
|
||||
|
||||
ALLOWED_HOSTS = CFG['allowed_hosts']
|
||||
CSRF_TRUSTED_ORIGINS = CFG['csrf_origins']
|
||||
|
||||
# OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = 'oauth2_provider.AccessToken'
|
||||
# OAUTH2_PROVIDER_APPLICATION_MODEL = 'oauth2_provider.Application'
|
||||
@@ -597,6 +598,26 @@ try:
|
||||
except KeyError: # pragma: no cover
|
||||
FAKTUROID_SLUG = ''
|
||||
|
||||
try:
|
||||
FAKTUROID_REDIRECT_URI = CFG['fakturoid_redirect_uri']
|
||||
except KeyError:
|
||||
FAKTUROID_REDIRECT_URI = ''
|
||||
|
||||
try:
|
||||
FAKTUROID_CLIENT_ID = CFG['fakturoid_client_id']
|
||||
except KeyError:
|
||||
FAKTUROID_CLIENT_ID = ''
|
||||
|
||||
try:
|
||||
FAKTUROID_APP_NAME = CFG['fakturoid_app_name']
|
||||
except KeyError:
|
||||
FAKTUROID_APP_NAME = ''
|
||||
|
||||
try:
|
||||
FAKTUROID_CLIENT_SECRET = CFG['fakturoid_client_secret']
|
||||
except KeyError:
|
||||
FAKTUROID_CLIENT_SECRET = ''
|
||||
|
||||
# ID obfuscation
|
||||
try:
|
||||
OPAQUE_SECRET_KEY = CFG['opaque_secret_key']
|
||||
|
||||
@@ -93,6 +93,7 @@ urlpatterns += [
|
||||
re_path(r'^tp\_callback', rowersviews.rower_process_tpcallback),
|
||||
re_path(r'^rp3\_callback', rowersviews.rower_process_rp3callback),
|
||||
re_path(r'^twitter\_callback', rowersviews.rower_process_twittercallback),
|
||||
re_path(r'^fakturoid\_callback', rowersviews.rower_process_fakturoidcallback),
|
||||
re_path(r'^i18n/', include('django.conf.urls.i18n')),
|
||||
re_path(r'^tz_detect/', include('tz_detect.urls')),
|
||||
re_path(r'^logo/', logoview),
|
||||
|
||||
Reference in New Issue
Block a user