def includeme(config): config.add_api_capability( "basicauth", description="Very basic authentication sessions. Not for production use.", url="http://kinto.readthedocs.io/en/stable/api/1.x/authentication.html", ) OpenAPI.expose_authentication_method("basicauth", {"type": "basic"})
def includeme(config): config.add_api_capability( 'basicauth', description='Very basic authentication sessions. Not for production use.', url='http://kinto.readthedocs.io/en/stable/api/1.x/authentication.html', ) OpenAPI.expose_authentication_method('basicauth', {'type': 'basic'})
def includeme(config): config.add_api_capability( "basicauth", description="Very basic authentication sessions. Not for production use.", url="http://kinto.readthedocs.io/en/stable/api/1.x/authentication.html", ) OpenAPI.expose_authentication_method("basicauth", {"type": "basic"})
def includeme(config): config.add_api_capability( 'basicauth', description= 'Very basic authentication sessions. Not for production use.', url='http://kinto.readthedocs.io/en/stable/api/1.x/authentication.html', ) OpenAPI.expose_authentication_method('basicauth', {'type': 'basic'})
class OpenAPITest(BaseWebTest, unittest.TestCase): def setUp(self): super(OpenAPITest, self).setUp() self.request = mock.MagicMock() self.request.registry.settings = self.get_app_settings() self.generator = OpenAPI(get_services(), self.request) self.api_doc = self.generator.generate() def test_assign_base_path(self): self.assertEqual(self.api_doc["basePath"], "/{}".format(self.api_prefix)) def test_default_security_generator(self): self.assertEqual(self.api_doc["paths"]["/"]["get"]["security"], []) self.assertEqual( self.api_doc["paths"]["/mushrooms"]["get"]["security"], [{ "basicauth": [] }]) def test_security_extensions(self): method = { "type": "oauth2", "authorizationUrl": "https://oauth-stable.dev.lcip.org/v1", "flow": "implicit", "scopes": { "kinto": "Kinto user scope." }, } self.generator.expose_authentication_method("fxa", method) api_doc = self.generator.generate() self.assertEqual(api_doc["securityDefinitions"]["fxa"], method) self.assertCountEqual( api_doc["paths"]["/mushrooms"]["get"]["security"], [{ "basicauth": [] }, { "fxa": ["kinto"] }], ) def test_default_tags(self): self.assertEqual(self.api_doc["paths"]["/mushrooms"]["get"]["tags"], ["Mushrooms"]) self.assertEqual( self.api_doc["paths"]["/mushrooms/{id}"]["get"]["tags"], ["Mushrooms"]) def test_default_operation_ids(self): self.assertEqual( self.api_doc["paths"]["/mushrooms"]["get"]["operationId"], "get_mushrooms") self.assertEqual( self.api_doc["paths"]["/mushrooms/{id}"]["get"]["operationId"], "get_mushroom")
class OpenAPITest(BaseWebTest, unittest.TestCase): def setUp(self): super(OpenAPITest, self).setUp() self.request = mock.MagicMock() self.request.registry.settings = self.get_app_settings() self.generator = OpenAPI(get_services(), self.request) self.api_doc = self.generator.generate() def test_assign_base_path(self): self.assertEquals(self.api_doc['basePath'], "/{}".format(self.api_prefix)) def test_default_security_generator(self): self.assertEquals(self.api_doc['paths']['/']['get']['security'], []) self.assertEquals( self.api_doc['paths']['/mushrooms']['get']['security'], [{ 'basicauth': [] }]) def test_security_extensions(self): method = { "type": "oauth2", "authorizationUrl": "https://oauth-stable.dev.lcip.org/v1", "flow": "implicit", "scopes": { "kinto": "Kinto user scope." } } self.generator.expose_authentication_method("fxa", method) api_doc = self.generator.generate() self.assertEquals(api_doc['securityDefinitions']['fxa'], method) self.assertCountEqual( api_doc['paths']['/mushrooms']['get']['security'], [{ 'basicauth': [] }, { 'fxa': ['kinto'] }]) def test_default_tags(self): self.assertEquals(self.api_doc['paths']['/mushrooms']['get']['tags'], ['Mushrooms']) self.assertEquals( self.api_doc['paths']['/mushrooms/{id}']['get']['tags'], ['Mushrooms']) def test_default_operation_ids(self): self.assertEquals( self.api_doc['paths']['/mushrooms']['get']['operationId'], 'get_mushrooms') self.assertEquals( self.api_doc['paths']['/mushrooms/{id}']['get']['operationId'], 'get_mushroom')
def includeme(config): # Activate end-points. config.scan("kinto.plugins.openid.views") settings = config.get_settings() openid_policies = [] for policy in aslist(settings["multiauth.policies"]): v = settings.get("multiauth.policy.%s.use" % policy, "") if v.endswith("OpenIDConnectPolicy"): openid_policies.append(policy) if len(openid_policies) == 0: # Do not add the capability if no policy is configured. return providers_infos = [] for name in openid_policies: issuer = settings["multiauth.policy.%s.issuer" % name] openid_config = fetch_openid_config(issuer) client_id = settings["multiauth.policy.%s.client_id" % name] header_type = settings.get("multiauth.policy.%s.header_type", "Bearer") providers_infos.append({ "name": name, "issuer": openid_config["issuer"], "auth_path": "/openid/%s/login" % name, "client_id": client_id, "header_type": header_type, "userinfo_endpoint": openid_config["userinfo_endpoint"], }) OpenAPI.expose_authentication_method( name, { "type": "oauth2", "authorizationUrl": openid_config["authorization_endpoint"] }) config.add_api_capability( "openid", description="OpenID connect support.", url="http://kinto.readthedocs.io/en/stable/api/1.x/authentication.html", providers=providers_infos, ) config.add_request_method(get_user_profile, name="get_user_profile")
def includeme(config): # Activate end-points. config.scan('kinto.plugins.openid.views') settings = config.get_settings() openid_policies = [] for k, v in settings.items(): m = re.match('multiauth\.policy\.(.*)\.use', k) if m: print(k, v) if v.endswith('OpenIDConnectPolicy'): openid_policies.append(m.group(1)) if len(openid_policies) == 0: # Do not add the capability if no policy is configured. return providers_infos = [] for name in openid_policies: issuer = settings['multiauth.policy.%s.issuer' % name] openid_config = fetch_openid_config(issuer) client_id = settings['multiauth.policy.%s.client_id' % name] header_type = settings.get('multiauth.policy.%s.header_type', 'Bearer') providers_infos.append({ 'name': name, 'issuer': openid_config['issuer'], 'auth_path': '/openid/%s/login' % name, 'client_id': client_id, 'header_type': header_type, 'userinfo_endpoint': openid_config['userinfo_endpoint'], }) OpenAPI.expose_authentication_method( name, { 'type': 'oauth2', 'authorizationUrl': openid_config['authorization_endpoint'], }) config.add_api_capability( 'openid', description='OpenID connect support.', url='http://kinto.readthedocs.io/en/stable/api/1.x/authentication.html', providers=providers_infos)
def openapi_view(request): # Only build json once try: return openapi_view.__json__ except AttributeError: openapi_view.__json__ = OpenAPI(get_services(), request).generate() return openapi_view.__json__
def includeme(config): # Activate end-points. config.scan("kinto.plugins.openid.views") settings = config.get_settings() openid_policies = [] for policy in aslist(settings["multiauth.policies"]): v = settings.get("multiauth.policy.%s.use" % policy, "") if v.endswith("OpenIDConnectPolicy"): openid_policies.append(policy) if len(openid_policies) == 0: # Do not add the capability if no policy is configured. return providers_infos = [] for name in openid_policies: issuer = settings["multiauth.policy.%s.issuer" % name] openid_config = fetch_openid_config(issuer) client_id = settings["multiauth.policy.%s.client_id" % name] header_type = settings.get("multiauth.policy.%s.header_type", "Bearer") providers_infos.append( { "name": name, "issuer": openid_config["issuer"], "auth_path": "/openid/%s/login" % name, "client_id": client_id, "header_type": header_type, "userinfo_endpoint": openid_config["userinfo_endpoint"], } ) OpenAPI.expose_authentication_method( name, {"type": "oauth2", "authorizationUrl": openid_config["authorization_endpoint"]} ) config.add_api_capability( "openid", description="OpenID connect support.", url="http://kinto.readthedocs.io/en/stable/api/1.x/authentication.html", providers=providers_infos, )
class OpenAPITest(BaseWebTest, unittest.TestCase): def setUp(self): super(OpenAPITest, self).setUp() self.request = mock.MagicMock() self.request.registry.settings = self.get_app_settings() self.generator = OpenAPI(get_services(), self.request) self.api_doc = self.generator.generate() def test_assign_base_path(self): self.assertEqual(self.api_doc["basePath"], "/{}".format(self.api_prefix)) def test_default_security_generator(self): self.assertEqual(self.api_doc["paths"]["/"]["get"]["security"], []) self.assertEqual( self.api_doc["paths"]["/mushrooms"]["get"]["security"], [{"basicauth": []}] ) def test_security_extensions(self): method = { "type": "oauth2", "authorizationUrl": "https://oauth-stable.dev.lcip.org/v1", "flow": "implicit", "scopes": {"kinto": "Kinto user scope."}, } self.generator.expose_authentication_method("fxa", method) api_doc = self.generator.generate() self.assertEqual(api_doc["securityDefinitions"]["fxa"], method) self.assertCountEqual( api_doc["paths"]["/mushrooms"]["get"]["security"], [{"basicauth": []}, {"fxa": ["kinto"]}], ) def test_default_tags(self): self.assertEqual(self.api_doc["paths"]["/mushrooms"]["get"]["tags"], ["Mushrooms"]) self.assertEqual(self.api_doc["paths"]["/mushrooms/{id}"]["get"]["tags"], ["Mushrooms"]) def test_default_operation_ids(self): self.assertEqual( self.api_doc["paths"]["/mushrooms"]["get"]["operationId"], "get_mushrooms" ) self.assertEqual( self.api_doc["paths"]["/mushrooms/{id}"]["get"]["operationId"], "get_mushroom" )
def includeme(config): # Activate end-points. config.scan('kinto.plugins.openid.views') settings = config.get_settings() openid_policies = [] for k, v in settings.items(): m = re.match('multiauth\.policy\.(.*)\.use', k) if m: if v.endswith('OpenIDConnectPolicy'): openid_policies.append(m.group(1)) if len(openid_policies) == 0: # Do not add the capability if no policy is configured. return providers_infos = [] for name in openid_policies: issuer = settings['multiauth.policy.%s.issuer' % name] openid_config = fetch_openid_config(issuer) client_id = settings['multiauth.policy.%s.client_id' % name] header_type = settings.get('multiauth.policy.%s.header_type', 'Bearer') providers_infos.append({ 'name': name, 'issuer': openid_config['issuer'], 'auth_path': '/openid/%s/login' % name, 'client_id': client_id, 'header_type': header_type, 'userinfo_endpoint': openid_config['userinfo_endpoint'], }) OpenAPI.expose_authentication_method(name, { 'type': 'oauth2', 'authorizationUrl': openid_config['authorization_endpoint'], }) config.add_api_capability( 'openid', description='OpenID connect support.', url='http://kinto.readthedocs.io/en/stable/api/1.x/authentication.html', providers=providers_infos)
def setUp(self): super(OpenAPITest, self).setUp() self.request = mock.MagicMock() self.request.registry.settings = self.get_app_settings() self.generator = OpenAPI(get_services(), self.request) self.api_doc = self.generator.generate()
def setUp(self): super(OpenAPITest, self).setUp() self.request = mock.MagicMock() self.request.registry.settings = self.get_app_settings() self.generator = OpenAPI(get_services(), self.request) self.api_doc = self.generator.generate()