websauna.system.user.oauthloginservice module

Default implementation of social login handling.

class websauna.system.user.oauthloginservice.AuthomaticLoginHandler(request, provider_name)[source]

Bases: object

Social login (OAuth/authomatic) internal handling.

Subclass and override this for customizations.

Internal implementation of handling OAuth endpoint. The request must be processed as view /login/{provider_name} where provider_name is one of the Authomatic providers set up by Initializer.configure_authomatic(). This view will

  • Check if the request is internal login request and then redirect to OAuth provider

  • Process POST/redirect back from the OAuth Provider

  • Call ISocialAuthMapper to create the user account for incoming social login

The function returns a tuple. If login success, HTTP response is set. If login fails automatic result is set. If the automatic result is set you are expected to render a login page with error message on it.

return

Tuple (HTTP response, Authomatic result)

do_bad_request()[source]

Handle getting HTTP GET to POST endpoint.

GoogleBot et. al.

do_error(authomatic_result, e)[source]

Handle getting error from OAuth provider.

Return type

Response

do_success(authomatic_result)[source]

Handle we got a valid OAuth login data.

Try and log in the user.

Return type

Response

handle()[source]
Return type

Response

process_form()[source]

Process form values from the internal post request.

By default this doesn nothing. If your site wants to combine e.g. login + choose product action to single POST you can do it here.

Example:

class TreesAuthomaticLoginHandler(AuthomaticLoginHandler):

    def process_form(self):
        request = self.request
        product_id = request.POST.get("product_id")
        if product_id:
            request.session["delivery_data"] = {
                "product": product_id,
                "delivery_details": {},
                "started": now().isoformat()
            }
            request.session.changed()
class websauna.system.user.oauthloginservice.DefaultOAuthLoginService(request)[source]

Bases: object

handle_request(provider_name)[source]

Handle all requests coming to login/facebook, login/twitter etc. endpoints.

  • Login form does an empty HTTP POST request to initiate OAuth process

  • Federated authentication service does HTTP GET redirect when they accept OAuth authentication request

Return type

Response