social_details - Get the information we can about the user and return it in a simple format to create the user instance later. On some cases the details are already part of the auth response from the provider, but sometimes this could hit a provider API.
social_uid - Get the social uid from whichever service we’re authing thru. The uid is the unique identifier of the given user in the provider.
auth_allowed - Verifies that the current auth process is valid within the current project, this is where emails and domains whitelists are applied (if defined).
social_user - Checks if the current social-account is already associated in the site.
get_username- Make up a username for this person, appends a random string at the end if there’s any collision.
create_user - Create a user account if we haven’t found one yet.
associate_user - Create the record that associated the social account with this user.
extra_data - Populate the extra_data field in the social record with the values specified by settings (and the default ones like access_token, etc).
user_details - Update the user record with any changed info from the auth service.
def login(request, message=None): """login will either show the user a button to login with github, and then a link to their collections (given storage is set up) or a link to connect storage (if it isn't) """ if message is not None: messages.info(request, message)
context = None if request.user.is_authenticated: if not request.user.agree_terms: return render(request, "terms/usage_agreement_login.html", context) context = validate_credentials(user=request.user) return render(request, "social/login.html", context)
def social_user(backend, uid, user=None, *args, **kwargs): """OVERRIDED: It will give the user an error message if the account is already associated with a username.""" provider = backend.name social = backend.strategy.storage.user.get_social_auth(provider, uid)
if social: if user and social.user != user: msg = "This {0} account is already in use.".format(provider) return login(request=backend.strategy.request, message=msg) # raise AuthAlreadyAssociated(backend, msg) elif not user: user = social.user
return { "social": social, "user": user, "is_new": user is None, "new_association": social is None, }
if not backend.auth_allowed(response,details): raise AuthForbidden(backend)
shub.apps.users.views.social_user
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
原social_user
def social_user(backend,uid,user=None,*args,**kwargs): provide = backend.name social = backend.strategy.storage.user.get_social_auth(provider,id) if social: if user and social.user!=user: msg = 'This account is already in use' raise AuthAlreadyAssociated(backend,msg) elif not user: user = social.user; return {'social':social, 'user':user, 'is_new':user is None, 'new_association' :social is None
}
social_core.pipeline.user.get_username
github 的重定向url
1 2 3 4 5 6 7 8 9 10 11
点击login with github后跳转 https://github.com/login?client_id=776ca8fdb3919f16e2f8&return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3D776ca8fdb3919f16e2f8%26redirect_uri%3Dhttp%253A%252F%252Fwww.hustshub.cn%252Fcomplete%252Fgithub%252F%26response_type%3Dcode%26scope%3Drepo%252Cuser%26state%3D4ZDP9Ug7hEoce1a001zLnO1XywIZUw7U