简体   繁体   English

在Apigee中,如何通过策略访问组织的开发者帐户?

[英]In Apigee, how can developer accounts for an organization be accessed through a policy?

In this use case, in an API Proxy, a custom attribute for each developer in an organization has to be accessed. 在此用例中,在API代理中,必须访问组织中每个开发人员的自定义属性。

I am aware of the call ' https://api.enterprise.apigee.com/v1/o/org_name/developers ' which will give a list of emails (usernames) of all developers and then I can use ' https://api.enterprise.apigee.com/v1/o/org_name/developers/dev1_email@abc.com ' to get a particular developer account. 我知道调用' https://api.enterprise.apigee.com/v1/o/org_name/developers ',它会给出所有开发人员的电子邮件(用户名)列表,然后我可以使用' https:// api.enterprise.apigee.com/v1/o/org_name/developers/dev1_email@abc.com '获取特定的开发者帐户。

I tried using the Service Callout policy to get a list of all developers, returning developer emails: 我尝试使用Service Callout策略获取所有开发人员的列表,返回开发人员电子邮件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="get-developer-list">
    <DisplayName>Get Developer List</DisplayName>
    <Request learPayload="true" variable="DeveloperListRequest"/>
    <Response>DeveloperList</Response>
    <HTTPTargetConnection>
        <URL>https://api.enterprise.apigee.com/v1/o/myOrg/developers</URL>
    </HTTPTargetConnection>
</ServiceCallout>

However, this requires a username and password which can be set by an Assign Message policy. 但是,这需要用户名和密码,可以通过“分配消息”策略进行设置。 How can this be achieved? 怎么能实现这一目标? Is this the right approach overall or is there any other way? 这是正确的方法还是有其他方法吗?

You should avoid calling out to the management server in most cases. 在大多数情况下,您应该避免呼叫管理服务器。 The management server endpoint is not built for the same amount of traffic that you can handle in your APIs, and you can cause it to stop responding if you overload it. 管理服务器端点不是为您可以在API中处理的相同数量的流量构建的,并且如果您使其超载,则可以使其停止响应。

To access a developer's information, you can use the AccessEntity policy: 要访问开发人员的信息,您可以使用AccessEntity策略:

<AccessEntity name="GetDeveloperInfo">
    <EntityType value="developer"/>
    <EntityIdentifier ref="variableHoldingIdentifier" type="developeremail"/>
</AccessEntity>

You specify the variable that holds the id of the developer you want to access in the EntityIdentifier ref attribute. 您可以在EntityIdentifier ref属性中指定包含要访问的开发人员ID的变量。 The EntityIdentifier type attribute holds the type of data you are using to access the entity. EntityIdentifier类型属性包含用于访问实体的数据类型。 For developers, you can access via email, developer ID, appID, or consumerKey. 对于开发人员,您可以通过电子邮件,开发人员ID,appID或consumerKey进行访问。 See the AccessEntity docs for more details. 有关更多详细信息,请参阅AccessEntity文档

If you need to start with a list of all developers, you can't do that via a standard policy, and you'd have to call out to the management API for the list, but you should still use the AccessEntity policy to retrieve the developer's data. 如果您需要从所有开发人员的列表开始,您不能通过标准策略执行此操作,并且您必须调用管理API以获取列表,但您仍应使用AccessEntity策略来检索开发人员的数据。

If you worry at all about security, I would recommend that you create a user specifically to do your callout with a complex password. 如果您担心安全问题,我建议您专门创建一个用户使用复杂密码进行标注。 Create a custom role that only allows GET access to read the developer list, and assign that user that role only. 创建仅允许GET访问的自定义角色以读取开发人员列表,并仅为该用户分配该角色。 Putting the password in the API directly means that if you download the bundle/archive the source code somewhere, the username/password can be compromised. 将密码直接放入API意味着如果您在某处下载/归档源代码,则可能会损害用户名/密码。 You could store an encrypted version of the password in a key/value map, and retrieve it from there and decrypt it in the API, so that someone would have to get both your bundle and access to your key/value map data to get any access. 您可以将密码的加密版本存储在键/值映射中,并从那里检索它并在API中解密,这样某人就必须同时获取您的包和访问您的键/值映射数据以获取任何密码/值映射数据访问。 In any case, if you've properly locked down the access for that user, someone who gained access to the user credentials could only get the developer list, and nothing else. 在任何情况下,如果您已正确锁定该用户的访问权限,则获得用户凭据访问权限的人只能获取开发人员列表,而不能获取任何其他内容。

To avoid calling out too often (and swamping your management API endpoint), you could cache the response from the management API for a certain period (a minute or more). 为了避免过于频繁地调用(以及淹没管理API端点),您可以将管理API的响应缓存一段时间(一分钟或更长时间)。 That would avoid the problem of heavy traffic hitting the management API. 这样可以避免流量大的问题导致管理API出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM