websauna.system.user.social module

class websauna.system.user.social.EmailSocialLoginMapper(registry, provider_id)[source]

Bases: object

Base class for mapping internal users to social network (OAuth) users.

activate_user(dbsession, user)[source]

Checks to perform when the user becomes a valid user for the first time.

If this user has already started sign up process through email we need to cancel that.

create_blank_user(user_model, dbsession, email)[source]

Create a new blank user instance as we could not find matching user with the existing details.

Parameters
  • user_model (Callable[…, InterfaceClass]) – Class to be used for user creation.

  • dbsession (Session) – SQLAlchemy Session object.

  • email (str) – User email.

Return type

InterfaceClass

Returns

Newly created user.

get_existing_user(user_model, dbsession, email)[source]

Check if we have a matching user for the email already.

Parameters
  • user_model (Callable[…, InterfaceClass]) – User class to query for the user with given email.

  • dbsession (Session) – SQLAlchemy Session object.

  • email (str) – User email.

Return type

InterfaceClass

Returns

User object.

get_or_create_user_by_social_medial_email(request, user)[source]

Given a user information returned by Authomatic, return an existing User object from our database or create one if it does not exists.

Parameters
  • request (Request) – Pyramid request object.

  • user (User) – A user returned by Authomatic.

Return type

InterfaceClass

Returns

User object.

provider_id = None

This is the string we use to map configuration for the

update_every_login_social_data(user, data)[source]

Update internal user data on every login.

Bt default, sets user.user_data[“social”][“facebook”] or user.user_data[“social”][“yoursocialnetwork”] to reflect the raw data given us by import_social_media_user().

Parameters
  • user (InterfaceClass) – User object.

  • data (dict) – Normalized data.

update_first_login_social_data(user, data)[source]

Set the initial data on the user model.

When the user logs in from a social network for the first time (no prior logins with this email before) we fill in blanks in the user model with incoming data. Default action is not to set any items.

Parameters
  • user (InterfaceClass) – User object.

  • data (dict) – Normalized data.

class websauna.system.user.social.FacebookMapper(registry, provider_id)[source]

Bases: websauna.system.user.social.EmailSocialLoginMapper

Map and login Facebook OAuth users to internal users.

You must have application created in developers.facebook.com

The application must have its consumer_key and consumer_secret configured in the secrets config file.

For testing: The application must have one Web site platform configured in developers.facebook.com, pointing to http://localhost:8521/ and Valid OAuth redirect URLs to http://localhost:8521/login/facebook

capture_social_media_user(request, result)[source]

Extract social media information from the Authomatic login result in order to associate the user account.

Parameters
  • request (Request) – Pyramid request.

  • result (LoginResult) – Login result from Authomatic.

Return type

InterfaceClass

Returns

User object.

import_social_media_user(user)[source]

Map Authomatic user information to a dictionary.

Parameters

user (User) – A user returned by Authomatic.

Return type

dict

Returns

Mapping from authomatic.core.User.

update_first_login_social_data(user, data)[source]

Update internal user data on every login.

Parameters
  • user (InterfaceClass) – User object.

  • data (dict) – Normalized data.

class websauna.system.user.social.GoogleMapper(registry, provider_id)[source]

Bases: websauna.system.user.social.EmailSocialLoginMapper

Map and login Google OAuth users to internal users.

See Setting up Google login.

capture_social_media_user(request, result)[source]

Extract social media information from the Authomatic login result in order to associate the user account.

Parameters
  • request (Request) – Pyramid request.

  • result (LoginResult) – Login result from Authomatic.

Return type

InterfaceClass

Returns

User object.

import_social_media_user(user)[source]

Map Authomatic user information to a dictionary.

ref: http://peterhudec.github.io/authomatic/reference/providers.html#authomatic.providers.oauth2.Google

Parameters

user (User) – A user returned by Authomatic.

Returns

Mapping from authomatic.core.User.

update_first_login_social_data(user, data)[source]

Set the initial data on the user model.

Parameters
  • user (InterfaceClass) – User object.

  • data (dict) – Normalized data.

exception websauna.system.user.social.NotSatisfiedWithData[source]

Bases: Exception

Raised when social media login cannot proceed due to incomplete provided information.

E.g. we need email to map the user, but the Facebook doesn’t give us email because user doesn’t grant the permission.

class websauna.system.user.social.TwitterMapper(registry, provider_id)[source]

Bases: websauna.system.user.social.EmailSocialLoginMapper

Map Twitter OAuth users to internal users.

See Setting up Twitter login.

capture_social_media_user(request, result)[source]

Extract social media information from the Authomatic login result in order to associate the user account.

Parameters
  • request (Request) – Pyramid request.

  • result (LoginResult) – Login result from Authomatic.

Return type

InterfaceClass

Returns

User object.

import_social_media_user(user)[source]

Map Authomatic user information to a dictionary.

Pass-through Twitter auth data to user_data[‘social’][‘twitter’]

Parameters

user (User) – A user returned by Authomatic.

Returns

Mapping from authomatic.core.User.

update_first_login_social_data(user, data)[source]

Set the initial data on the user model.

Parameters
  • user (InterfaceClass) – User object.

  • data (dict) – Normalized data.