标签: python-social-auth

在没有社交后端的情况下在Python-Social-Auth上注册新用户的最佳方法是什么?

我知道这听起来有点混乱,但有些网站允许多种方式进行注册,比如使用社交网络(FB或TW,当然我正在使用python-social-auth这个porpouse)或使用表单来创建一个新用户......

有没有办法使用自定义注册表单(即使用一组常用的字段,如电子邮件,密码,名字等)将新用户注册到我的网站,并将其与python-social-auth集成?

谢谢.

python django python-social-auth

5
推荐指数
1
解决办法
422
查看次数

python social auth加载策略并手动验证用户版本0.1.26

我在过去的两个月里使用python social auth进行社交认证,这很棒.我需要QQ支持,因此安装了最新的git commit(23e4e289ec426732324af106c7c2e24efea34aeb - 不是发布的一部分).到目前为止,我曾使用以下代码对用户进行身份验证:

    # setup redirect uri in order to load strategy
    uri = redirect_uri = "social:complete"
    if uri and not uri.startswith('/'):
        uri = reverse(redirect_uri, args=(backend,))

    # load the strategy
    try:
        strategy = load_strategy(
            request=request, backend=backend,
            redirect_uri=uri, **kwargs
        )
        strategy = load_strategy(request=bundle.request)
    except MissingBackend:
        raise ImmediateHttpResponse(HttpNotFound('Backend not found'))

    # get the backend for the strategy
    backend = strategy.backend

    # check backend type and set token accordingly
    if isinstance(backend, BaseOAuth1):
        token = {
            'oauth_token': bundle.data.get('access_token'),
            'oauth_token_secret': bundle.data.get('access_token_secret'),
        } …
Run Code Online (Sandbox Code Playgroud)

python-social-auth

5
推荐指数
0
解决办法
1252
查看次数

使用Google身份验证时出现Python Social Auth-导入错误

我在一个多月前成功地关注了这篇博文:http://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/

当我创建一个新环境并重新创建这些步骤时,我现在no module named google_auth在模板渲染过程中遇到导入错误.

它追溯到这一行:

<a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}">Login</a>
Run Code Online (Sandbox Code Playgroud)

看起来django没有在社交应用程序中查找正确的模板处理?有关为什么不再有效的任何想法?

#settings.py
INSTALLED_APPS = (... , 'social.apps.django_app.default', ...)

AUTHENTICATION_BACKENDS = ('social.backends.google.GoogleOAuth2', 'django.contrib.auth.backends.ModelBackend')

TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect')

#urls.py
urlpatterns = patterns('', 
url('', include('social.apps.django_app.urls', namespace='social')),
url('', include('django.contrib.auth.urls', namespace='auth')),
url(r'^$', 'app.views.home', name='home'),
)
Run Code Online (Sandbox Code Playgroud)

编辑:下面的完整追溯

Environment:
Request Method: GET

Django Version: 1.7
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'charts',
 'social.apps.django_app.default',
 'djcelery',
 'kombu.transport.django')
Installed …
Run Code Online (Sandbox Code Playgroud)

python django python-social-auth

5
推荐指数
1
解决办法
2453
查看次数

使用OAuth2进行Django Rest Framework身份验证

假设我想构建一个使用RESTful API作为后端的iOS应用程序.

我想要使​​用Django Rest Framework.原因有三:

  1. Python太棒了
  2. Django太棒了
  3. Django Rest Framework很受欢迎且文档齐全

我的应用需要对用户进行身份验证,以控制对不同API端点的访问.我需要通过验证我的客户

  • 我自己的OAuth2提供商
  • 第三方OAuth2提供商(例如Facebook)

我发现Django Oauth Toolkit是创建自己的OAuth2提供程序的事实标准.与Django Rest Framework的集成也很好地记录并且易于实现.

到现在为止还挺好.

现在如果我想通过第三方添加注册/登录?(Facebook,Twitter等).

我猜这是过程的样子.

通过第三方提供商进行身份验证

没有第三方

通过自己的OAuth提供商进行身份验证

我想我需要将社交帐户令牌添加到用户模型(用于重新验证和与第三方APIS交互).Django-allauth这样做,我在我的一个项目中使用它,但遗憾的是django-allauth似乎不适合当前的用例,因为Django不提供客户端.

那么有一种方法(一个应用程序)可以轻松地将社交媒体登录/注册与Django Rest Framework和Django OAuth Toolkit集成吗?我遇到了Python Social Auth,但我不确定如何将它与Django Oauth Toolkit混合使用.

我在正确的道路上吗?

您将如何使用Django实现这样的身份验证体系结构/进程?

谢谢

django rest facebook django-rest-framework python-social-auth

5
推荐指数
0
解决办法
163
查看次数

使用 Python-social-auth 未在管道中设置社交用户

AttributeError at /complete/google-oauth2/

'NoneType' object has no attribute 'provider'
Run Code Online (Sandbox Code Playgroud)

新用户或已经注册的用户会发生这种情况https://github.com/omab/python-social-auth/blob/master/social/actions.py#L69,这是一个新问题。当我使用自定义管道时,它出现了,但它以前可以工作,现在恢复到最基本的 python-social-auth 设置不起作用。

