标签: python-social-auth

如何强制 redirect_uri 在 python-social-app 中使用 HTTPS?

我正在使用带有 python-social-app 的 django 框架,并且在尝试使用 Facebook 登录按钮登录时出错。

我的应用程序由三个 docker 容器组成:

  1. 姜戈应用程序。
  2. 数据库。
  3. NGINX + SSL 证书。

这是我的错误:

身份验证过程已取消:URL 已阻止:此重定向失败,因为重定向 URI 未在应用程序的客户端 OAuth 设置中列入白名单。确保客户端和 Web OAuth 登录已打开,并将您的所有应用程序域添加为有效的 OAuth 重定向 URI。块引用

这是我在尝试登录时可以看到的 URL

https://www.facebook.com/v2.9/dialog/oauth?client_id=247739632734206&redirect_uri=http%3A%2F%2Fwww.DOMAN_NAME.com%2Fcomplete%2Ffacebook%2F&state=7AySpKwDWAKtiIxP75LBIP3scopesqwy=

正如我所看到的,问题是 redirect_uri 以 HTTP 而不是 HTTPS 开头。

Django==2.2
social-auth-app-django==3.1.0
social-auth-core==3.1.0
Run Code Online (Sandbox Code Playgroud)

我对这个问题的最佳猜测是 Django 应用程序不“知道”它在 NGINX+SSL 后面运行,并使用 HTTP 协议而不是 HTTPS 生成 redirect_uri。

Facebook 设置具有以 HTTPS 开头的正确重定向 URI。这个问题不是 Facebook 特有的,Google 的 redirect_uri 也有同样的问题。

如何强制 python-social 使用 HTTPS?

django google-login oauth-2.0 facebook-login python-social-auth

3
推荐指数
2
解决办法
1830
查看次数

ModuleNotFoundError: 没有名为“jose”的模块

python-social-auth在我的 Django 项目中使用社交平台在我的项目中进行身份验证。一切正常,但出现此错误ModuleNotFoundError: No module named 'jose' 这是整个错误:

[05/Apr/2020 14:01:00] "GET /accounts/login/ HTTP/1.1" 200 3058
Internal Server Error: /login/twitter/
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\site-packages\social_core\backends\utils.py", line 50, in get_backend
    return BACKENDSCACHE[name]
KeyError: 'twitter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Ahmed\AppData\Roaming\Python\Python37\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\Ahmed\AppData\Roaming\Python\Python37\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Ahmed\AppData\Roaming\Python\Python37\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, …
Run Code Online (Sandbox Code Playgroud)

python django python-social-auth

3
推荐指数
2
解决办法
4693
查看次数

python-social-auth +移动应用程序

我有一个django应用程序,我为移动应用程序创建API.在用户身份验证方面,我简单地获取登录+传递并执行标准的django登录.当用户登录时,我生成令牌,保存并提供给移动应用程序.

现在谈到Facebook,我想实现python-social-auth库.我知道如何为标准网络实现它,这真的很微不足道.但是我不知道如何将它实现到我的移动API中以及如何将其添加到我的令牌中.

只是想......有没有可能做programatical auth所以我能够创建API方法并从那里调用社交认证的东西?但是如何在Facebook端"允许访问您的个人资料的XY应用程序"页面呢?

任何建议都有帮助 先感谢您.

python django facebook python-social-auth

2
推荐指数
1
解决办法
2055
查看次数

Python社交auth Django管道非类型错误

我在Django设置文件中使用python-social-auth模块进行Facebook登录时有以下pipleline:

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.get_username',
    'social.pipeline.user.user_details',
    'social.pipeline.social_auth.associate_by_email',
)
Run Code Online (Sandbox Code Playgroud)

我的登录方法如下:

当我第一次尝试使用Facebook进行身份验证时,我得到以下内容:/ error/facebook /'NoneType'对象中的AttributeError没有属性'provider'

