当前位置: 首页>>代码示例>>Python>>正文


Python IdentityManagementServiceClient.create_authentication_token方法代码示例

本文整理汇总了Python中interface.services.coi.iidentity_management_service.IdentityManagementServiceClient.create_authentication_token方法的典型用法代码示例。如果您正苦于以下问题:Python IdentityManagementServiceClient.create_authentication_token方法的具体用法?Python IdentityManagementServiceClient.create_authentication_token怎么用?Python IdentityManagementServiceClient.create_authentication_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在interface.services.coi.iidentity_management_service.IdentityManagementServiceClient的用法示例。


在下文中一共展示了IdentityManagementServiceClient.create_authentication_token方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_non_anonymous_resource_registry_operations_with_token

# 需要导入模块: from interface.services.coi.iidentity_management_service import IdentityManagementServiceClient [as 别名]
# 或者: from interface.services.coi.iidentity_management_service.IdentityManagementServiceClient import create_authentication_token [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(len(response_data), 2)
        self.assertGreaterEqual(len(response_data[0]), 20)  # This is a resource_id
        inst_id = str(response_data[0])

        inst_obj = rr.read(inst_id)
        self.assertEquals(inst_obj.type_, RT.InstrumentDevice)
        self.assertEquals(inst_obj.name, "Instrument1")
        self.assertEquals(inst_obj.visibility, ResourceVisibilityEnum.OWNER)

        act_objs, assocs = rr.find_objects(inst_id, PRED.hasOwner, RT.ActorIdentity, id_only=False)
        self.assertEquals(len(act_objs), 1)
        self.assertEquals(act_objs[0]._id, actor_id)

        # Anonymous query should not show the resource anymore
        response = self.test_app.get("/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True")
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 0)

        # Authenticated request with owner shows resource
        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&requester=" + actor_id
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 1)
        self.assertEqual(len(response_data[1]), 1)
        self.assertEqual(response_data[0][0], inst_id)

        token_str = id_client.create_authentication_token(actor_id, validity=2)

        # Request with authentication token for owner shows resource
        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&authtoken=" + token_str
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 1)
        self.assertEqual(len(response_data[1]), 1)
        self.assertEqual(response_data[0][0], inst_id)

        gevent.sleep(2.1)

        # Request with expired authentication token for owner does not show resource (no error though)
        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&authtoken=" + token_str
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 0)

        # Request with valid authentication token for different user does not show resource
        actor_id2, _ = rr.create(IonObject(RT.ActorIdentity, name="Actor2"))
        token_str2 = id_client.create_authentication_token(actor_id2, validity=2)

        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&authtoken=" + token_str2
        )
开发者ID:edwardhunter2,项目名称:coi-services,代码行数:70,代码来源:test_service_gateway_service.py

示例2: TestIdentityManagementServiceInt

# 需要导入模块: from interface.services.coi.iidentity_management_service import IdentityManagementServiceClient [as 别名]
# 或者: from interface.services.coi.iidentity_management_service.IdentityManagementServiceClient import create_authentication_token [as 别名]

#.........这里部分代码省略.........
        # Try merging the account again
        with self.assertRaises(BadRequest):
            self.identity_management_service.complete_account_merge(token, headers={'ion-actor-id':id})

        # Signon again and verify the two accounts have been merged
        id, valid_until, registered = self.identity_management_service.signon(certificate, True)
        self.assertTrue(registered)
        id_2, valid_until_2, registered_2 = self.identity_management_service.signon(certificate_2, True)
        self.assertTrue(registered_2)

        # Validate the two accounts are the same
        self.assertEqual(id, id_2, "The two accounts should have the same id")

        # Try to merge to your own account
        with self.assertRaises(BadRequest):
            token = self.identity_management_service.initiate_account_merge("[email protected]",  headers={'ion-actor-id':id})

        #  Done testing. Delete user
        self.identity_management_service.delete_user_info(user_info_id)
        self.identity_management_service.unregister_user_credentials(id, subject)
        self.identity_management_service.delete_actor_identity(id)

    def test_auth_tokens(self):
        # Note: test of service gateway token functionality is in SGS test

        rr = self.resource_registry

        actor_identity_obj = IonObject("ActorIdentity", {"name": self.subject})
        actor_id = self.identity_management_service.create_actor_identity(actor_identity_obj)

        user_info_obj = IonObject("UserInfo", {"name": "Foo"})
        user_info_id = self.identity_management_service.create_user_info(actor_id, user_info_obj)

        token_str = self.identity_management_service.create_authentication_token(actor_id, validity=10000)
        self.assertIsInstance(token_str, str)
        self.assertGreaterEqual(len(token_str), 25)

        token_info = self.identity_management_service.check_authentication_token(token_str)
        self.assertEquals(token_info["actor_id"], actor_id)

        token_info = self.identity_management_service.check_authentication_token(token_str)
        self.assertGreaterEqual(int(token_info["expiry"]), get_ion_ts_millis())

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id="", validity=10000)

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(user_info_id, validity=10000)

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id, validity="FOO")

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id, validity=-200)

        cur_time = get_ion_ts_millis()

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id, start_time=str(cur_time-100000), validity=50)

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id, validity=35000000)

        with self.assertRaises(NotFound):
            self.identity_management_service.check_authentication_token("UNKNOWN")
开发者ID:ednad,项目名称:coi-services,代码行数:69,代码来源:test_identity_management_service.py


注:本文中的interface.services.coi.iidentity_management_service.IdentityManagementServiceClient.create_authentication_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。