Comments (1)
I have got this solved by storing the info about 2FA authentication in session. But I feel it is a bit hacky and unneedingly complicated.
The pipeline:
from django.shortcuts import redirect
from django.urls import reverse
from social_core.pipeline.partial import partial
from two_factor.utils import default_device
@partial
def two_factor_auth(strategy, details, *args, user=None, **kwargs):
current_partial = kwargs.get("current_partial")
request = kwargs["request"]
if request.session.get("tfa_completed", False):
return
if default_device(user):
return redirect(
reverse("two_factor_authentication") + f"?partial_token={current_partial.token}"
)
return
The view:
from django.urls import reverse
from django.views.generic import FormView
from social_django.utils import load_strategy
from two_factor.forms import AuthenticationTokenForm
from two_factor.utils import default_device
class AuthenticationView(FormView):
template_name = "two_factor/core/login.html"
form_class = AuthenticationTokenForm
def get_success_url(self):
partial = self.get_partial()
self.request.session["tfa_completed"] = True
return (
reverse("social:complete", kwargs={"backend": partial.backend})
+ f"?partial_token={partial.token}"
)
def get_partial(self):
strategy = load_strategy()
partial_token = self.request.GET.get("partial_token")
partial = strategy.partial_load(partial_token)
return partial
def get_form_kwargs(self, *args, **kwargs):
kwargs = super().get_form_kwargs(*args, **kwargs)
user = self.get_partial().kwargs["user"]
kwargs["user"] = user
kwargs["initial_device"] = default_device(user)
return kwargs
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["step"] = "auth"
return context
from python-social-auth.
Related Issues (20)
- cannot import name 'OpenIdConnectAssociation' HOT 1
- Too bad, casually abandoned HOT 2
- Issue with redirecting page after login using Facebbok for django site
- Support for tokens / secrets in database HOT 1
- VK now demands API version
- python-social-auth - FB login issue HOT 3
- Backend AzureADB2COAuth2 requires 'SOCIAL_AUTH_AZUREAD_B2C_OAUTH2_POLICY' but there is no documentation about this anywhere HOT 2
- 401 Client Error: Authorization Required for url: https://api.twitter.com/oauth/request_token
- 401 Client Error: Authorization Required for url: https://api.twitter.com/oauth/request_token
- 401 Client Error: Authorization Required for url: https://api.twitter.com/oauth/request_token
- Allow exception handling during DEBUG mode
- Facebook login popup from Angular + JWT + DRF
- django.db.migrations.exceptions.NodeNotFoundError: Migration listings.0001_initial dependencies reference nonexistent parent node ('owners', '0001_initial')
- base64.encodestring was deprecated and removed in Python 3.9 . Use encodebytes instead.
- auth
- Is there any example/documentation for IDP initiated SSO in SAML backend? HOT 1
- Регистрация через соц сети
- GoogleOpenId is not defined in https://github.com/python-social-auth/social-core/blob/4.5.0/social_core/backends/google.py
- linkedin openid complete endpoint request is stuck
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-social-auth.