def user_login(request):
    """ Login page view."""

    #context = RequestContext(request)
    context = RequestContext(request,
                             {'request': request,
                              'user': request.user})

    user = request.user

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)  # authentication

    if not user.is_anonymous():
        print user
        if not request.method == 'POST':

            user.backend = 'django.contrib.auth.backends.ModelBackend'
        if user.is_active:
            login(request, user)
            return HttpResponseRedirect('/')
        else:
            return render_to_response('main/login.html', {}, context)

    else:
        return render_to_response('main/login.html', …
Run Code Online (Sandbox Code Playgroud)

python django pipeline python-social-auth

2
推荐指数
1
解决办法
1362
查看次数

Spotify 的 Python 社交身份验证:重定向缺少“状态”参数

我正在需要访问用户的 Spotify 帐户的 Django 应用程序中实现 Python Social Auth。身份验证流程中的初始步骤有效:将请求发送到 Spotify 的“/授权”端点,并向用户显示一个模式,解释应用程序将被授权的访问范围。但是,当应用程序的重定向 uri 被请求时 ('/completed/spotify/') 会引发此异常:

AuthMissingParameter at /complete/spotify/
Missing needed parameter state
Request Method: GET
Request URL:    http://127.0.0.1:8000/complete/spotify/
Django Version: 1.8.2
Exception Type: AuthMissingParameter
Exception Value:    
Missing needed parameter state
Exception Location: /Users/brandon/Envs/group_playlist_generator/lib/python2.7/site-packages/social/backends/oauth.py in validate_state, line 86
Python Executable:  /Users/brandon/Envs/group_playlist_generator/bin/python
Python Version: 2.7.9
Python Path:    
['/Users/brandon/dev/group_playlist_generator',
 '/Users/brandon/Envs/group_playlist_generator/lib/python27.zip',
 '/Users/brandon/Envs/group_playlist_generator/lib/python2.7',
 '/Users/brandon/Envs/group_playlist_generator/lib/python2.7/plat-darwin',
 '/Users/brandon/Envs/group_playlist_generator/lib/python2.7/plat-mac',
 '/Users/brandon/Envs/group_playlist_generator/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/brandon/Envs/group_playlist_generator/lib/python2.7/lib-tk',
 '/Users/brandon/Envs/group_playlist_generator/lib/python2.7/lib-old',
 '/Users/brandon/Envs/group_playlist_generator/lib/python2.7/lib-dynload',
 '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/brandon/Envs/group_playlist_generator/lib/python2.7/site-packages']
Run Code Online (Sandbox Code Playgroud)

这个问题可能只是我在 Auth 方面的经验的一个函数,尤其是在 Django 的上下文中。我已经阅读了 PSA 源代码的相关部分,但我不明白这个“状态”参数是如何在 Spotify 和应用程序之间传递的。我看到此参数已添加到对 Spotify 的原始请求中,但我不确定如何确保将其传递回重定向​​ …

python django spotify oauth-2.0 python-social-auth

2
推荐指数
1
解决办法
1025
查看次数

python-social-auth - 我怎么能在 Django 中断开连接?

我正在使用a带有 href like 的标签,/disconnect/backend/然后它向我显示了一个空页面。我试过{% url %}模板标签,如:

{% url 'social:disconnect' 'twitter' %}
Run Code Online (Sandbox Code Playgroud)

它仍然创建与我在标签中使用的相同的 url。我怎么能断开帐户?或者也许还有一种方法可以只关联一个帐户?

python django python-social-auth

2
推荐指数
1
解决办法
1004
查看次数

接收错误:django.core.exceptions.ImproperlyConfigured

我在vm上安装了Python Social Auth,并尝试运行makemigrations并收到此错误:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/myenv/local/lib/python2.7/site-packages/django/core/management/__init__.py",
line 338, in execute_from_command_line
    utility.execute()
  File "/opt/myenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 312,
in execute
    django.setup()
  File "/opt/myenv/local/lib/python2.7/site-packages/django/__init__.py",
line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/opt/myenv/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, 
in populate
    app_config = AppConfig.create(entry)
  File "/opt/myenv/local/lib/python2.7/site-packages/django/apps/config.py",
line 127, in create
    "'%s' isn't a subclass of AppConfig." % entry)
