Hi,
I only just had a chance to come back to this, and while I have more
information unfortunately I don't have more progress.
I'm hoping you can suggest something after reading the details below, if
not I will have to trace the request through the other middlewhere and
see what happens.
On 9/2/18 05:17, Peter Sagerson wrote:
> I would probably start by checking the user's session and making sure
> the device was persisted. Look at OTPMiddleware to see what's going
> on--it's pretty straightforward.
The users device doesn't appear to persist. The logs below show (i hope)
roughly what goes on (i hacked in log statements to the decorator):
When I try and view a protected page for the first time I'm captured and
sent to the login page (as expected)
> 2018-03-01 13:27:38 DEBUG django_otp.decorators: in test()
> 2018-03-01 13:27:38 DEBUG django_otp.decorators: user device None
> 2018-03-01 13:27:38 DEBUG django_otp.decorators: user.is_verified False
> 2018-03-01 13:27:38 DEBUG django_otp.decorators: if_configured True
> 2018-03-01 13:27:38 DEBUG django_otp.decorators: _user_is_authenticated(user) True
> 2018-03-01 13:27:38 DEBUG django_otp.decorators: user_has_device True
> 2018-03-01 13:27:39 DEBUG otp_vip.views: In multi_factor view
> 2018-03-01 13:27:39 DEBUG otp_vip.views: using template otp_vip/validate_vip.html
> 2018-03-01 13:27:39 DEBUG otp_vip.views: is user verified False
> 2018-03-01 13:27:39 DEBUG otp_vip.views: user otp dev None> 2018-03-01 13:27:41 DEBUG otp_vip.views: creating some empty forms
I take my OTP and enter it in the form, printing my POST data as I go.
You can see the verification succeed and the device being recorded
against the user.
> 2018-03-01 13:28:21 DEBUG otp_vip.views: In multi_factor view
> 2018-03-01 13:28:21 DEBUG otp_vip.views: using template otp_vip/validate_vip.html
> 2018-03-01 13:28:21 DEBUG otp_vip.views: is user verified False
> 2018-03-01 13:28:21 DEBUG otp_vip.views: user otp dev None
> 2018-03-01 13:28:21 DEBUG otp_vip.views: <QueryDict: {u'csrfmiddlewaretoken': [u'csrf data'], u'otp_token': [u'638741'], u'otp_device': [u'otp_vip.viptokencredential/33']}>
> 2018-03-01 13:28:21 DEBUG otp_vip.views: attempting to log in via pin
> 2018-03-01 13:28:21 DEBUG otp_vip.credential_models: recording token to db
> 2018-03-01 13:28:21 DEBUG otp_vip.credential_models: Calling validate_token_data with user
ka...@kgoetz.id.au and token 638741
> 2018-03-01 13:28:21 DEBUG otp_vip.utils: Initialising ValidateTokenData with user
ka...@kgoetz.id.au and code 638741
> 2018-03-01 13:28:22 DEBUG otp_vip.utils: Checking request return code
> 2018-03-01 13:28:22 DEBUG otp_vip.utils: Authentication succeeded at 2018-03-01 13:28:22.035024
> 2018-03-01 13:28:22 DEBUG otp_vip.views: second factor token worked
> 2018-03-01 13:28:22 DEBUG otp_vip.views: is user verified True
> 2018-03-01 13:28:22 DEBUG otp_vip.views: user otp dev VIP access for Mac (v2) (Push enabled False) (kg2652)
In this view I've tried returning an HttpRepsonse('with html in it') and
an HttpResponseRedirect('/to-protectedpage'), both fail in the same way.
The example above is an HttpResponse - a redirect simply goes
immediately in to the next block where the protected page is viewed and
the user captured again due to a missing device/unverified state and
we're back where we started.
> 2018-03-01 13:28:39 DEBUG django_otp.decorators: in test()
> 2018-03-01 13:28:39 DEBUG django_otp.decorators: user device None
> 2018-03-01 13:28:39 DEBUG django_otp.decorators: user.is_verified False
> 2018-03-01 13:28:39 DEBUG django_otp.decorators: if_configured True
> 2018-03-01 13:28:39 DEBUG django_otp.decorators: _user_is_authenticated(user) True
> 2018-03-01 13:28:39 DEBUG django_otp.decorators: user_has_device True
> 2018-03-01 13:28:39 DEBUG otp_vip.views: In multi_factor view
> 2018-03-01 13:28:39 DEBUG otp_vip.views: using template otp_vip/validate_vip.html
> 2018-03-01 13:28:39 DEBUG otp_vip.views: is user verified False
> 2018-03-01 13:28:39 DEBUG otp_vip.views: user otp dev None> 2018-03-01 13:28:41 DEBUG otp_vip.views: creating some empty forms
To check if it was due to middleware ordering, I changed from the
previous configuration to one where OTPMiddleware was immediately after
AuthenticationMiddleware, this doesn't appear to have altered the
systems behaviour.
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.common.CommonMiddleware',
'dj_pagination.middleware.PaginationMiddleware',
'tendenci.apps.profiles.middleware.ForceLogoutProfileMiddleware',
'tendenci.apps.profiles.middleware.ProfileMiddleware',
'tendenci.apps.base.middleware.Http403Middleware',
'tendenci.apps.redirects.middleware.RedirectMiddleware',
'tendenci.apps.mobile.middleware.MobileMiddleware',
'tendenci.apps.theme.middleware.RequestMiddleware',
'tendenci.apps.base.middleware.MissingAppMiddleware',
'tendenci.apps.memberships.middleware.ExceededMaxTypesMiddleware',
'tendenci.apps.forums.middleware.PybbMiddleware',
'tendenci.apps.profiles.middleware.ProfileLanguageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'htmlmin.middleware.HtmlMinifyMiddleware',
'htmlmin.middleware.MarkRequestMiddleware',
'django_otp.middleware.OTPMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_otp.middleware.OTPMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.common.CommonMiddleware',
'dj_pagination.middleware.PaginationMiddleware',
'tendenci.apps.profiles.middleware.ForceLogoutProfileMiddleware',
'tendenci.apps.profiles.middleware.ProfileMiddleware',
'tendenci.apps.base.middleware.Http403Middleware',
'tendenci.apps.redirects.middleware.RedirectMiddleware',
'tendenci.apps.mobile.middleware.MobileMiddleware',
'tendenci.apps.theme.middleware.RequestMiddleware',
'tendenci.apps.base.middleware.MissingAppMiddleware',
'tendenci.apps.memberships.middleware.ExceededMaxTypesMiddleware',
'tendenci.apps.forums.middleware.PybbMiddleware',
'tendenci.apps.profiles.middleware.ProfileLanguageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'htmlmin.middleware.HtmlMinifyMiddleware',
'htmlmin.middleware.MarkRequestMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
kk