Welcome to Pacifica Authentication’s documentation!

The Pacifica Authentication library provides Pacifica Core services a consistent authentication configuration and APIs.

Installation

The Pacifica software is available through PyPi so creating a virtual environment to install is what is shown below. Please keep in mind compatibility with the Pacifica Core services.

Installation in Virtual Environment

These installation instructions are intended to work on both Windows, Linux, and Mac platforms. Please keep that in mind when following the instructions.

Please install the appropriate tested version of Python for maximum chance of success.

Linux and Mac Installation

mkdir ~/.virtualenvs
python -m virtualenv ~/.virtualenvs/pacifica
. ~/.virtualenvs/pacifica/bin/activate
pip install pacifica-auth

Windows Installation

This is done using PowerShell. Please do not use Batch Command.

mkdir "$Env:LOCALAPPDATA\virtualenvs"
python.exe -m virtualenv "$Env:LOCALAPPDATA\virtualenvs\pacifica"
& "$Env:LOCALAPPDATA\virtualenvs\pacifica\Scripts\activate.ps1"
pip install pacifica-auth

Configuration

The configuration of Pacifica Authentication is done on the command line using arguments passed to services that incorporate the library.

Authentication Options

These are common command line switches when Pacifica services include the authentication library.

Session Directory --session-dir

Default is sessions and contains the user sessions managed by the core service.

Database URL --db-url

Default is sqlite:///database.sqlite3 and is the SQLAlchemy engine connection url

Social Auth Module --social-module

Python Social Auth backends Python module name. The module name is relative to social_core.backends.

Social Auth Class --social-class

Python Social Auth class name from the module in the --social-module name.

Social Auth Settings --social-setting

Python Social Auth settings are passed as to CherryPy configrations. Examples are the following:

pacifica-service \
  --social-setting=github_key=<GitHub OAuth Key> \
  --social-setting=github_secret=<GitHub OAuth Secret>

Application Directory --app-dir

This is optional as some Pacifica services don’t serve applications to users. This can serve both ReactJS or Swagger-UI as example applications.

Example Usage

Need to have good example application.

Authentication Python Module

Application Python Module

Base application module.

pacifica.auth.application.check_sa_module_class(args)[source]

Check the combination of module and class.

pacifica.auth.application.check_sa_settings(obj_str)[source]

Verify social auth settings.

pacifica.auth.application.error_page_default(**kwargs)[source]

Error page when something goes wrong.

pacifica.auth.application.pacifica_auth_arguments(parser)[source]

Add Pacifica authentication command line arguments.

pacifica.auth.application.session_commit()[source]

Commit the user session to the database.

pacifica.auth.application.social_settings(args, user_class, user_import_path)[source]

Setup the social settings for pacifica auth.

Root CherryPy Python Module

Root class to handle social auth.

class pacifica.auth.root.Root(sa_module, app_dir)[source]

Root class to integrate social auth.

__init__(sa_module, app_dir)[source]

Save the sa module and app directory.

app(*args)[source]

Serve the app or redirect to login.

done()[source]

Done with the social auth login.

index()[source]

If the user isn’t there redirect to login.

logout()[source]

Logout the user deleting the session.

SAPlugin Python Module

CherryPy plugin to manage SQLAlchemy session connection.

class pacifica.auth.saplugin.SAEnginePlugin(bus, connection_string=None)[source]

CherryPy SQLAlchemy Plugin.

__init__(bus, connection_string=None)[source]

Create the plugin saving engine connection and session.

bind()[source]

Bind the session to the engine.

commit()[source]

Commit the session to the database or rollback.

start()[source]

Start the engine connection and subscribe bind and commit.

stop()[source]

Unsubscribe bind and commit and dispose of engine.

SATool Python Module

CherryPy Social Auth Tools to setup database connections.

class pacifica.auth.satool.SATool[source]

CherryPy tool to manage handler.

__init__()[source]

Create the SATool and set bind priority.

_setup()[source]

Setup and attach the hooks.

bind_session()[source]

Bind the db session to something we can use.

commit_transaction()[source]

Delete the db session and publish commit.

SQLAlchemy User Model Python Module

Example user model for consumers to use.

class pacifica.auth.user_model.Base(**kwargs)

The most base type

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

_decl_class_registry = <WeakValueDictionary>
metadata = MetaData(bind=None)
class pacifica.auth.user_model.User(**kwargs)[source]

Example SQLAlchemy User Model.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

_sa_class_manager = {'active': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'email': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'password': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'username': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'uuid': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}
active
email
id
is_active()[source]

Return the user active attribute.

is_authenticated()[source]

The user is always authenticated.

name
password
username
uuid

Pacifica Authentication Module.

pacifica.auth.auth_session(func)[source]

Authenticate the method.

pacifica.auth.pacifica_auth_arguments(parser)[source]

Add Pacifica authentication command line arguments.

pacifica.auth.error_page_default(**kwargs)[source]

Error page when something goes wrong.

pacifica.auth.social_settings(args, user_class, user_import_path)[source]

Setup the social settings for pacifica auth.

Indices and tables