retrieving tokens works
This commit is contained in:
@@ -89,6 +89,10 @@
|
|||||||
<p><a href="/rowers/me/rojaboauthorize"><img src="/static/img/rojabo.png"
|
<p><a href="/rowers/me/rojaboauthorize"><img src="/static/img/rojabo.png"
|
||||||
alt="connect with Rojabo" width="130"></a></p>
|
alt="connect with Rojabo" width="130"></a></p>
|
||||||
|
|
||||||
|
{% if user.is_staff %}
|
||||||
|
<p><a href="/rowers/me/idokladauthorize/">iDoklad authorize</a></p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -745,6 +745,7 @@ urlpatterns = [
|
|||||||
views.rower_prefs_view, name='rower_prefs_view'),
|
views.rower_prefs_view, name='rower_prefs_view'),
|
||||||
re_path(r'^me/prefs/user/(?P<userid>\d+)/$',
|
re_path(r'^me/prefs/user/(?P<userid>\d+)/$',
|
||||||
views.rower_simpleprefs_view, name='rower_simpleprefs_view'),
|
views.rower_simpleprefs_view, name='rower_simpleprefs_view'),
|
||||||
|
re_path(r'^me/idokladauthorize/$', views.rower_idoklad_authorize, name='rower_idoklad_authorize'),
|
||||||
re_path(r'^me/rojaboauthorize/$', views.rower_rojabo_authorize,
|
re_path(r'^me/rojaboauthorize/$', views.rower_rojabo_authorize,
|
||||||
name='rower_rojabo_authorize'),
|
name='rower_rojabo_authorize'),
|
||||||
re_path(r'^me/polarauthorize/$', views.rower_polar_authorize,
|
re_path(r'^me/polarauthorize/$', views.rower_polar_authorize,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from django.core.mail import EmailMessage
|
|||||||
from rowers import credits
|
from rowers import credits
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def rower_idoklad_auth(request):
|
def rower_idoklad_authorize(request):
|
||||||
state=str(uuid4())
|
state=str(uuid4())
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
@@ -23,6 +23,7 @@ def rower_idoklad_auth(request):
|
|||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
@login_required()
|
||||||
def process_idokladcallback(request):
|
def process_idokladcallback(request):
|
||||||
dologging('idoklad.log',' /rowers/idokladcallback/')
|
dologging('idoklad.log',' /rowers/idokladcallback/')
|
||||||
|
|
||||||
@@ -33,9 +34,45 @@ def process_idokladcallback(request):
|
|||||||
messages.error(request,error)
|
messages.error(request,error)
|
||||||
return HttpResponseRedirect(reverse('workouts_view'))
|
return HttpResponseRedirect(reverse('workouts_view'))
|
||||||
|
|
||||||
|
post_data = {
|
||||||
|
'grant_type': "authorization_code",
|
||||||
return HttpResponse('')
|
'client_id': IDOKLAD_CLIENT_ID,
|
||||||
|
'client_secret': IDOKLAD_CLIENT_SECRET,
|
||||||
|
'scope': 'idoklad_api offline_access',
|
||||||
|
'code': code,
|
||||||
|
'redirect_uri': IDOKLAD_REDIRECT_URI,
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
}
|
||||||
|
|
||||||
|
base_url = 'https://identity.idoklad.cz/server/connect/token'
|
||||||
|
|
||||||
|
response = requests.post(base_url, data=post_data, headers=headers)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
result = response.json()
|
||||||
|
try:
|
||||||
|
t = iDokladToken.objects.get(id=1)
|
||||||
|
t.acces_token = result['access_token'],
|
||||||
|
t.refresh_token = result['refresh_token']
|
||||||
|
t.expires_in = result['expires_in']
|
||||||
|
t.save()
|
||||||
|
except iDokladToken.DoesNotExist:
|
||||||
|
t = iDokladToken(
|
||||||
|
access_token = result['access_token'],
|
||||||
|
refresh_token = result['refresh_token'],
|
||||||
|
expires_in = result['expires_in'],
|
||||||
|
)
|
||||||
|
t.save()
|
||||||
|
messages.info(request,"Token refreshed and stored")
|
||||||
|
else:
|
||||||
|
messages.error(request,"Error")
|
||||||
|
|
||||||
|
url = reverse('rower_exportsettings_view')
|
||||||
|
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def braintree_webhook_view(request):
|
def braintree_webhook_view(request):
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ from rowers.models import ( RowerPowerForm, RowerHRZonesForm, SimpleRowerPowerFo
|
|||||||
IndoorVirtualRaceForm, PlannedSessionCommentForm, Alert,
|
IndoorVirtualRaceForm, PlannedSessionCommentForm, Alert,
|
||||||
Condition, StaticChartRowerForm, FollowerForm,
|
Condition, StaticChartRowerForm, FollowerForm,
|
||||||
VirtualRaceAthleteForm, InstantPlanForm, DataRowerForm,
|
VirtualRaceAthleteForm, InstantPlanForm, DataRowerForm,
|
||||||
StepEditorForm, )
|
StepEditorForm, iDokladToken )
|
||||||
from rowers.models import (
|
from rowers.models import (
|
||||||
FavoriteForm, BaseFavoriteFormSet, SiteAnnouncement, BasePlannedSessionFormSet,
|
FavoriteForm, BaseFavoriteFormSet, SiteAnnouncement, BasePlannedSessionFormSet,
|
||||||
get_course_timezone, BaseConditionFormSet,
|
get_course_timezone, BaseConditionFormSet,
|
||||||
@@ -225,6 +225,7 @@ from rowsandall_app.settings import (
|
|||||||
RECAPTCHA_SITE_KEY, RECAPTCHA_SITE_SECRET,
|
RECAPTCHA_SITE_KEY, RECAPTCHA_SITE_SECRET,
|
||||||
NK_REDIRECT_URI, NK_CLIENT_ID, NK_CLIENT_SECRET,
|
NK_REDIRECT_URI, NK_CLIENT_ID, NK_CLIENT_SECRET,
|
||||||
ROJABO_REDIRECT_URI, ROJABO_CLIENT_ID, ROJABO_CLIENT_SECRET,
|
ROJABO_REDIRECT_URI, ROJABO_CLIENT_ID, ROJABO_CLIENT_SECRET,
|
||||||
|
IDOKLAD_REDIRECT_URI, IDOKLAD_CLIENT_ID, IDOKLAD_CLIENT_SECRET,
|
||||||
)
|
)
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
|||||||
@@ -97,6 +97,8 @@ AUTHENTICATION_BACKENDS = (
|
|||||||
#'rules.permissions.ObjectPermissionBackend',
|
#'rules.permissions.ObjectPermissionBackend',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CSRF_TRUSTED_ORIGINS = ['https://rowsandall.com', 'https://www.rowsandall.com', 'http://localhost', 'https://dunav.ngrok.io']
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.common.BrokenLinkEmailsMiddleware',
|
'django.middleware.common.BrokenLinkEmailsMiddleware',
|
||||||
@@ -600,9 +602,11 @@ except KeyError: # pragma: no cover
|
|||||||
try:
|
try:
|
||||||
IDOKLAD_CLIENT_ID = CFG['idoklad_client_id']
|
IDOKLAD_CLIENT_ID = CFG['idoklad_client_id']
|
||||||
IDOKLAD_CLIENT_SECRET = CFG['idoklad_client_secret']
|
IDOKLAD_CLIENT_SECRET = CFG['idoklad_client_secret']
|
||||||
|
IDOKLAD_REDIRECT_URI = CFG['idoklad_redirect_uri']
|
||||||
except KeyError: # pragma: no cover
|
except KeyError: # pragma: no cover
|
||||||
IDOKLAD_CLIENT_ID = ''
|
IDOKLAD_CLIENT_ID = ''
|
||||||
IDOKLAD_CLIENT_SECRET = ''
|
IDOKLAD_CLIENT_SECRET = ''
|
||||||
|
IDOKLAD_REDIRECT_URI = ''
|
||||||
|
|
||||||
|
|
||||||
# ID obfuscation
|
# ID obfuscation
|
||||||
|
|||||||
Reference in New Issue
Block a user