即使重新加载数据库和刷新同步数据库。(这是 Django 1.4.20,我们正在升级的一个旧项目)。

问题很明显,在默认管道中的任何地方,社交用户都不能正常工作,但我对 python-social-auth 代码的理解不够好,我在这里兜圈子。任何指示或帮助将不胜感激。

出现在我的堆栈跟踪中的 500 以防有任何帮助。

[23/Jul/2015 12:00:32] "GET /complete/google-oauth2/?state=MRFnOQG6Cv5Cmb1xqdcp53C33dDrFf7C&code=4/2bgjgYgxFtqB2c10BInigkigGfy4ZNOSYBqyHBUdLGo&authuser=0&prompt=consent&session_state=4c6c24bdd3100a506c4744be8ab9b793ed6399d5..a5f9 HTTP/1.1" 500 148571
Run Code Online (Sandbox Code Playgroud)

这是代码阻塞的数据,这显然是因为管道的某些先前部分没有将“social_user”放入 user. 但我不知道哪里会失败,对此更熟悉的人是否对默认管道可能失败的地方有任何建议?

partial None
is_authenticated    False
args    ()
is_new  False
redirect_value  ''
user    <User: 4o5bb5o5>
social_user None
kwargs  {}
login   <function _do_login at 0xaef3de9c>
backend <social.backends.google.GoogleOAuth2 object at 0x9e68fac>
data    <QueryDict: {u'state': [u'dwMOHkBxsVgvj4mwL54LXqihzJVYMWTV'], u'code': [u'4/fjOVlVyAK5mS_mcv7uHVWQsFycpjlbB_YOy4F7omIIY'], u'prompt': [u'none'], u'session_state': [u'ab65081ee8e4a3720d5963deced4cabc7b259a85..8f10'], u'authuser': [u'0']}>
redirect_name   
'next'
Run Code Online (Sandbox Code Playgroud)

当我导航到主页时,我可以使用 gmail 帐户正常登录。(虽然一些在 create_user 之后发生的 post_save …

python django python-social-auth

5
推荐指数
1
解决办法
1698
查看次数

python social auth和django,用Facebook api 2.4发送电子邮件

我在我的django项目中使用python social auth来提供Facebook登录功能.我可以在弹出窗口中看到Facebook提供的电子邮件.但它在我的部分管道中变得空洞.相同的代码与我的其他Facebook应用程序正常工作,除了api版本之外设置完全相同(以前它是2.3,现在是2.4).没有选项可以将Facebook api版本更改为2.3.我的python-social-auth版本是0.2.12以下是我的设置文件中的相关数据

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email',]
FACEBOOK_EXTENDED_PERMISSIONS = ['email',]
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['email',]
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_LOGIN_ERROR_URL = '/'

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',
    'home.pipeline.require_email',
    'social.pipeline.social_auth.associate_by_email',  # <--- enable this one
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    'home.pipeline.send_welcome_mail',
)

SOCIAL_AUTH_FACEBOOK_KEY = os.environ['SOCIAL_AUTH_FACEBOOK_KEY']
SOCIAL_AUTH_FACEBOOK_SECRET = os.environ['SOCIAL_AUTH_FACEBOOK_SECRET']
Run Code Online (Sandbox Code Playgroud)

这是我的自定义部分管道功能

@partial
def require_email(strategy, backend, uid, details, user=None, *args, **kwargs):
    print details
    #some stuff......
Run Code Online (Sandbox Code Playgroud)

此功能打印空电子邮件ID,如下所示

{'username': u'Anurag Jain', 'fullname': u'Anurag Jain', 'last_name': u'Jain', 'email': '', 'first_name': u'Anurag'}
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我解决这个问题.

django facebook-graph-api python-social-auth

5
推荐指数
1
解决办法
672
查看次数

如何将flask-migrate与其他declarative_bases一起使用

我正在尝试在Flask中实现python-social-auth。我已经消除了很多麻烦,同时尝试解释约4篇教程和一本完整的Flask书,并且觉得Flask-migrate陷入了某种僵局。

我目前正在使用以下代码创建python-social-auth在flask-sqlalchemy环境中运行所需的表。

from social.apps.flask_app.default import models
models.PSABase.metadata.create_all(db.engine)
Run Code Online (Sandbox Code Playgroud)

现在,他们显然正在使用某种形式的自己的Base,与我的实际db-object无关。反过来,这会使Flask-Migrate完全错过这些表,并在迁移中将其删除。现在,很明显,我可以从每次删除操作中删除这些db-drop,但是我可以想象,这是一件事会被遗忘的事情之一,突然之间我再也没有OAuth-tie了。

我已经获得了此解决方案,以按照python-social-auth Flask示例的建议使用manage.py-command syncdb的用法(和修改)

Flask-Migrate的作者Miguel Grinberg在回复一个看起来与我非常相似的问题。

我在堆栈溢出时能找到的最接近的是这个,但对我来说,它并没有给我们太多启示,而且答案从未被接受(而且我无法使它起作用,我已经尝试了几次)

供参考,这是我的manage.py:

#!/usr/bin/env python

