Facebook和linkedin没有正确填写电子邮件字段

时间:2014-06-23 16:28:45

标签: python-social-auth

Google和github登录正常运行但由于某些原因我无法通过facebook和linkedin帐户正确填写电子邮件字段。

以下是涉及的文件

__init__.py

db = SQLAlchemy(app)
login_manager=LoginManager()
login_manager.init_app(app)

# Import blueprints from app (example: from app.posts import posts)
from app.users import users

# Register all blueprints to the main app (example: app.register_blueprint(posts))
app.register_blueprint(users)
app.register_blueprint(social_auth)

#3rd part db interaction
init_social(app, db)

# Import main views from app
from app import views

#Set login bootback
login_manager.login_view ='/login'

app.context_processor(backends)

Settings.py配置,密钥已从帖子中删除

#Flask
SECRET_KEY = ''
SESSION_COOKIE_NAME = ''

### Python Social Auth ###
DEBUG_TB_INTERCEPT_REDIRECTS = False
SESSION_PROTECTION = 'strong'

#Redirects and Paths
SOCIAL_AUTH_LOGIN_URL = '/login'
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_BACKEND_ERROR_URL = '/login'

SOCIAL_AUTH_USER_MODEL = 'app.users.models.User'
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True


#Facebook
SOCIAL_AUTH_FACEBOOK_KEY=''
SOCIAL_AUTH_FACEBOOK_SECRET=''
#Google
SOCIAL_AUTH_GOOGLE_KEY=''
SOCIAL_AUTH_GOOGLE_SECRET=''
#LinkedIn
SOCIAL_AUTH_LINKEDIN_KEY=''
SOCIAL_AUTH_LINKEDIN_SECRET=''
#Github
SOCIAL_AUTH_GITHUB_KEY=''
SOCIAL_AUTH_GITHUB_SECRET=''


SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
    'social.backends.google.GoogleOpenId',
    'social.backends.google.GoogleOAuth2',
    'social.backends.google.GoogleOAuth',
    'social.backends.facebook.FacebookOAuth2',
    'social.backends.linkedin.LinkedinOAuth',
    'social.backends.github.GithubOAuth2',
)

这是模型本身,非常接近omab提供的示例

models.py

from __future__ import absolute_import, print_function

from time import time
import functools
import uuid

import pbkdf2
from marshmallow import Serializer, fields
from app import db


ROLE_USER=0
ROLE_ADMIN=1
ROLE_GOD=2

default_img = '/assets/images/avatars/default.jpg'

class User(db.Model):
    #meat n' potatoes
    id = db.Column(db.Integer, primary_key=True)
    img=db.Column(db.String(255), default=default_img)
    username = db.Column(db.String(255))
    email = db.Column(db.String(200), unique=True)
    first_name = db.Column(db.String(30))
    last_name = db.Column(db.String(40))
    created_at = db.Column(db.BigInteger, default=time())

    #controls
    role = db.Column(db.SmallInteger, default=ROLE_USER)
    is_active = db.Column(db.Boolean, default=True)
    is_authenticated= db.Column(db.Boolean, default=True)

    #password
    salt = db.Column(db.String(50))
    pass_hash = db.Column(db.String(255)) 


    def __unicode__(self):
        return self.email

    def __repr__(self):
        return '<User %r>' % self.email

    def is_authenticated(self):
        return self.is_authenticated

    def is_anonymous(self):
        return False

    def is_active(self):
        return self.is_active

    def get_id(self):
        return unicode(self.id)

    def _check_password(self, password):
        hash_check = pbkdf2.crypt(password, self.salt, 1000)
        if hash_check ==self.pass_hash:
            valid=True
        else:
            valid=False

        return valid

    def validate_user(self,password):
        p=self.check_password(password=password)
        if p:
            return True;
        else:
            return False;

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }

class UserSerializer(Serializer):
    id=fields.Integer()
    img=fields.String()
    email=fields.String()
    first_name=fields.String()
    last_name=fields.String()

1 个答案:

答案 0 :(得分:0)

在我愚蠢的文档中发现这一点,没有意识到他们会有不同的请求参数: http://psa.matiasaguirre.net/docs/backends/index.html

<强>更新

请参阅Babken Vardanyan的回答

https://stackoverflow.com/a/46807907/2529583