def get_oauth2_server(self, validator=None, **kwargs):
        """ Returns an OAuth2 server instance, depending on the client application type

        Generates an OdooValidator instance if no custom validator is defined
        All other arguments are directly passed to the server constructor (for
        example, a token generator function)
        """
        self.ensure_one()

        if validator is None:
            validator = OdooValidator()

        if self.application_type == 'web application':
            return oauth2.WebApplicationServer(validator, **kwargs)
        elif self.application_type == 'mobile application':
            return oauth2.MobileApplicationServer(validator, **kwargs)
        elif self.application_type == 'legacy application':
            return oauth2.LegacyApplicationServer(validator, **kwargs)
        elif self.application_type == 'backend application':
            return oauth2.BackendApplicationServer(validator, **kwargs)
Exemplo n.º 2
0
import bottle
from bottle_oauthlib.oauth2 import BottleOAuth2
from oauthlib import oauth2
# Do not remove this important statement! Otherwise routes cannot be found
from src import routes

from src.helper import database_intializer_helper
from src.authentication.oauth2_password_validator import OAuth2_PasswordValidator
from src.helper.database_data_initializer import DatabaseDataInitializer

app = application = bottle.default_app()
db_init = database_intializer_helper.DatabaseInitializer()
db_data_init = DatabaseDataInitializer()

validator = OAuth2_PasswordValidator()
app.auth = BottleOAuth2(app)
app.auth.initialize(oauth2.LegacyApplicationServer(OAuth2_PasswordValidator()))


if __name__ == '__main__':
    bottle.run(host='127.0.0.1', port=8000, server=bottle.GeventServer)
Exemplo n.º 3
0
import bottle
from bottle_oauthlib.oauth2 import BottleOAuth2
from oauthlib import oauth2

app = bottle.Bottle()
app.auth = BottleOAuth2(app)
app.authmetadata = BottleOAuth2(app)

oauthlib_server = oauth2.LegacyApplicationServer(oauth2.RequestValidator())
app.authmetadata.initialize(
    oauth2.MetadataEndpoint(
        [oauthlib_server],
        claims={
            "issuer": "https://xx",
            "token_endpoint": "https://xx/token",
            "revocation_endpoint": "https://xx/revoke",
            "introspection_endpoint": "https://xx/tokeninfo"
        }))


@app.get('/.well-known/oauth-authorization-server')
@app.authmetadata.create_metadata_response()
def metadata():
    pass


if __name__ == "__main__":
    app.run()  # pragma: no cover