Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bottle support? #141

Open
rcarmo opened this issue Mar 5, 2016 · 6 comments
Open

Bottle support? #141

rcarmo opened this issue Mar 5, 2016 · 6 comments

Comments

@rcarmo
Copy link

rcarmo commented Mar 5, 2016

Hi there,

I'm trying to get this to work with Bottle, but would like to know if there are plans for supporting it officially.

Cheers!

@rcarmo
Copy link
Author

rcarmo commented Mar 5, 2016

Just for the record, this is mostly working for me right now (and I say mostly solely because I'm not too happy with the decorator - the adapter itself seems to be finished):

from authomatic.adapters import BaseAdapter
from authomatic import Authomatic
from functools import wraps
from config import OAUTH2_CONFIG, OAUTH2_SIGNATURE
from bottle import request, response, redirect
from urlparse import urlunparse

authomatic = Authomatic(OAUTH2_CONFIG, OAUTH2_SIGNATURE)

def login(provider_name):
    def decorator(func):
        def wrapper(*args, **kwargs):
            # we're using beaker sessions here
            if 'user' not in request.session:
                result = authomatic.login(BottleAdapter(request, response), provider_name)
                if result:
                    if result.user:
                        result.user.update()
                        request.session['user'] = result.user.email
                        request.session.save()
            return func(*args, **kwargs)        
        return wrapper
    return decorator


class BottleAdapter(BaseAdapter):
    """Adapter for the |bottle|_ framework."""

    def __init__(self, request, response):
        """
        :param request:
            A |bottle|_ :class:`Request` instance.

        :param response:
            A |bottle|_ :class:`Response` instance.
        """
        self.request = request
        self.response = response


    #===========================================================================
    # Request
    #===========================================================================

    @property
    def url(self):
        return urlunparse(self.request.urlparts[0:3] + (None, None, None))


    @property
    def params(self):
        return dict(self.request.params)


    @property
    def cookies(self):
        return dict(self.request.cookies)


    #===========================================================================
    # Response
    #===========================================================================

    def write(self, value):
        self.response.write(value)


    def set_header(self, key, value):
        self.response.headers[key] = str(value)


    def set_status(self, status):
        self.response.status = status

@mrichar1
Copy link
Member

After several years of inactivity, authomatic is now under community management, and we have just released a new stable version (1.0.0).

We are now reviewing all issues and PRs and hoping to begin work to solve as many of these as possible.

We are keen to find out which issues still apply, and which PRs are still required/are likely to merge cleanly into the current code. We are aiming to review them all, but any help with prioritisation would be very useful!

If you are still interested in having this issue/PR resolved, or are able to help us work on it, please reply to this message. That way we know which issues are most important to the community.

@rcarmo
Copy link
Author

rcarmo commented Nov 28, 2019

I'd love to see this folded into core, since I use either Sanic or Bottle as the core of most of my Python web apps and authomatic would be a terrific fit.

@mrichar1 mrichar1 added this to Todo: High Priority in Issue-Management Nov 28, 2019
@jensens
Copy link
Member

jensens commented Nov 28, 2019

@rcarmo Are you able to provide a pull request and check then if it works? We are a volunteer driven project. If merged we can release a 1.1.0 with the new feature soon.

@rcarmo
Copy link
Author

rcarmo commented Nov 28, 2019 via email

@mrichar1
Copy link
Member

Hi - thanks for getting back in touch!

I'll explain a bit about how the testing currently works, since it's pretty complicated (and a bit fragile), and you can decide whether to run screaming or not :)

Each framework (Django, Flask etc) has a test app contained in examples/ that has a route / that returns the data rendered by tests.functional_tests.fixtures.render_home(framework_name) - how this is done is obviously framework-specific.

Frameworks are controlled via the liveandletdie module (also an authomatic org project). This provides a standard API around all the frameworks to start, restart, stop etc them.

The list of frameworks to run is held in tests/functional_tests/config.py (which is encrypted as it contains auth secrets - but the 'public' parts are mirrored in config-template.py).

For each listed framework, the test suite starts it (via liveandletdie), and then tests each of the various auth providers (twitter, facebook etc) against it.

So the steps to developing tests for a new framework are:

  1. Write an example app that serves up the data from fixtures.render_home
  2. Extend liveandletdie to control the framework.
  3. Add the framework to the list to be tested in config.py.

Step 1 should be relatively easy if you are already familiar with bottle, with the other examples for reference.

Step 2 we can help with - I've done some work on liveandletdie so have an idea about how this would work.

Step 3 is easy - and only applies once the code is close to merging (since we need a branch on authomatic for the config to be decrypted).

@jensens jensens moved this from Todo: High Priority to Todo: Low Priority in Issue-Management Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Issue-Management
  
Todo: Low Priority
Development

No branches or pull requests

3 participants