示例#1
0
    def setUp(self):
        super().setUp()
        self.oauth = BottleOAuth2(self.app)
        self.validator = mock.MagicMock()
        self.server = Server(self.validator)
        self.oauth.initialize(self.server)

        self.fake_response = ({}, "", "200 fooOK")
示例#2
0
    def setUp(self):
        super().setUp()
        self.oauth = BottleOAuth2(self.app)
        self.validator = mock.MagicMock()
        self.server = Server(self.validator)
        self.oauth.initialize(self.server)

        self.fake_response = ({
            "Content-Type": "application/x-www-form-urlencoded"
        }, "a=b&c=d", "200 FooOK")
示例#3
0
    def setUp(self):
        super().setUp()
        self.oauth = BottleOAuth2(self.app)
        self.validator = mock.MagicMock()
        self.server = Server(self.validator)
        self.oauth.initialize(self.server)

        self.fake_response = ({
            "Content-Type": "application/json"
        }, "{'valid': true, 'foo': 'bar'}", "200 FooOK")
示例#4
0
    def setUp(self):
        super().setUp()
        self.oauth = BottleOAuth2(self.app)
        self.validator = mock.MagicMock()
        self.server = Server(self.validator)
        self.oauth.initialize(self.server)

        self.fake_request = AttrDict(client="foo",
                                     user="******",
                                     scopes=['banana', 'pinapple'])
示例#5
0
    def test_fatal_error_no_page(self):
        oauth = BottleOAuth2(self.app)
        oauth.initialize(self.server)

        @self.app.route('/fooh')
        @oauth.create_authorization_response()
        def test(): return None

        with mock.patch("oauthlib.oauth2.Server.create_authorization_response",
                        side_effect=oauthlib.oauth2.InvalidClientIdError()) as mocked:
            app_response = self.urlopen("/fooh")
            self.assertEqual(app_response['code'], 500, "error is not handled by BottleOAuth2")
            self.assertNotIn('Location', app_response['header'])
        mocked.assert_called_once()
示例#6
0
    def setUp(self):
        super().setUp()
        self.oauth = BottleOAuth2(self.app)
        self.validator = mock.MagicMock()
        self.server = LegacyApplicationServer(self.validator)
        self.metadata_endpoint = MetadataEndpoint([self.server], claims={
            "issuer": "https://xx",
            "token_endpoint": "https://xx/token",
            "revocation_endpoint": "https://xx/revoke",
            "introspection_endpoint": "https://xx/tokeninfo"
        })

        self.oauth.initialize(self.metadata_endpoint)

        self.fake_response = ({}, "", "200 fooOK")
示例#7
0
 def setUp(self):
     super().setUp()
     self.oauth = BottleOAuth2(self.app)
示例#8
0
文件: wsgi.py 项目: surags/fydp2020
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)
示例#9
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