标签: python-social-auth

如何使用Python-Social-auth和Django检索Facebook好友的信息

如何使用Python-Social-auth和Django检索Facebook好友的信息?我已经检索了个人资料信息并对用户进行了身份验证,但我希望获得有关他们朋友的更多信息并邀请他们加入我的应用.谢谢!

python django facebook facebook-graph-api python-social-auth

11
推荐指数
1
解决办法
6285
查看次数

使用Django的python-social-auth:ImportError:没有名为'social_django'的模块

所有包安装!! 嗨,我正在使用python 3.5 Django == 1.10我安装了Python-social-auth执行命令Python manage.py传输错误收到!

Traceback (most recent call last):
File "manage.py", line 22, in 
execute_from_command_line(sys.argv)
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django
/core/management/init.py", line 367, in execute_from_command_line
utility.execute()
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django/core/management/init.py", line 341, in execute
django.setup()
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django/init.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/berluskuni/web_project/exprender/.exprender/lib64/python3.5/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", …
Run Code Online (Sandbox Code Playgroud)

django python-3.x python-social-auth

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

python oauthlib:在转义中ValueError"只有unicode对象可以逃脱"

我正在使用python-social-auth我的Django应用程序登录社交网络.在我的本地机器上一切正常,但当我部署到服务器时,我收到以下错误:

oauthlib.oauth1.rfc5849.utils in escape
ValueError: Only unicode objects are escapable. Got None of type <type 'NoneType'>.
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

File "django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "social/apps/django_app/utils.py", line 45, in wrapper
    return func(request, backend, *args, **kwargs)
File "social/apps/django_app/views.py", line 12, in auth
    return do_auth(request.social_strategy, redirect_name=REDIRECT_FIELD_NAME)
File "social/actions.py", line 25, in do_auth
    return strategy.start()
File "social/strategies/base.py", line 66, in start
    return self.redirect(self.backend.auth_url())
File "social/backends/oauth.py", line 99, in auth_url
    token = self.set_unauthorized_token()
File "social/backends/oauth.py", line 158, in …
Run Code Online (Sandbox Code Playgroud)

python django oauth python-requests python-social-auth

9
推荐指数
1
解决办法
2305
查看次数

在Django中使用python-social-auth和电子邮件注册复制电子邮件

我在我的项目中使用python-social-auth和电子邮件注册.对于用户模型,我使用AbstractBaseUser的子类:

class User(AbstractBaseUser):
    USERNAME_FIELD = 'email'


AUTH_USER_MODEL = 'userprofile.User'
Run Code Online (Sandbox Code Playgroud)

但是,如果用他的电子邮件注册的用户(demo@demo.com)和密码尝试使用与同一电子邮件地址关联的Facebook帐户登录,则会收到以下错误:

IntegrityError at /social/complete/facebook/
duplicate key value violates unique constraint "userprofile_user_email_key"
DETAIL:  Key (email)=(demo@demo.com) already exists.

/Users/vera/.virtualenvs/app/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
                    response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
/Users/vera/.virtualenvs/app/lib/python2.7/site-packages/django/views/decorators/csrf.py in wrapped_view
        return view_func(*args, **kwargs) ...
/Users/vera/.virtualenvs/app/lib/python2.7/site-packages/social/apps/django_app/utils.py in wrapper
            return func(request, backend, *args, **kwargs) ...
/Users/vera/.virtualenvs/app/lib/python2.7/site-packages/social/apps/django_app/views.py in complete
                       redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs) ...
/Users/vera/.virtualenvs/app/lib/python2.7/site-packages/social/actions.py in do_complete
                                 *args, **kwargs) ...
/Users/vera/.virtualenvs/app/lib/python2.7/site-packages/social/strategies/base.py in complete
        return self.backend.auth_complete(*args, **kwargs) ...
/Users/vera/.virtualenvs/app/lib/python2.7/site-packages/social/backends/facebook.py in auth_complete
        return self.do_auth(access_token, response, *args, **kwargs) ...
/Users/vera/.virtualenvs/app/lib/python2.7/site-packages/social/backends/facebook.py …
Run Code Online (Sandbox Code Playgroud)

python django django-authentication python-social-auth

8
推荐指数
1
解决办法
2296
查看次数

找不到用于linkedin oauth2的python-social-auth后端

我正在尝试使用python-social-auth在我的应用程序中合并linkedin oauth2.但是,当我在Chrome中导航到127.0.0.1:8000/login/linkedin/时,我收到"未找到后端"错误.具体来说,日志显示以下错误:

[08/Sep/2014 16:44:38] "GET /login/linkedin HTTP/1.1" 301 0
[08/Sep/2014 16:44:38] "GET /login/linkedin/ HTTP/1.1" 404 1608
Run Code Online (Sandbox Code Playgroud)

我在settings.py中有以下相关代码:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'github_app',
    'tech_seeker',
    'social.apps.django_app.default'
)

SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = "<MY_KEY_HERE>"
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = "<MY_SECRET_HERE>"

SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy'

AUTHENTICATION_BACKENDS = (
    'social.backends.linkedin.LinkedinOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'github_app.auth_pipeline.user'
)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

python django python-social-auth

8
推荐指数
1
解决办法
3260
查看次数

使用Django OAuth2 Toolkit以编程方式生成访问令牌

我正在使用Python Social Auth和Django OAuth Toolkit来管理我的用户帐户并限制对我的REST API的访问.

我可以为使用常规手动注册我的应用的用户创建令牌

curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/

但是,当我通过访问令牌向PSA注册我的用户时,我想为自己的应用创建一个OAuth2 Toolkit令牌,并将其作为JSON返回给客户端,以便它可以使用它来通过我的API发出请求.

