You may require setting permissions on the data field level, especially when working with third-party vendors who should only have access to specific fields in the accounts database. In this case, you can use an API manager to create an API proxy and define its logic. Apigee is one example of an API proxy platform which can give you this capability.
Below is a code example and guidelines for using an Apigee API proxy to allow data-level permissions for the following Gigya APIs:
Data Flow Overview
We have configured a live example which demonstrates calling accounts.search with the following query:
In the first example, we configured the call without filters, as you usually would using Gigya.
In the second example, the call is passed via an API proxy created in Apigee and includes only profile.firstName , profile.email , profile.lastName , isActive and UID so that any other field is filtered out.
Check it out:
This is the configuration in the Node.js file for the filtered search:
This guide assumes that you have already created an application key and secret in the Gigya Console. If you have not, see the appendix for instructions.
Most API managers, including Apigee, offer powerful authorization capabilities, for example using OAuth 2.0. We recommend implementing authorization with your API proxy for security reasons.
1. Download Files
Download and unzip the following folder: Apigee files.
2. Create an Apigee API Proxy
- Go to https://login.apigee.com/login.
- If you do not yet have an account, click Create account and complete the registration process. Otherwise, login.
- In the screen that opens, activate the API Management option. Complete the activation process via the confirmation email.
- Go to https://enterprise.apigee.com/
- Under APIs, select API Proxies:
- Click +API Proxy:
- In the Build a Proxy menu, select the Node.js App option and click Next.
- In the Details section, enter the Proxy Name, such as getAccountInfo.
- Under Source, select Existing.
- Click Choose Files to upload the sample node.js files into the new API proxy.
- Upload a pair of the files provided in the first step: for each API proxy, a script file and a configuration file. The script files are named after the relevant Gigya APIs, and the configuration files are named "config*". The Apigee Node sample folder is organized in sub-folders by the Gigya APIs.
- Enter a description and click Next.
- In the Security section, select Pass through (none) and click Next. Other options may be available, depending on your Apigee account tier.
- Under Virtual Hosts, select secure and click Next.
- Select whether to build a prod or test environment or both, and click Build and Deploy.
- Click View <Your API Name> proxy in the editor.
3. Configure the API Proxy
For each of the API proxies:
- Go to the Developer tab.
- On the left hand side, under Target Endpoints, select the PostFlow file.
In the code editor, locate the <ResourceURL> tag at the bottom, nested under the <ScriptTarget> tag. Make sure the node references the script file and not the configuration file. For example, if you are configuring the accounts.getAccountInfo API, make sure the following appears:
- Under Scripts. open the configuration file and enter the following configurations:
- exports.applicationKey: Your site's API key. You can copy the API key from the home page of the Gigya Console.
- exports.applicationSecret: The Gigya application secret.
- exports.userKey: The user key associated with the application.
- exports.includedFields: An array of the fields to which this application has access permissions using the Gigya API call.
- exports.excludedFields: An array of fields for which this application is denied access.
Appendix: Creating a Gigya Application
Application and User Keys
Using the Gigya API with a User Key
If you are not the main site administrator, you may not have access to the Partner Secret Key. Instead, you can call the GIgya API using your user key and user secret. You still need to pass the API Key of the target site. Note that calls performed this way are subject to the user key's permissions and are logged for auditing purposes.
When you pass a request across HTTPS, include the site's API Key and your personal User Key and Secret. For example:
For more information about user keys, including instructions for finding your user key in the Gigya Console, see Using the User Key.
Creating A User Key
You can make REST Requests using a userKey and secret. This is useful for delegating access to Gigya APIs without revealing your account's secret to multiple users. You can create multiple Applications, and give groups of users access to these various applications with each application having only the permissions that you define in it's settings. Each application has a userKey and secret that can be used when making REST calls to Gigya API Endpoints.
Another benefit of using a userKey and secret is that the user does not have to construct or check signatures, however, this means that all requests must be conducted over HTTPS.
To manage your Gigya Applications:
- Login to your Gigya Console.
- Navigate to the Admin tab.
- Select Manage Applications.
- Once on the Applications page, press Create New Application and follow the on-screen prompts.
- Once the app is created you can view the Apps userKey and secret by clicking the Edit icon, which will take you to the apps Edit Application page.
- You can disseminate this userKey and secret to users whom you want to attain the privileges associated with this app. Users will use this userKey and replace the secret parameter in the request with the secret associated to this key.
- If at any time you want to revoke access for users using this Application, simply delete it from your account and all future attempts to use this userKey and secret will fail.
curl Code Example
In the above example, the secret is the secret associated with the userKey, not the account secret located in the Gigya Dashboard.