from flask.ext.script import Server, Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand


from app import app, db

manager = Manager(app)
manager.add_command('runserver', Server())
manager.add_command('shell', Shell(make_context=lambda: {
    'app': app,
    'db_session': db.session
}))

migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)

@manager.command
def syncdb():
    from social.apps.flask_app.default import models
    models.PSABase.metadata.create_all(db.engine)
    db.create_all()

if __name__ == '__main__':
    manager.run()
Run Code Online (Sandbox Code Playgroud)

为了明确起见,db init / migration / upgrade命令仅创建我的用户表(显然是迁移表),而不创建社交auth表,而syncdb命令适用于python-social-auth表。 …

sqlalchemy flask-sqlalchemy flask-migrate python-social-auth

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

如何仅与谷歌一起使用 python-social-auth ?

我正在尝试将谷歌身份验证添加到我的项目中

我安装了它:

pip install python-social-auth
Run Code Online (Sandbox Code Playgroud)

并将其添加到settings.py中:

SOCIAL_AUTH_USER_MODEL = 'accounts.CustomUser'##

SOUTH_MIGRATION_MODULES = {
    'default': 'social.apps.django_app.default.south_migrations'
    }

AUTHENTICATION_BACKENDS = (
    'myproject.middleware.AuthenticationCMSBackend',##
    'social.backends.google.GoogleOpenId',
    'social.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

LOGIN_REDIRECT_URL = '/'

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY  = '507847...m.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'SEt-6...0j3'"""

TEMPLATE_CONTEXT_PROCESSORS =  (
    ...
    'django.core.context_processors.request',
    'social.apps.django_app.context_processors.backends',
    'social.apps.django_app.context_processors.login_redirect',
)
Run Code Online (Sandbox Code Playgroud)

至于 SOCIAL_AUTH_GOOGLE_OAUTH2_KEY 和 secert,我访问https://console.developers.google.com/apis/credentials并使用 localhost url 创建它们(目前用于测试)

我在模板中这样称呼它:

<a href="{% url 'social:begin' 'google-oauth2' %}"> login </a>
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误:

找不到后端

我究竟做错了什么?

下一步,我想确保只有我验证的用户才能验证任何拥有谷歌帐户的人,该怎么做?

django google-authentication django-1.6 python-social-auth

5
推荐指数
1
解决办法
3950
查看次数

Python-social-auth 登录后重定向到另一个域

使用 登录后是否可以重定向到另一个网站python-social-auth

比方说:

<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}"></a>
Run Code Online (Sandbox Code Playgroud)

上面的例子是根据文档,它运行良好,但是当我尝试这个时:

<a href="{% url 'social:begin' 'facebook' %}?next=http://www.google.com/"></a>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

http://example.com:8000/accounts/profile/ Not Found
Run Code Online (Sandbox Code Playgroud)

这是有道理的;我没有定义这个 URL

此时我已经登录,但我看到一个错误页面。

但是使用相同的配置,如果我重定向到我自己的网站,这有效,我认为这是有关设置的问题,但我不知道是哪一个。

编辑:

如果我next在第一个配置中删除 GET 参数,它会引发相同的错误。

python django redirect python-social-auth

5
推荐指数
1
解决办法
1902
查看次数

获取“AuthStateMissing ...会话值状态丢失。” 当将 AtlassianOAuth2 与 Django 一起使用时要调用回调 URI

我试图在 Django 应用程序中设置 oauth2 身份验证。这是我的设置:

\n\n
*other parts ommited*\n# AUTH STUFF\n\nAUTHENTICATION_BACKENDS = (\n    \'social_core.backends.atlassian.AtlassianOAuth2\',\n    \'django.contrib.auth.backends.ModelBackend\',\n)\n\nSOCIAL_AUTH_ATLASSIAN_KEY = \' *my atlassian key here* \'\nSOCIAL_AUTH_ATLASSIAN_KEY_SECRET = \' *my atlassian secret key here* \'\nLOGIN_URL = \'/auth/login/atlassian-oauth2\'\nLOGIN_REDIRECT_URL = \'/\'\nLOGOUT_REDIRECT_URL = \'/\'\nSOCIAL_AUTH_URL_NAMESPACE = \'social\'\n\nSESSION_COOKIE_SECURE = False\n# i had to do that^, based on what i have read from\n# /sf/ask/2633211591/\n# but it still doesn\'t work, sadly...\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的登录页面视图:

\n\n
def index(request):\n    session_id = request.session.session_key\n    session_id = hashlib.sha256(str(session_id).encode(\'utf-8\')).hexdigest()\n    auth_url = \'https://auth.atlassian.com/authorize?audience=api.atlassian.com&client_id=*my_client_id_here*&scope=read%3Ajira-user%20read%3Ajira-work%20manage%3Ajira-project&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcomplete%2Fatlassian%2F&state=$\'+ session_id +\'&response_type=code&prompt=consent\'\n    print(auth_url)\n    context = {\n        \'message\': …
Run Code Online (Sandbox Code Playgroud)

django oauth django-authentication jira-rest-api python-social-auth

5
推荐指数
1
解决办法
3369
查看次数