目前,我生成令牌简单地使用generate_tokenoauthlib,是好的做法呢?我应该考虑其他因素吗?

from oauthlib.common import generate_token

...

@psa('social:complete')
def register_by_access_token(request, backend):
    # This view expects an access_token GET parameter, if it's needed,
    # request.backend and request.strategy will be loaded with the current
    # backend and strategy.
    token = request.GET.get('access_token')
    user = request.backend.do_auth(token)

    if user:
        login(request, user)
        app = Application.objects.get(name="myapp")

        # We delete the old one
        try:
            old = AccessToken.objects.get(user=user, application=app)
        except: …
Run Code Online (Sandbox Code Playgroud)

django oauth-2.0 python-social-auth

8
推荐指数
1
解决办法
3308
查看次数

在python-social-auth中从google和facebook检索个人资料图片

如何通过扩展管道使用python-social-auth从google和facebook检索个人资料图片和出生日期?我已经读过我可以创建函数并设置它们的路径,但我不知道必须检索的属性名称.请帮忙!

python django python-2.7 python-social-auth

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

决定何时使用Python Social Auth刷新OAUTH2令牌

我认为这主要是关于最佳实践的问题.

我有一个OAUTH2提供程序,只要刷新令牌就会发出访问令牌(有效期为10小时).

我在这里发现刷新访问令牌非常容易,但我无法理解如何确定何时刷新.

简单的答案可能是"当它不再起作用时",这意味着当我从后端获得HTTP 401时.这个解决方案的问题在于效率不高,而且我只能假设因为令牌已过期而得到401.

我的django应用程序我发现user social auth有一个Extra data字段包含这样的东西:

{ "scope": "read write", "expires": 36000, "refresh_token": "xxxxxxxxxxxxx", "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "token_type": "Bearer" }

但我不确定如何使用该expires字段.

所以我的问题是:我怎么知道访问令牌是否已经过期而我需要刷新它?

编辑:我刚刚发现此评论似乎相关,但我无法理解如何在管道中插入这个新功能,以便在令牌刷新期间工作.

python django oauth-2.0 python-social-auth

8
推荐指数
1
解决办法
1623
查看次数

python 社交身份验证中缺少会话状态

我按照本教程(https://artandlogic.com/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/)进行操作,并且收到以下错误。我已将服务器托管在 EC2 实例上,并且有一个域http://(xyz).com。我还看到了这个问题的答案(使用 django python-social-auth 重定向后会话值丢失),但我没有得到任何帮助。\n在此输入图像描述

\n\n

这是文本中的堆栈跟踪

\n\n
 AuthStateMissing at /api/user/complete/google-oauth2/\nSession value state missing.\nRequest Method: GET\nRequest URL:    http://interviewmiles.com:8000/api/user/complete/google-oauth2/?state=9Sa5JSkbcAbbGzBtqpx6jtbLCuJPe6kJ&code=4/c4VTig14u7THYLd1M4VoTRf1dnq58wp6S68EbkSwhZs&authuser=0&session_state=8aa4e419c219643dc264950a24151457677d99ae..b805&prompt=none\nDjango Version: 1.9.7\nException Type: AuthStateMissing\nException Value:    \nSession value state missing.\nException Location: /usr/local/lib/python2.7/site-packages/social/backends/oauth.py in validate_state, line 88\nPython Executable:  /usr/bin/python\nPython Version: 2.7.10\nPython Path:    \n[\'/home/ec2-user/interviewmiles/login\',\n \'/usr/local/lib/python2.7/site-packages/django_cors_headers-1.1.0-py2.7.egg\',\n \'/usr/lib64/python27.zip\',\n \'/usr/lib64/python2.7\',\n \'/usr/lib64/python2.7/plat-linux2\',\n \'/usr/lib64/python2.7/lib-tk\',\n \'/usr/lib64/python2.7/lib-old\',\n \'/usr/lib64/python2.7/lib-dynload\',\n \'/usr/local/lib64/python2.7/site-packages\',\n \'/usr/local/lib/python2.7/site-packages\',\n \'/usr/lib64/python2.7/site-packages\',\n \'/usr/lib/python2.7/site-packages\',\n \'/usr/lib64/python2.7/dist-packages\',\n \'/usr/lib64/python2.7/dist-packages/PIL\',\n \'/usr/lib/python2.7/dist-packages\']\n\n/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response\n                response = self.process_exception_by_middleware(e, request) ...\n\n\xe2\x96\xb6 Local vars\n/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response\n                    response = wrapped_callback(request, *callback_args, **callback_kwargs) ...\n\xe2\x96\xb6 Local vars\n/usr/local/lib/python2.7/site-packages/django/views/decorators/cache.py in …
Run Code Online (Sandbox Code Playgroud)

python django cookies session python-social-auth

8
推荐指数
1
解决办法
5144
查看次数

Django - DRF (django-rest-framework-social-oauth2) 和 React 创建用户

我正在使用 DRF 和 ReactJS,我正在尝试使用 django-rest-framework-social-oauth2.

在 React 中,我向后端发送请求,auth/login/patreon/然后到达 Patreon OAuth 屏幕,在那里我说我想使用 PAtreon 登录。Patreon 然后返回一个请求到后端的accounts/profile。此时,python-social-oauth用户也已创建。

在这一点上我很困惑。如何向 Patreon 发出登录请求,在后端创建用户,并将会话信息返回给 React 前端,以便我可以在来自前端的所有后续请求中包含会话信息?我不希望返回的请求在后端/accounts/profile,是吗?

更新 我现在意识到我可以设置重定向 url,LOGIN_REDIRECT_URL但是,我现在如何检索会话 ID,将其传递给前端,并将其包含在所有请求中?

django django-rest-framework reactjs python-social-auth

8
推荐指数
1
解决办法
593
查看次数