django.core.exceptions.ImproperlyConfigured: 'social.apps.django_app.middleware.SocialAuthExceptionMiddleware'
isn't a subclass of AppConfig.
Run Code Online (Sandbox Code Playgroud)

我在本地主机上运行了相同的应用程序,并且运行正常。我不明白此错误的含义。请帮忙。

python django python-social-auth

2
推荐指数
1
解决办法
1111
查看次数

Facebook不会返回电子邮件Python社交身份验证

这是我的管道settings.py:

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'accounts.pipeline.create_user',
    'accounts.pipeline.update_user_social_data',
    # 'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
)
Run Code Online (Sandbox Code Playgroud)

以及这一行:

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
Run Code Online (Sandbox Code Playgroud)

我也尝试过这个:

FACEBOOK_EXTENDED_PERMISSIONS = ['email']
Run Code Online (Sandbox Code Playgroud)

在我的pipeline.py:

def create_user(strategy, details, user=None, *args, **kwargs):
    if user:
        return {
            'is_new': False
        }

    fields = dict((name, kwargs.get(name) or details.get(name))
                  for name in strategy.setting('USER_FIELDS',
                                               USER_FIELDS))

    if not fields:
        return

    if strategy.session_get('signup') == 'UserType1':
        user1 = UserType1.objects.create_user(username=fields.get('username'))
        user1.user_type = User.USERTYPE1
        user1.save()

        return {
            'is_new': True,
            'user': user1
        }

    elif strategy.session_get('signup') == 'UserType2': …
Run Code Online (Sandbox Code Playgroud)

python django facebook django-socialauth python-social-auth

2
推荐指数
1
解决办法
2353
查看次数

如何使用social-auth-app-django刷新令牌?

我使用Python Social Auth - Django登录我的用户.

我的后端是微软,所以我可以使用Microsoft Graph,但我不认为它是相关的.

Python Social Auth处理身份验证,但现在我想调用API,为此,我需要一个有效的访问令牌.根据用例我可以得到:

social = request.user.social_auth.get(provider='azuread-oauth2')
response = self.get_json('https://graph.microsoft.com/v1.0/me',
                         headers={'Authorization': social.extra_data['token_type'] + ' ' 
                                                   + social.extra_data['access_token']})
Run Code Online (Sandbox Code Playgroud)

但访问令牌只有3600秒有效,所以我需要刷新,我想我可以手动完成,但必须有一个更好的解决方案.如何刷新access_token?

python django python-social-auth

2
推荐指数
2
解决办法
2490
查看次数

Django Social Auth:Google OAuth2 - 仅显示来自受限域列表的电子邮件

我在网站上有 Django Social Auth(pypi 包social-auth-app-django)与 Google OAuth2 一起使用。

当他们打开页面时,他们会被重定向到 Google 的 OAuth2 身份验证。这非常有效,如果他们尝试使用不在我的限制列表中的电子邮件地址登录,他们会收到 AuthForbidden 异常。我为此添加了一个陷阱,并向他们显示一个不允许他们登录此网站的页面。到目前为止一切都很好。

但是,我希望无效的电子邮件帐户根本不显示在 Google 身份验证页面的列表中。在使用带有参数的 javascript 之前,我已经通过手动调用身份验证页面来完成此操作,但我不确定如何使用罐装 Django 社交身份验证模块来执行此操作。

这可以做到吗?如果可以,怎么做?

我有中间件可以检测用户是否未登录并返回一个 login() 视图,该视图将用户重定向到 Google 身份验证页面。

视图.py

# Login using OAuth2.
@csrf_protect
def login(request):
    next_page = request.path
    if next_page is None or next_page == '':
        next_page = request.POST.get('next', request.GET.get('next', ''))

    # Check if they are already logged in and redirect them to the original page if so.
    if hasattr(request, 'user') and request.user.is_authenticated:
        return HttpResponseRedirect(next_page)

    # Otherwise, send them …
Run Code Online (Sandbox Code Playgroud)

django django-socialauth python-social-auth

2
推荐指数
1
解决办法
1354
查看次数